From 8fd15d7193cce3957c87c9e4dedef34de8755251 Mon Sep 17 00:00:00 2001 From: Aziz FADIL Date: Sun, 8 Sep 2024 13:28:05 -0400 Subject: [PATCH] Fix withdrawal, and deposit form validation --- package.json | 2 +- src-tauri/Cargo.lock | 2 +- src-tauri/Cargo.toml | 2 +- src-tauri/tauri.conf.json | 2 +- src/lib/schemas.ts | 39 +++++++++++-------- .../activity/components/activity-form.tsx | 3 +- 6 files changed, 29 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index b5d1e87..d56d881 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "wealthfolio-app", "private": true, - "version": "1.0.8", + "version": "1.0.9", "type": "module", "scripts": { "dev": "vite", diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index d16c2cc..b50ef0d 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -4352,7 +4352,7 @@ dependencies = [ [[package]] name = "wealthfolio-app" -version = "1.0.8" +version = "1.0.9" dependencies = [ "chrono", "csv", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6af884d..736c892 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wealthfolio-app" -version = "1.0.8" +version = "1.0.9" description = "Portfolio tracker" authors = ["Aziz Fadil"] license = "LGPL-3.0" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 05f028a..397f380 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -8,7 +8,7 @@ }, "package": { "productName": "Wealthfolio", - "version": "1.0.8" + "version": "1.0.9" }, "tauri": { "allowlist": { diff --git a/src/lib/schemas.ts b/src/lib/schemas.ts index bf3ed53..af7944b 100644 --- a/src/lib/schemas.ts +++ b/src/lib/schemas.ts @@ -34,7 +34,7 @@ export const newGoalSchema = z.object({ export const newActivitySchema = z.object({ id: z.string().uuid().optional(), - accountId: z.string().min(1, { message: 'Account ID is required' }), + accountId: z.string().min(1, { message: 'Please select an account.' }), activityDate: z.date(), currency: z.string().min(1, { message: 'Currency is required' }), fee: z.coerce @@ -52,21 +52,28 @@ export const newActivitySchema = z.object({ }) .positive({ message: 'Quantity must be a positive number.' }), assetId: z.string().min(1, { message: 'Asset ID is required' }), - activityType: z.enum([ - 'BUY', - 'SELL', - 'DIVIDEND', - 'INTEREST', - 'DEPOSIT', - 'WITHDRAWAL', - 'TRANSFER_IN', - 'TRANSFER_OUT', - 'CONVERSION_IN', - 'CONVERSION_OUT', - 'FEE', - 'TAX', - 'SPLIT', - ]), + activityType: z.enum( + [ + 'BUY', + 'SELL', + 'DIVIDEND', + 'INTEREST', + 'DEPOSIT', + 'WITHDRAWAL', + 'TRANSFER_IN', + 'TRANSFER_OUT', + 'CONVERSION_IN', + 'CONVERSION_OUT', + 'FEE', + 'TAX', + 'SPLIT', + ], + { + errorMap: () => { + return { message: 'Please select an activity type.' }; + }, + }, + ), unitPrice: z.coerce .number({ required_error: 'Please enter a valid price.', diff --git a/src/pages/activity/components/activity-form.tsx b/src/pages/activity/components/activity-form.tsx index 98db52f..fc14a8e 100644 --- a/src/pages/activity/components/activity-form.tsx +++ b/src/pages/activity/components/activity-form.tsx @@ -129,6 +129,8 @@ export function ActivityForm({ accounts, defaultValues, onSuccess = () => {} }: form.setValue('currency', currentAccountCurrency); if (CASH_ACTIVITY_TYPES.includes(watchedType)) { form.setValue('assetId', `$CASH-${currentAccountCurrency}`); + form.setValue('unitPrice', 1); + form.setValue('fee', 0); } }, [currentAccountCurrency, watchedType]); @@ -264,7 +266,6 @@ export function ActivityForm({ accounts, defaultValues, onSuccess = () => {} }: ); } - interface CashActivityFieldsProps { currentAccountCurrency: string; }