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/date to string #990

Merged
merged 4 commits into from
Aug 13, 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
15 changes: 9 additions & 6 deletions app/(app)/alpha/additional-details/_client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
slideThreeSchema,
} from "@/schema/additionalUserDetails";
import { zodResolver } from "@hookform/resolvers/zod";
import { useForm, useFormContext } from "react-hook-form";
import { useForm } from "react-hook-form";

import { toast } from "sonner";
import {
Expand All @@ -33,7 +33,7 @@ type UserDetails = {
firstName: string;
surname: string;
gender: string;
dateOfBirth: Date | undefined;
dateOfBirth: string;
location: string;
professionalOrStudent: string;
course: string;
Expand Down Expand Up @@ -236,13 +236,16 @@ function SlideTwo({ details }: { details: UserDetails }) {
defaultValues: { dateOfBirth, gender },
});

const parsedDateOfBirth = dateOfBirth ? new Date(dateOfBirth) : null;
const [year, setYear] = useState<number | undefined>(
dateOfBirth?.getFullYear(),
parsedDateOfBirth?.getFullYear(),
);
const [month, setMonth] = useState<number | undefined>(
dateOfBirth?.getMonth(),
parsedDateOfBirth?.getMonth(),
);
const [day, setDay] = useState<number | undefined>(
parsedDateOfBirth?.getDate(),
);
const [day, setDay] = useState<number | undefined>(dateOfBirth?.getDate());

const [listOfDaysInSelectedMonth, setListOfDaysInSelectedMonth] = useState([
0,
Expand Down Expand Up @@ -271,7 +274,7 @@ function SlideTwo({ details }: { details: UserDetails }) {
} else {
selectedDate = new Date(year, month, day);
}
setValue("dateOfBirth", selectedDate);
setValue("dateOfBirth", selectedDate.toISOString());
}
}, [year, month, day]);

Expand Down
2 changes: 1 addition & 1 deletion app/(app)/alpha/additional-details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async function Page() {
firstName: details?.firstName || "",
surname: details?.surname || "",
gender: details?.gender || "",
dateOfBirth: details?.dateOfBirth || undefined,
dateOfBirth: details?.dateOfBirth || "",
location: details?.location || "",
professionalOrStudent: details?.professionalOrStudent || "",
course: details?.course || "",
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion schema/additionalUserDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const slideOneSchema = z.object({

export const slideTwoSchema = z.object({
gender: z.string().min(1, "Gender is required"),
dateOfBirth: z.date(),
dateOfBirth: z.string(),
});

export const slideThreeSchema = z
Expand Down