Skip to content

Commit 1ce593f

Browse files
Fix/date to string (#990)
* update drizzle-kit * convert dateOfBirth to iso String * update Date object to String --------- Co-authored-by: Niall Maher <[email protected]>
1 parent 6aff8bb commit 1ce593f

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

app/(app)/alpha/additional-details/_client.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
slideThreeSchema,
1313
} from "@/schema/additionalUserDetails";
1414
import { zodResolver } from "@hookform/resolvers/zod";
15-
import { useForm, useFormContext } from "react-hook-form";
15+
import { useForm } from "react-hook-form";
1616

1717
import { toast } from "sonner";
1818
import {
@@ -33,7 +33,7 @@ type UserDetails = {
3333
firstName: string;
3434
surname: string;
3535
gender: string;
36-
dateOfBirth: Date | undefined;
36+
dateOfBirth: string;
3737
location: string;
3838
professionalOrStudent: string;
3939
course: string;
@@ -236,13 +236,16 @@ function SlideTwo({ details }: { details: UserDetails }) {
236236
defaultValues: { dateOfBirth, gender },
237237
});
238238

239+
const parsedDateOfBirth = dateOfBirth ? new Date(dateOfBirth) : null;
239240
const [year, setYear] = useState<number | undefined>(
240-
dateOfBirth?.getFullYear(),
241+
parsedDateOfBirth?.getFullYear(),
241242
);
242243
const [month, setMonth] = useState<number | undefined>(
243-
dateOfBirth?.getMonth(),
244+
parsedDateOfBirth?.getMonth(),
245+
);
246+
const [day, setDay] = useState<number | undefined>(
247+
parsedDateOfBirth?.getDate(),
244248
);
245-
const [day, setDay] = useState<number | undefined>(dateOfBirth?.getDate());
246249

247250
const [listOfDaysInSelectedMonth, setListOfDaysInSelectedMonth] = useState([
248251
0,
@@ -271,7 +274,7 @@ function SlideTwo({ details }: { details: UserDetails }) {
271274
} else {
272275
selectedDate = new Date(year, month, day);
273276
}
274-
setValue("dateOfBirth", selectedDate);
277+
setValue("dateOfBirth", selectedDate.toISOString());
275278
}
276279
}, [year, month, day]);
277280

app/(app)/alpha/additional-details/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default async function Page() {
3232
firstName: details?.firstName || "",
3333
surname: details?.surname || "",
3434
gender: details?.gender || "",
35-
dateOfBirth: details?.dateOfBirth || undefined,
35+
dateOfBirth: details?.dateOfBirth || "",
3636
location: details?.location || "",
3737
professionalOrStudent: details?.professionalOrStudent || "",
3838
course: details?.course || "",

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schema/additionalUserDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const slideOneSchema = z.object({
2525

2626
export const slideTwoSchema = z.object({
2727
gender: z.string().min(1, "Gender is required"),
28-
dateOfBirth: z.date(),
28+
dateOfBirth: z.string(),
2929
});
3030

3131
export const slideThreeSchema = z

0 commit comments

Comments
 (0)