fixed updating expense
This commit is contained in:
parent
e63c2e6f08
commit
4a84b70ed6
6 changed files with 98 additions and 31 deletions
|
|
@ -48,13 +48,18 @@ export class ExpenseFormComponent implements OnInit {
|
||||||
private readonly merchantService: MerchantService,
|
private readonly merchantService: MerchantService,
|
||||||
private readonly tagService: TagService) {
|
private readonly tagService: TagService) {
|
||||||
effect(() => {
|
effect(() => {
|
||||||
|
const form = this.form().value();
|
||||||
const valid = this.formValid();
|
const valid = this.formValid();
|
||||||
const dirty = this.formDirty();
|
const dirty = this.formDirty();
|
||||||
const value = this.form().value();
|
const value = {
|
||||||
|
...form,
|
||||||
|
merchant: Boolean(form.merchant) ? form.merchant : null,
|
||||||
|
note: Boolean(form.note) ? form.note : null
|
||||||
|
};
|
||||||
|
|
||||||
this.valid.emit(valid);
|
this.valid.emit(valid);
|
||||||
this.dirty.emit(dirty);
|
this.dirty.emit(dirty);
|
||||||
this.value.emit(value);
|
this.value.emit(value as ExpenseForm);
|
||||||
this.lastDate.set(value.date);
|
this.lastDate.set(value.date);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -98,8 +103,8 @@ export class ExpenseFormComponent implements OnInit {
|
||||||
date: new Date(year, month, day),
|
date: new Date(year, month, day),
|
||||||
cents: expense.cents,
|
cents: expense.cents,
|
||||||
category: expense.category,
|
category: expense.category,
|
||||||
merchant: expense.merchant ?? {},
|
merchant: expense.merchant ?? null,
|
||||||
note: expense.note ?? '',
|
note: expense.note,
|
||||||
tags: expense.tags ?? []
|
tags: expense.tags ?? []
|
||||||
} as ExpenseForm;
|
} as ExpenseForm;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,10 +38,10 @@ export class ExpenseComponent {
|
||||||
const postExpense: CreateExpense = {
|
const postExpense: CreateExpense = {
|
||||||
date: this.dateToPlainDate(form.date),
|
date: this.dateToPlainDate(form.date),
|
||||||
cents: form.cents,
|
cents: form.cents,
|
||||||
categoryId: form.category.id,
|
category: form.category,
|
||||||
note: !!form.note ? form.note : undefined,
|
merchant: form.merchant,
|
||||||
merchantId: !!form.merchant ? form.merchant.id : undefined,
|
note: form.note,
|
||||||
tagIds: form.tags.map(tag => tag.id)
|
tags: form.tags
|
||||||
};
|
};
|
||||||
this.savingExpense.set(true);
|
this.savingExpense.set(true);
|
||||||
const snackId = this.snackBar.staticBar('Tracking new expense...');
|
const snackId = this.snackBar.staticBar('Tracking new expense...');
|
||||||
|
|
@ -70,10 +70,10 @@ export class ExpenseComponent {
|
||||||
id: this.expense()!.id,
|
id: this.expense()!.id,
|
||||||
date: this.dateToPlainDate(form.date),
|
date: this.dateToPlainDate(form.date),
|
||||||
cents: form.cents,
|
cents: form.cents,
|
||||||
categoryId: form.category.id,
|
category: form.category,
|
||||||
note: !!form.note ? form.note : undefined,
|
merchant: form.merchant,
|
||||||
merchantId: !!form.merchant ? form.merchant.id : undefined,
|
note: form.note,
|
||||||
tagIds: form.tags.map(tag => tag.id)
|
tags: form.tags
|
||||||
};
|
};
|
||||||
this.savingExpense.set(true);
|
this.savingExpense.set(true);
|
||||||
const snackId = this.snackBar.staticBar('Updating expense...');
|
const snackId = this.snackBar.staticBar('Updating expense...');
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,44 @@
|
||||||
<div class="categories-container">
|
<div class="categories-container">
|
||||||
<div class="category-list-header">
|
<div class="category-list-header">
|
||||||
<p>Categories</p>
|
<p>Categories</p>
|
||||||
|
|
||||||
|
<mat-form-field appearance="outline">
|
||||||
|
<mat-label>New Category</mat-label>
|
||||||
|
<input type="text" matInput [(ngModel)]="newCategory" [ngModelOptions]="{ standalone: true }">
|
||||||
|
@if (!!newCategory()) {
|
||||||
|
<button matSuffix matIconButton (click)="addClick()">
|
||||||
|
<mat-icon>add</mat-icon>
|
||||||
|
</button>
|
||||||
|
}
|
||||||
|
</mat-form-field>
|
||||||
|
|
||||||
<app-divider />
|
<app-divider />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="category-list">
|
<div class="category-list">
|
||||||
@for (category of categories(); track category.id) {
|
<!-- <mat-list>-->
|
||||||
<div>{{ category.name }}</div>
|
<!-- <mat-list-item>-->
|
||||||
}
|
<!-- <div class="category-item">-->
|
||||||
@if (!categories().length) {
|
<!-- <mat-form-field appearance="outline">-->
|
||||||
<div class="category-list-empty">
|
<!-- <mat-label>New Category</mat-label>-->
|
||||||
No categories to display
|
<!-- <input type="text" matInput [(ngModel)]="newCategory">-->
|
||||||
</div>
|
<!-- <button matSuffix matIconButton (click)="addClick()">-->
|
||||||
}
|
<!-- <mat-icon>shopping_cart</mat-icon>-->
|
||||||
|
<!-- </button>-->
|
||||||
|
<!-- </mat-form-field>-->
|
||||||
|
<!-- </div>-->
|
||||||
|
<!-- </mat-list-item>-->
|
||||||
|
@for (category of categories(); track category.id) {
|
||||||
|
<!-- <mat-list-item>-->
|
||||||
|
{{ category.name }}
|
||||||
|
<!-- </mat-list-item>-->
|
||||||
|
}
|
||||||
|
@if (!categories().length) {
|
||||||
|
<!-- <mat-list-item>No categories to display</mat-list-item>-->
|
||||||
|
<!-- <div class="category-list-empty">-->
|
||||||
|
<!-- No categories to display-->
|
||||||
|
<!-- </div>-->
|
||||||
|
}
|
||||||
|
<!-- </mat-list>-->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,20 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.category-list {
|
//.add-category {
|
||||||
display: grid;
|
// display: flex;
|
||||||
gap: 1rem;
|
// align-items: baseline;
|
||||||
justify-content: center;
|
// gap: 0.5rem;
|
||||||
|
//}
|
||||||
|
|
||||||
|
//.category-list {
|
||||||
|
// display: grid;
|
||||||
|
// gap: 1rem;
|
||||||
|
// justify-content: center;
|
||||||
|
//}
|
||||||
|
.category-item {
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
mat-form-field {
|
||||||
|
width: 400px;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,24 @@
|
||||||
import { Component, computed } from '@angular/core';
|
import {Component, computed, effect, model} from '@angular/core';
|
||||||
import { CategoryService } from '../../../services/category.service';
|
import { CategoryService } from '../../../services/category.service';
|
||||||
import { DividerComponent } from '../../divider/divider.component';
|
import { DividerComponent } from '../../divider/divider.component';
|
||||||
|
import {MatFormField, MatInput, MatLabel} from '@angular/material/input';
|
||||||
|
import {FormsModule} from '@angular/forms';
|
||||||
|
import {MatList, MatListItem} from '@angular/material/list';
|
||||||
|
import {MatIconButton} from '@angular/material/button';
|
||||||
|
import {MatIcon} from '@angular/material/icon';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-categories',
|
selector: 'app-categories',
|
||||||
imports: [
|
imports: [
|
||||||
DividerComponent
|
DividerComponent,
|
||||||
|
MatInput,
|
||||||
|
MatFormField,
|
||||||
|
MatLabel,
|
||||||
|
FormsModule,
|
||||||
|
// MatList,
|
||||||
|
// MatListItem,
|
||||||
|
MatIconButton,
|
||||||
|
MatIcon
|
||||||
],
|
],
|
||||||
templateUrl: './categories.component.html',
|
templateUrl: './categories.component.html',
|
||||||
styleUrl: './categories.component.scss'
|
styleUrl: './categories.component.scss'
|
||||||
|
|
@ -13,5 +26,15 @@ import { DividerComponent } from '../../divider/divider.component';
|
||||||
export class CategoriesComponent {
|
export class CategoriesComponent {
|
||||||
protected categories = computed(() => this.categoryService.categories());
|
protected categories = computed(() => this.categoryService.categories());
|
||||||
|
|
||||||
public constructor(private readonly categoryService: CategoryService) { }
|
public newCategory = model<string>('');
|
||||||
|
|
||||||
|
public constructor(private readonly categoryService: CategoryService) {
|
||||||
|
effect(() => {
|
||||||
|
console.log(this.newCategory());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public addClick(): void {
|
||||||
|
console.log('add clicked');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,18 +38,18 @@ export interface Expense {
|
||||||
date: Date;
|
date: Date;
|
||||||
cents: number;
|
cents: number;
|
||||||
category: Category;
|
category: Category;
|
||||||
note?: string;
|
|
||||||
merchant?: Merchant;
|
merchant?: Merchant;
|
||||||
|
note?: string;
|
||||||
tags: Tag[];
|
tags: Tag[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CreateExpense {
|
export interface CreateExpense {
|
||||||
date: Temporal.PlainDate;
|
date: Temporal.PlainDate;
|
||||||
cents: number;
|
cents: number;
|
||||||
categoryId: string;
|
category: Category;
|
||||||
|
merchant?: Merchant;
|
||||||
note?: string;
|
note?: string;
|
||||||
merchantId?: string;
|
tags: Tag[];
|
||||||
tagIds?: string[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UpdateExpense extends CreateExpense {
|
export interface UpdateExpense extends CreateExpense {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue