1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-09 07:25:19 +02:00

front end for /claim #131

This commit is contained in:
Brian Skinner 2024-01-19 11:38:07 -08:00
parent be27bddb4c
commit b4918cbd9b
8 changed files with 72 additions and 42295 deletions

View file

@ -1,22 +1,42 @@
import type { AccountClassification } from '@prisma/client' import type { AccountClassification, AccountCategory } from '@prisma/client'
import { Controller } from 'react-hook-form' import { Controller } from 'react-hook-form'
import { InputCurrency, DatePicker } from '@maybe-finance/design-system' import { Input, InputCurrency, DatePicker } from '@maybe-finance/design-system'
import { BrowserUtil } from '@maybe-finance/client/shared' import { BrowserUtil } from '@maybe-finance/client/shared'
export type AccountValuationFieldProps = { export type AccountValuationFieldProps = {
control: any control: any
classification?: AccountClassification classification?: AccountClassification
category?: AccountCategory
currentBalanceEditable?: boolean currentBalanceEditable?: boolean
} }
export function AccountValuationFormFields({ export function AccountValuationFormFields({
control, control,
classification = 'asset', classification = 'asset',
category = 'investment',
currentBalanceEditable = true, currentBalanceEditable = true,
}: AccountValuationFieldProps) { }: AccountValuationFieldProps) {
return ( return (
<> <>
{category === 'stock' && (
<Controller
control={control}
name="stockSymbol"
shouldUnregister
render={({ field, fieldState: { error } }) => (
<Input
{...field}
type="text"
className="mb-4"
label="Symbol"
placeholder="e.g. MCD"
error={error && 'Symbol is required'}
/>
)}
/>
)}
<Controller <Controller
control={control} control={control}
name="startDate" name="startDate"
@ -39,14 +59,38 @@ export function AccountValuationFormFields({
render={({ field, fieldState: { error } }) => ( render={({ field, fieldState: { error } }) => (
<InputCurrency <InputCurrency
{...field} {...field}
label={`${classification === 'liability' ? 'Start' : 'Purchase'} value`} label={`${
classification === 'liability'
? 'Start'
: category === 'stock'
? 'Total purchase'
: 'Purchase'
} value`}
placeholder="0" placeholder="0"
error={error && 'Positive value is required'} error={error && 'Positive value is required'}
/> />
)} )}
/> />
{currentBalanceEditable && ( {category === 'stock' && (
<Controller
control={control}
name="numberShares"
rules={{ required: true, validate: (val) => val >= 0 }}
shouldUnregister
render={({ field, fieldState: { error } }) => (
<Input
{...field}
type="text"
label="Number of shares"
placeholder="0"
error={error && 'Number of shares is required'}
/>
)}
/>
)}
{category !== 'stock' && currentBalanceEditable && (
<Controller <Controller
control={control} control={control}
name="currentBalance" name="currentBalance"

View file

@ -31,11 +31,12 @@ export default function AssetForm({ mode, defaultValues, onSubmit, accountType }
const { errors, isSubmitting, isValid } = formState const { errors, isSubmitting, isValid } = formState
const [startDate] = watch(['startDate']) const [startDate] = watch(['startDate'])
const currentBalanceEditable = !startDate || !DateUtil.isToday(startDate) const currentBalanceEditable = !startDate || !DateUtil.isToday(startDate)
const [categoryValue] = watch(['categoryUser'])
const categoryList = useMemo(() => { const categoryList = useMemo(() => {
const { cash, investment, crypto, valuable, other } = AccountUtil.CATEGORIES const { stock, cash, investment, crypto, valuable, other } = AccountUtil.CATEGORIES
if (mode === 'create') { if (mode === 'create') {
return [cash, investment, crypto, valuable, other] return [stock, cash, investment, crypto, valuable, other]
} else { } else {
return AccountUtil.CATEGORY_MAP[accountType!] return AccountUtil.CATEGORY_MAP[accountType!]
} }
@ -89,6 +90,7 @@ export default function AssetForm({ mode, defaultValues, onSubmit, accountType }
<div> <div>
<AccountValuationFormFields <AccountValuationFormFields
control={control} control={control}
category={categoryValue}
currentBalanceEditable={currentBalanceEditable} currentBalanceEditable={currentBalanceEditable}
/> />
</div> </div>

View file

@ -6,9 +6,11 @@ import { DateTime } from 'luxon'
import type { AccountCategory } from '@prisma/client' import type { AccountCategory } from '@prisma/client'
export type AccountValuationFields = { export type AccountValuationFields = {
stockSymbol: string | null
startDate: string | null startDate: string | null
originalBalance: number | null originalBalance: number | null
currentBalance: number | null currentBalance: number | null
numberShares: number | null
} }
// Property // Property

View file

@ -56,6 +56,11 @@ export const CATEGORIES: Record<AccountCategory, SharedType.NormalizedCategory>
singular: 'Vehicle', singular: 'Vehicle',
plural: 'Vehicles', plural: 'Vehicles',
}, },
stock: {
value: 'stock',
singular: 'Stock',
plural: 'Stocks',
},
other: { other: {
value: 'other', value: 'other',
singular: 'Other', singular: 'Other',
@ -81,7 +86,7 @@ export const CATEGORY_MAP_SIMPLE: Record<AccountType, AccountCategory[]> = {
LOAN: ['loan'], LOAN: ['loan'],
PROPERTY: ['property'], PROPERTY: ['property'],
VEHICLE: ['vehicle'], VEHICLE: ['vehicle'],
OTHER_ASSET: ['cash', 'investment', 'crypto', 'valuable', 'other'], OTHER_ASSET: ['stock', 'cash', 'investment', 'crypto', 'valuable', 'other'],
OTHER_LIABILITY: ['other'], OTHER_LIABILITY: ['other'],
} }

42279
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "AccountCategory" ADD VALUE 'stock';

View file

@ -94,6 +94,7 @@ enum AccountType {
} }
enum AccountCategory { enum AccountCategory {
stock
cash cash
investment investment
crypto crypto

View file

@ -4614,9 +4614,9 @@
"@types/node" "*" "@types/node" "*"
"@types/node@*", "@types/node@>=8.1.0": "@types/node@*", "@types/node@>=8.1.0":
version "20.11.3" version "20.11.4"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.3.tgz#ac29fba7aeadc74046b02e50758156f4850f1296" resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.4.tgz#c724a5d6723182af758b91b994209336f4439cb7"
integrity sha512-nrlmbvGPNGaj84IJZXMPhQuCMEVTT/hXZMJJG/aIqVL9fKxqk814sGGtJA4GI6hpJSLQjpi6cn0Qx9eOf9SDVg== integrity sha512-6I0fMH8Aoy2lOejL3s4LhyIYX34DPwY8bl5xlNjBvUEk8OHrcuzsFt+Ied4LvJihbtXPM+8zUqdydfIti86v9g==
dependencies: dependencies:
undici-types "~5.26.4" undici-types "~5.26.4"
@ -7202,9 +7202,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0" lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001426, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001565: caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001406, caniuse-lite@^1.0.30001426, caniuse-lite@^1.0.30001538, caniuse-lite@^1.0.30001565:
version "1.0.30001576" version "1.0.30001577"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001576.tgz#893be772cf8ee6056d6c1e2d07df365b9ec0a5c4" resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001577.tgz#a24991eb4ad67324ba8b96716340d53151f2f6f8"
integrity sha512-ff5BdakGe2P3SQsMsiqmt1Lc8221NR1VzHj5jXN5vBny9A6fpze94HiVV/n7XRosOlsShJcvMv5mdnpjOGCEgg== integrity sha512-rs2ZygrG1PNXMfmncM0B5H1hndY5ZCC9b5TkFaVNfZ+AUlyqcMyVIQtc3fsezi0NUCk5XZfDf9WS6WxMxnfdrg==
capture-exit@^2.0.0: capture-exit@^2.0.0:
version "2.0.0" version "2.0.0"
@ -8906,9 +8906,9 @@ ejs@^3.1.7, ejs@^3.1.8:
jake "^10.8.5" jake "^10.8.5"
electron-to-chromium@^1.4.601: electron-to-chromium@^1.4.601:
version "1.4.631" version "1.4.632"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.631.tgz#db2de2e1ce90fc1785b5c3f49fde594413270e05" resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.632.tgz#df6253483b802eb83eee2fdc0e5067bd46f36f11"
integrity sha512-g73CJB/rMPjdxpiNJYmV1homV7mLVUNe/R0z/HhqMfpjkt58FpYmkTjbtuv3zymdbTTJ+VOEqe1c+lkTjSOhmQ== integrity sha512-JGmudTwg7yxMYvR/gWbalqqQiyu7WTFv2Xu3vw4cJHXPFxNgAk0oy8UHaer8nLF4lZJa+rNoj6GsrKIVJTV6Tw==
elliptic@^6.5.3, elliptic@^6.5.4: elliptic@^6.5.3, elliptic@^6.5.4:
version "6.5.4" version "6.5.4"