Skip to content

Commit

Permalink
feat: allow pass period config id when creating budget
Browse files Browse the repository at this point in the history
  • Loading branch information
duongdev committed Jul 20, 2024
1 parent 4ce7e52 commit 116aa64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/api/v1/services/budget.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export async function createBudget({
preferredCurrency,
periodConfigs: {
create: {
id: period.id,
type: period.type,
amount: period.amount,
startDate: period.startDate ?? periodConfig.startDate,
Expand Down
11 changes: 10 additions & 1 deletion apps/mobile/app/(app)/budget/new-budget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ export default function CreateBudgetScreen() {
const { sideOffset, ...rootProps } = useModalPortalRoot()

const handleCreate = async (data: BudgetFormValues) => {
mutateAsync({ data, id: createId() }).catch(() => {
mutateAsync({
data: {
...data,
period: {
...data.period,
id: createId(),
},
},
id: createId(),
}).catch(() => {
// ignore
})
router.back()
Expand Down
1 change: 1 addition & 0 deletions packages/validation/src/budget.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const zCreateBudget = z.object({
inviteeEmails: z.array(z.string().email()).optional(),
period: z
.object({
id: z.string().optional(),
type: BudgetPeriodTypeSchema,
amount: z.number({ coerce: true }).min(0),
startDate: z.date({ coerce: true }).optional(),
Expand Down

0 comments on commit 116aa64

Please # to comment.