add-expense-mobile-friendly
This commit is contained in:
parent
ca88144629
commit
23132741a9
4 changed files with 81 additions and 82 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
.app-content {
|
.app-content {
|
||||||
padding: 2rem;
|
padding: 0.5rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
|
|
||||||
|
|
@ -1,71 +1,56 @@
|
||||||
<div class="add-expense-container">
|
<div class="add-expense-container">
|
||||||
<mat-card appearance="outlined">
|
<mat-card appearance="outlined">
|
||||||
<mat-card-header class="add-expense-header">
|
<mat-card-header>
|
||||||
<mat-card-title>Track new Expense</mat-card-title>
|
<mat-card-title>Track new Expense</mat-card-title>
|
||||||
|
<button matButton="tonal" [disabled]="!enableSaveButton()" (click)="saveClick()">Save</button>
|
||||||
</mat-card-header>
|
</mat-card-header>
|
||||||
|
|
||||||
<mat-card-content>
|
<mat-card-content>
|
||||||
<div class="add-expense-dropdowns">
|
<mat-form-field appearance="outline">
|
||||||
<mat-form-field appearance="outline">
|
<mat-label>Date</mat-label>
|
||||||
<mat-label>Date</mat-label>
|
<input matInput [matDatepicker]="expenseDatePicker" [formField]="expenseForm.date">
|
||||||
<input matInput [matDatepicker]="expenseDatePicker" [formField]="expenseForm.date">
|
<mat-datepicker-toggle matIconSuffix [for]="expenseDatePicker"></mat-datepicker-toggle>
|
||||||
<mat-datepicker-toggle matIconSuffix [for]="expenseDatePicker"></mat-datepicker-toggle>
|
<mat-datepicker #expenseDatePicker></mat-datepicker>
|
||||||
<mat-datepicker #expenseDatePicker></mat-datepicker>
|
</mat-form-field>
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Cents</mat-label>
|
<mat-label>Cents</mat-label>
|
||||||
<input type="number" matInput [formField]="expenseForm.cents">
|
<input type="number" matInput [formField]="expenseForm.cents">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Category</mat-label>
|
<mat-label>Category</mat-label>
|
||||||
<input type="text" matInput [matAutocomplete]="categoryAuto" [formField]="expenseForm.category" [value]="expenseForm.category()">
|
<input type="text" matInput [matAutocomplete]="categoryAuto" [formField]="expenseForm.category" [value]="expenseForm.category()">
|
||||||
<mat-autocomplete [displayWith]="display" autoActiveFirstOption #categoryAuto="matAutocomplete">
|
<mat-autocomplete [displayWith]="autocompleteDisplay" autoActiveFirstOption #categoryAuto="matAutocomplete">
|
||||||
@for (category of categories(); track category.id) {
|
@for (category of categories(); track category.id) {
|
||||||
<mat-option [value]="category">{{ category.name }}</mat-option>
|
<mat-option [value]="category">{{ category.name }}</mat-option>
|
||||||
}
|
}
|
||||||
</mat-autocomplete>
|
</mat-autocomplete>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field appearance="outline">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Merchant</mat-label>
|
<mat-label>Merchant</mat-label>
|
||||||
<input type="text" matInput [matAutocomplete]="merchantAuto" [formField]="expenseForm.merchant">
|
<input type="text" matInput [matAutocomplete]="merchantAuto" [formField]="expenseForm.merchant">
|
||||||
<mat-autocomplete [displayWith]="display" autoActiveFirstOption #merchantAuto="matAutocomplete">
|
<mat-autocomplete [displayWith]="autocompleteDisplay" autoActiveFirstOption #merchantAuto="matAutocomplete">
|
||||||
@for (merchant of merchants(); track merchant.id) {
|
@for (merchant of merchants(); track merchant.id) {
|
||||||
<mat-option [value]="merchant">{{ merchant.name }}</mat-option>
|
<mat-option [value]="merchant">{{ merchant.name }}</mat-option>
|
||||||
}
|
}
|
||||||
</mat-autocomplete>
|
</mat-autocomplete>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="add-expense-additional">
|
<mat-form-field appearance="outline">
|
||||||
<mat-form-field appearance="outline">
|
<mat-label>Tags</mat-label>
|
||||||
<mat-label>Tags</mat-label>
|
<mat-select disableRipple multiple [formField]="expenseForm.tags">
|
||||||
<mat-select disableRipple multiple [formField]="expenseForm.tags">
|
@for (tag of tags(); track tag.id) {
|
||||||
@for (tag of tags(); track tag.id) {
|
<mat-option [value]="tag">{{ tag.name }}</mat-option>
|
||||||
<mat-option [value]="tag">{{ tag.name }}</mat-option>
|
}
|
||||||
}
|
</mat-select>
|
||||||
</mat-select>
|
</mat-form-field>
|
||||||
</mat-form-field>
|
|
||||||
|
|
||||||
<mat-form-field appearance="outline" class="add-expense-note">
|
<mat-form-field appearance="outline">
|
||||||
<mat-label>Note</mat-label>
|
<mat-label>Note</mat-label>
|
||||||
<textarea rows="1" matInput [formField]="expenseForm.note"></textarea>
|
<textarea rows="1" matInput [formField]="expenseForm.note"></textarea>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
|
||||||
</mat-card-content>
|
</mat-card-content>
|
||||||
|
|
||||||
<mat-card-footer class="add-expense-footer">
|
|
||||||
<mat-card-actions>
|
|
||||||
<button matButton="tonal" [disabled]="!enableSaveButton()" (click)="saveClick()">Save</button>
|
|
||||||
</mat-card-actions>
|
|
||||||
|
|
||||||
@if (errorSaving()) {
|
|
||||||
<mat-error>
|
|
||||||
{{ errorSaving() }}
|
|
||||||
</mat-error>
|
|
||||||
}
|
|
||||||
</mat-card-footer>
|
|
||||||
</mat-card>
|
</mat-card>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,39 @@
|
||||||
.add-expense-header {
|
.add-expense-container {
|
||||||
padding-bottom: 1rem;
|
width: 100%;
|
||||||
}
|
|
||||||
|
|
||||||
.add-expense-footer {
|
|
||||||
padding: 0 0 1rem 0.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
.add-expense-dropdowns {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 1rem;
|
flex-direction: column;
|
||||||
justify-content: space-between;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.add-expense-additional {
|
mat-card {
|
||||||
display: flex;
|
max-width: 800px;
|
||||||
gap: 1rem;
|
|
||||||
justify-content: space-between;
|
|
||||||
}
|
|
||||||
|
|
||||||
.add-expense-note {
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mat-card-header {
|
||||||
|
padding-bottom: 1rem;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat-card-content {
|
||||||
|
display: grid;
|
||||||
|
}
|
||||||
|
|
||||||
|
mat-form-field {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 550px) {
|
||||||
|
mat-card-content {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
gap: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: 800px) {
|
||||||
|
mat-card-content {
|
||||||
|
grid-template-columns: 1fr 1fr 1fr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ import { CreateExpense, ExpenseService } from '../../services/expense.service';
|
||||||
import { DatePipe } from '@angular/common';
|
import { DatePipe } from '@angular/common';
|
||||||
|
|
||||||
interface ExpenseForm {
|
interface ExpenseForm {
|
||||||
date: Date;
|
date: Date | string;
|
||||||
cents: number;
|
cents: number;
|
||||||
category: Category | string;
|
category: Category | string;
|
||||||
merchant: Merchant | string;
|
merchant: Merchant | string;
|
||||||
|
|
@ -44,10 +44,9 @@ export class AddExpenseComponent {
|
||||||
return dateValid && centsValid && categoryValid && merchantValid && noteValid;
|
return dateValid && centsValid && categoryValid && merchantValid && noteValid;
|
||||||
});
|
});
|
||||||
protected saving = signal(false);
|
protected saving = signal(false);
|
||||||
protected errorSaving = signal('');
|
|
||||||
|
|
||||||
private defaultFormState: ExpenseForm = {
|
private defaultFormState: ExpenseForm = {
|
||||||
date: new Date(),
|
date: '',
|
||||||
cents: NaN,
|
cents: NaN,
|
||||||
category: '',
|
category: '',
|
||||||
merchant: '',
|
merchant: '',
|
||||||
|
|
@ -69,7 +68,6 @@ export class AddExpenseComponent {
|
||||||
private readonly datePipe: DatePipe) { }
|
private readonly datePipe: DatePipe) { }
|
||||||
|
|
||||||
public async saveClick(): Promise<void> {
|
public async saveClick(): Promise<void> {
|
||||||
this.errorSaving.set('');
|
|
||||||
const saveExpenseModel = this.expenseModel();
|
const saveExpenseModel = this.expenseModel();
|
||||||
const date = this.datePipe.transform(saveExpenseModel.date, 'yyyy-MM-dd')?.split('-') ?? [];
|
const date = this.datePipe.transform(saveExpenseModel.date, 'yyyy-MM-dd')?.split('-') ?? [];
|
||||||
const expense: CreateExpense = {
|
const expense: CreateExpense = {
|
||||||
|
|
@ -90,14 +88,14 @@ export class AddExpenseComponent {
|
||||||
this.expenseForm().reset(this.expenseModel());
|
this.expenseForm().reset(this.expenseModel());
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
this.errorSaving.set(`Error saving expense: ${error}`)
|
console.error(error);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
this.saving.set(false);
|
this.saving.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public display(value: Merchant | Category | Tag) {
|
public autocompleteDisplay(value: Merchant | Category) {
|
||||||
return value.name ?? null;
|
return value.name ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue