added saving state
This commit is contained in:
parent
e78b24e521
commit
49af11d7b8
2 changed files with 29 additions and 38 deletions
|
|
@ -18,7 +18,7 @@ export class ExpenseComponent {
|
|||
private form = viewChild(ExpenseFormComponent);
|
||||
|
||||
public editingExpense = signal(false);
|
||||
public savingExpense = signal(false); // TODO: implement UI for saving...
|
||||
public savingExpense = signal(false);
|
||||
|
||||
public expense = model<Expense>();
|
||||
public formValid = model(false);
|
||||
|
|
@ -41,8 +41,17 @@ export class ExpenseComponent {
|
|||
merchantId: !!form.merchant ? form.merchant.id : undefined,
|
||||
tagIds: form.tags.map(tag => tag.id)
|
||||
};
|
||||
await this.expenseService.postExpense(postExpense);
|
||||
this.resetForm();
|
||||
this.savingExpense.set(true);
|
||||
try {
|
||||
await this.expenseService.postExpense(postExpense);
|
||||
this.resetForm();
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error); // TODO: Add error processing
|
||||
}
|
||||
finally {
|
||||
this.savingExpense.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public resetAddClick(): void {
|
||||
|
|
@ -60,10 +69,19 @@ export class ExpenseComponent {
|
|||
merchantId: !!form.merchant ? form.merchant.id : undefined,
|
||||
tagIds: form.tags.map(tag => tag.id)
|
||||
};
|
||||
const expense = await this.expenseService.updateExpense(putExpense);
|
||||
this.expense.set(expense);
|
||||
this.form()?.refresh(expense);
|
||||
this.editingExpense.set(false);
|
||||
this.savingExpense.set(true);
|
||||
try {
|
||||
const expense = await this.expenseService.updateExpense(putExpense);
|
||||
this.expense.set(expense);
|
||||
this.form()?.refresh(expense);
|
||||
this.editingExpense.set(false);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error); // TODO: Add error processing
|
||||
}
|
||||
finally {
|
||||
this.savingExpense.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public cancelUpdateClick(): void {
|
||||
|
|
@ -78,31 +96,4 @@ export class ExpenseComponent {
|
|||
private dateToPlainDate(date: Date): Temporal.PlainDate {
|
||||
return new Temporal.PlainDate(date.getFullYear(), date.getMonth() + 1, date.getDate());
|
||||
}
|
||||
|
||||
// const saveExpenseModel = this.expenseModel();
|
||||
// const date = this.datePipe.transform(saveExpenseModel.date, 'yyyy-MM-dd')?.split('-') ?? [];
|
||||
// const expense: CreateExpense = {
|
||||
// year: date[0],
|
||||
// month: date[1],
|
||||
// day: date[2],
|
||||
// cents: saveExpenseModel.cents,
|
||||
// category: saveExpenseModel.category as Category,
|
||||
// merchant: saveExpenseModel.merchant ? saveExpenseModel.merchant as Merchant : undefined,
|
||||
// note: saveExpenseModel.note ? saveExpenseModel.note : undefined,
|
||||
// tags: saveExpenseModel.tags
|
||||
// };
|
||||
//
|
||||
// this.saving.set(true);
|
||||
// try {
|
||||
// await this.expenseService.postExpense(expense);
|
||||
// this.lastSelectedDate = saveExpenseModel.date ? saveExpenseModel.date as Date : undefined;
|
||||
// this.expenseModel.set({ ...this.defaultForm, date: saveExpenseModel.date });
|
||||
// this.expenseForm().reset(this.expenseModel());
|
||||
// }
|
||||
// catch (error) {
|
||||
// console.error(error);
|
||||
// }
|
||||
// finally {
|
||||
// this.saving.set(false);
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue