Skip to content

Commit

Permalink
fix(gluwave): Entry input datetime is in past when using previously o…
Browse files Browse the repository at this point in the history
…pened tab #185
  • Loading branch information
Kalhama committed Oct 10, 2024
1 parent efe2ed5 commit 44f1f8c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
18 changes: 11 additions & 7 deletions gluwave/src/components/carbohydrate-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,15 @@ export function CarbohydrateDialog({
carb,
children,
}: PropsWithChildren<Props>) {
const defaultValues = {
carbs: carb?.carbs ?? 0,
timestamp: carb?.timestamp ?? new Date(),
decay: carb?.decay ?? 60,
id: carb?.id,
}
const form = useForm<z.infer<typeof ZPostCarbohydrateSchema>>({
resolver: zodResolver(ZPostCarbohydrateSchema),
defaultValues: {
carbs: carb?.carbs ?? 0,
timestamp: carb?.timestamp ?? new Date(),
decay: carb?.decay ?? 60,
id: carb?.id,
},
defaultValues,
})
const editing = !!carb?.id

Expand Down Expand Up @@ -91,7 +92,10 @@ export function CarbohydrateDialog({
open={open}
onOpenChange={(s) => {
if (!editing) {
form.reset()
form.reset({
...defaultValues,
timestamp: carb?.timestamp ?? new Date(),
})
}
setOpenChange(s)
}}
Expand Down
16 changes: 10 additions & 6 deletions gluwave/src/components/glucose-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ interface Props {
}

export function GlucoseDialog({ glucose, children }: PropsWithChildren<Props>) {
const defaultValues = {
value: glucose?.glucose ?? 7,
timestamp: glucose?.timestamp ?? new Date(),
id: glucose?.id,
}
const form = useForm<z.infer<typeof ZPostGlucoseSchema>>({
resolver: zodResolver(ZPostGlucoseSchema),
defaultValues: {
value: glucose?.glucose ?? 7,
timestamp: glucose?.timestamp ?? new Date(),
id: glucose?.id,
},
defaultValues,
})
const editing = !!glucose?.id
const post = trpc.glucose.post.useMutation()
Expand All @@ -73,7 +74,10 @@ export function GlucoseDialog({ glucose, children }: PropsWithChildren<Props>) {
<Drawer
open={open}
onOpenChange={(s) => {
form.reset()
form.reset({
...defaultValues,
timestamp: glucose?.timestamp ?? new Date(),
})
setOpenChange(s)
}}
>
Expand Down
16 changes: 10 additions & 6 deletions gluwave/src/components/insulin-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ interface Props {
}

export function InsulinDialog({ insulin, children }: PropsWithChildren<Props>) {
const defaultValues = {
amount: insulin?.amount ?? 0,
timestamp: insulin?.timestamp ?? new Date(),
id: insulin?.id,
}
const form = useForm<z.infer<typeof ZPostInsulinSchema>>({
resolver: zodResolver(ZPostInsulinSchema),
defaultValues: {
amount: insulin?.amount ?? 0,
timestamp: insulin?.timestamp ?? new Date(),
id: insulin?.id,
},
defaultValues,
})
const editing = !!insulin?.id

Expand All @@ -76,7 +77,10 @@ export function InsulinDialog({ insulin, children }: PropsWithChildren<Props>) {
<Drawer
open={open}
onOpenChange={(s) => {
form.reset()
form.reset({
...defaultValues,
timestamp: insulin?.timestamp ?? new Date(),
})
setOpenChange(s)
}}
>
Expand Down

0 comments on commit 44f1f8c

Please sign in to comment.