Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mobile): prevent set budget amount zero #346

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/mobile/app/(app)/budget/[budgetId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function BudgetDetailScreen() {
push
>
<Button size="icon" variant="ghost">
<SettingsIcon className="size-6 text-primary" />
<SettingsIcon className="size-6 text-foreground" />
</Button>
</Link>
</View>
Expand Down
15 changes: 9 additions & 6 deletions apps/mobile/stores/budget/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,15 @@ export function useBudgetPeriodStats(

const remainingAmount = budgetAmount.add(totalBudgetUsage)

const usagePercentage = (
totalBudgetUsage.gt(0) ? new Decimal(0) : totalBudgetUsage.abs()
)
.div(budgetAmount!)
.mul(100)
.toNumber()
const usagePercentage = useMemo(() => {
if (budgetAmount.eq(0)) {
return 0
}
return (totalBudgetUsage.gt(0) ? new Decimal(0) : totalBudgetUsage.abs())
.div(budgetAmount!)
.mul(100)
.toNumber()
}, [totalBudgetUsage, budgetAmount])

const averageAmountPerDay = budgetAmount.div(
dayjsExtended(periodConfig?.endDate!).diff(
Expand Down
4 changes: 2 additions & 2 deletions packages/validation/src/budget.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const zCreateBudget = z.object({
amount: z
.string({ coerce: true })
.transform((val) => Number(`${val}`.replace(',', '.')))
.pipe(z.number({ coerce: true }).min(0))
.pipe(z.number({ coerce: true }).min(1))
.optional(),
startDate: z.date({ coerce: true }).optional(),
endDate: z.date({ coerce: true }).optional(),
Expand All @@ -41,7 +41,7 @@ export const zUpdateBudget = z.object({
amount: z
.string({ coerce: true })
.transform((val) => Number(`${val}`.replace(',', '.')))
.pipe(z.number({ coerce: true }).min(0))
.pipe(z.number({ coerce: true }).min(1))
.optional(),
startDate: z.date({ coerce: true }).optional(),
endDate: z.date({ coerce: true }).optional(),
Expand Down
Loading