Skip to content

Commit

Permalink
Merge pull request #74 from afadil/dev
Browse files Browse the repository at this point in the history
Fix withdrawal, and deposit form validation
  • Loading branch information
afadil authored Sep 8, 2024
2 parents 44c4841 + 8fd15d7 commit 43afaf6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "wealthfolio-app",
"private": true,
"version": "1.0.8",
"version": "1.0.9",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"package": {
"productName": "Wealthfolio",
"version": "1.0.8"
"version": "1.0.9"
},
"tauri": {
"allowlist": {
Expand Down
39 changes: 23 additions & 16 deletions src/lib/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.',
Expand Down
3 changes: 2 additions & 1 deletion src/pages/activity/components/activity-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -264,7 +266,6 @@ export function ActivityForm({ accounts, defaultValues, onSuccess = () => {} }:
</Form>
);
}

interface CashActivityFieldsProps {
currentAccountCurrency: string;
}
Expand Down

0 comments on commit 43afaf6

Please sign in to comment.