From 3d0d63b1d4865f1d6a434b891e1f15c7db7df6f5 Mon Sep 17 00:00:00 2001 From: Joe Arndt Date: Thu, 26 Feb 2026 12:24:47 -0600 Subject: [PATCH] updated merchant tab --- .../components/expense/expense.component.ts | 6 ++-- .../categories/categories.component.ts | 8 ++--- .../merchants/merchants.component.html | 33 +++++++++++-------- .../merchants/merchants.component.scss | 25 +++++--------- .../metadata/merchants/merchants.component.ts | 18 ++++++++-- src/app/services/category.service.ts | 8 ++--- src/app/services/expense.service.ts | 8 ++--- src/app/services/merchant.service.ts | 16 +++++++-- src/app/services/tag.service.ts | 4 +-- 9 files changed, 75 insertions(+), 51 deletions(-) diff --git a/src/app/components/expense/expense.component.ts b/src/app/components/expense/expense.component.ts index 6a4f799..32491ce 100644 --- a/src/app/components/expense/expense.component.ts +++ b/src/app/components/expense/expense.component.ts @@ -46,8 +46,8 @@ export class ExpenseComponent { this.savingExpense.set(true); const snackId = this.snackBar.staticBar('Tracking new expense...'); try { - await this.expenseService.postExpense(postExpense); - await this.expenseService.fetchExpenses(); + await this.expenseService.create(postExpense); + await this.expenseService.fetch(); this.resetForm(); this.snackBar.dismiss(snackId); this.snackBar.autoBar('Expense tracked!'); @@ -79,7 +79,7 @@ export class ExpenseComponent { this.savingExpense.set(true); const snackId = this.snackBar.staticBar('Updating expense...'); try { - const expense = await this.expenseService.updateExpense(putExpense); + const expense = await this.expenseService.update(putExpense); this.expense.set(expense); this.form()?.refresh(expense); this.editingExpense.set(false); diff --git a/src/app/components/metadata/categories/categories.component.ts b/src/app/components/metadata/categories/categories.component.ts index b0a71a0..41fec0b 100644 --- a/src/app/components/metadata/categories/categories.component.ts +++ b/src/app/components/metadata/categories/categories.component.ts @@ -18,12 +18,12 @@ export class CategoriesComponent { public constructor(private readonly categoryService: CategoryService) { } public async createCategory(name: string): Promise { - await this.categoryService.createCategory({ name }); - await this.categoryService.fetchCategories(); + await this.categoryService.create({ name }); + await this.categoryService.fetch(); } public async updateCategory(category: Category): Promise { - await this.categoryService.updateCategory(category); - await this.categoryService.fetchCategories(); + await this.categoryService.update(category); + await this.categoryService.fetch(); } } diff --git a/src/app/components/metadata/merchants/merchants.component.html b/src/app/components/metadata/merchants/merchants.component.html index 1b0bb83..7c0e464 100644 --- a/src/app/components/metadata/merchants/merchants.component.html +++ b/src/app/components/metadata/merchants/merchants.component.html @@ -1,17 +1,24 @@
-
-

Merchants

- -
+ + + Merchants + -
- @for (merchant of merchants(); track merchant.id) { -
{{ merchant.name }}
- } - @if (!merchants().length) { -
- No merchants to display + +
+
- } -
+ +
+ @for (merchant of merchants(); track merchant.id) { + + } + @if (!merchants().length) { +
+ No merchants to display +
+ } +
+ +
diff --git a/src/app/components/metadata/merchants/merchants.component.scss b/src/app/components/metadata/merchants/merchants.component.scss index 8d34c6c..7f8f410 100644 --- a/src/app/components/metadata/merchants/merchants.component.scss +++ b/src/app/components/metadata/merchants/merchants.component.scss @@ -1,28 +1,21 @@ -.merchants-container { - display: grid; - gap: 1rem; -} +@use "variables"; -.merchant-list-header { - padding-top: 1rem; +.merchants-container { + padding-top: 0.5rem; display: flex; flex-direction: column; align-items: center; - p { - font-size: 1.8rem; - line-height: 100%; - font-weight: 400; - margin: 0; - } - - app-divider { + mat-card { + max-width: variables.$wide-screen; width: 100%; } } +.new-merchant { + padding-top: 0.5rem; +} + .merchant-list { display: grid; - gap: 1rem; - justify-content: center; } diff --git a/src/app/components/metadata/merchants/merchants.component.ts b/src/app/components/metadata/merchants/merchants.component.ts index 7c8d730..78d93be 100644 --- a/src/app/components/metadata/merchants/merchants.component.ts +++ b/src/app/components/metadata/merchants/merchants.component.ts @@ -1,11 +1,13 @@ import { Component, computed } from '@angular/core'; -import { MerchantService } from '../../../services/merchant.service'; -import { DividerComponent } from '../../divider/divider.component'; +import { Merchant, MerchantService } from '../../../services/merchant.service'; +import { MatCardModule } from '@angular/material/card'; +import { MetadataFormComponent } from '../metadata-form/metadata-form.component'; @Component({ selector: 'app-merchants', imports: [ - DividerComponent + MatCardModule, + MetadataFormComponent ], templateUrl: './merchants.component.html', styleUrl: './merchants.component.scss' @@ -14,4 +16,14 @@ export class MerchantsComponent { protected merchants = computed(() => this.merchantService.merchants()); public constructor(private readonly merchantService: MerchantService) { } + + public async createMerchant(name: string): Promise { + await this.merchantService.create({ name }); + await this.merchantService.fetch(); + } + + public async updateMerchant(merchant: Merchant): Promise { + await this.merchantService.update(merchant); + await this.merchantService.fetch(); + } } diff --git a/src/app/services/category.service.ts b/src/app/services/category.service.ts index 67b96a4..b1b4ac3 100644 --- a/src/app/services/category.service.ts +++ b/src/app/services/category.service.ts @@ -10,18 +10,18 @@ export class CategoryService { public readonly categoryPath = 'http://localhost:3000/common-cents/categories'; public constructor(private readonly http: HttpService) { - void this.fetchCategories(); + void this.fetch(); } - public async fetchCategories(): Promise { + public async fetch(): Promise { this.internalCategories.set(await this.http.get(this.categoryPath)); } - public async createCategory(category: CreateCategory): Promise { + public async create(category: CreateCategory): Promise { return await this.http.post(this.categoryPath, category); } - public async updateCategory(category: Category): Promise { + public async update(category: Category): Promise { return await this.http.put(this.categoryPath, category); } } diff --git a/src/app/services/expense.service.ts b/src/app/services/expense.service.ts index 0113335..0ca6ff7 100644 --- a/src/app/services/expense.service.ts +++ b/src/app/services/expense.service.ts @@ -14,18 +14,18 @@ export class ExpenseService { public readonly expensePath = 'http://localhost:3000/common-cents/expenses'; // TODO: refactor public constructor(private readonly http: HttpService) { - void this.fetchExpenses(); + void this.fetch(); } - public async fetchExpenses(): Promise { + public async fetch(): Promise { this.internalExpenses.set(await this.http.get(this.expensePath)); } - public async postExpense(createExpense: CreateExpense): Promise { + public async create(createExpense: CreateExpense): Promise { return await this.http.post(this.expensePath, createExpense); } - public async updateExpense(updateExpense: UpdateExpense): Promise { + public async update(updateExpense: UpdateExpense): Promise { return await this.http.put(this.expensePath, updateExpense); } } diff --git a/src/app/services/merchant.service.ts b/src/app/services/merchant.service.ts index 8cca35b..1d0290b 100644 --- a/src/app/services/merchant.service.ts +++ b/src/app/services/merchant.service.ts @@ -10,15 +10,27 @@ export class MerchantService { public readonly merchantPath = 'http://localhost:3000/common-cents/merchants'; public constructor(private readonly http: HttpService) { - void this.fetchMerchants(); + void this.fetch(); } - public async fetchMerchants(): Promise { + public async fetch(): Promise { this.internalMerchants.set(await this.http.get(this.merchantPath)); } + + public async create(merchant: CreateMerchant): Promise { + return await this.http.post(this.merchantPath, merchant); + } + + public async update(merchant: Merchant): Promise { + return await this.http.put(this.merchantPath, merchant); + } } export interface Merchant { id: string; name: string; } + +export interface CreateMerchant { + name: string; +} diff --git a/src/app/services/tag.service.ts b/src/app/services/tag.service.ts index 06a373b..a3d493e 100644 --- a/src/app/services/tag.service.ts +++ b/src/app/services/tag.service.ts @@ -10,10 +10,10 @@ export class TagService { public readonly tagPath = 'http://localhost:3000/common-cents/tags'; public constructor(private readonly http: HttpService) { - void this.fetchTags(); + void this.fetch(); } - public async fetchTags(): Promise { + public async fetch(): Promise { this.internalTags.set(await this.http.get(this.tagPath)); } }