small tweak to add expense

This commit is contained in:
Joe Arndt 2026-02-13 19:53:32 -06:00
parent 0e2e2f9e84
commit 8bf9875e8e
3 changed files with 63 additions and 10 deletions

View file

@ -1,18 +1,44 @@
<div class="add-expense-container"> <div class="add-expense-container">
<app-card [header]="'Add Expense'"> <app-card [header]="'Add Expense'">
<div class="add-expense-body"> <div class="add-expense-body">
<div>Date</div> <div>
<div>Amount</div> Date: <input type="date" [formField]="expenseForm.date">
<div>Category</div> </div>
<div>Merchant</div>
<div>
Cents (required):
<input type="number" placeholder="Enter amount" [formField]="expenseForm.amount">
</div>
<div>
Category (required):
<select [formField]="expenseForm.categoryId">
<option value="">Select a category</option>
@for (category of categories(); track category.id) {
<option [value]="category.id">{{ category.name }}</option>
}
</select>
</div>
</div> </div>
<div> <div>
Note Merchant (optional):
<select [formField]="expenseForm.merchantId">
<option value="">Select a merchant</option>
@for (merchant of merchants(); track merchant.id) {
<option [value]="merchant.id">{{ merchant.name }}</option>
}
</select>
</div> </div>
<div>
Note (optional): <input type="text" [formField]="expenseForm.note">
</div>
<div>Tags</div>
<div class="card-footer"> <div class="card-footer">
<div>Tags</div> <button>Save</button>
</div> </div>
</app-card> </app-card>
</div> </div>

View file

@ -1,5 +1,5 @@
.add-expense-body { .add-expense-body {
display: flex; display: flex;
justify-content: space-between; justify-content: flex-start;
gap: 0.5rem; gap: 0.5rem;
} }

View file

@ -1,14 +1,41 @@
import { Component } from '@angular/core'; import {Component, computed, signal} from '@angular/core';
import {CardComponent} from '../card/card.component'; import { CardComponent } from '../card/card.component';
import {Category, CategoryService} from '../../services/category.service';
import {Merchant, MerchantService} from '../../services/merchant.service';
import { Tag } from '../../services/tag.service';
import {form, FormField} from '@angular/forms/signals';
interface AddExpenseForm {
date: Date,
amount: number | string,
categoryId: string,
merchantId: string,
note: string,
tags: Tag[]
}
@Component({ @Component({
selector: 'app-add-expense', selector: 'app-add-expense',
imports: [ imports: [
CardComponent CardComponent,
FormField
], ],
templateUrl: './add-expense.component.html', templateUrl: './add-expense.component.html',
styleUrl: './add-expense.component.scss', styleUrl: './add-expense.component.scss',
}) })
export class AddExpenseComponent { export class AddExpenseComponent {
protected categories = computed(() => this.categoryService.categories());
protected merchants = computed(() => this.merchantService.merchants());
private addExpenseModel = signal<AddExpenseForm>({
date: new Date(),
amount: '',
categoryId: '',
merchantId: '',
note: '',
tags: []
});
public expenseForm = form(this.addExpenseModel);
public constructor(private readonly categoryService: CategoryService,
private readonly merchantService: MerchantService) { }
} }