diff --git a/apps/demo/src/Create.tsx b/apps/demo/src/Create.tsx index 2b4cdd2..9e632bf 100644 --- a/apps/demo/src/Create.tsx +++ b/apps/demo/src/Create.tsx @@ -21,15 +21,22 @@ import { Page, PageProps } from "./App"; export const Create = ({ changePage }: PageProps) => { const { toast } = useToastProvider(); - const inputRef = React.useRef(null); - const submit = () => { + const submit: React.FormEventHandler = (e) => { + e.preventDefault(); + const formData = new FormData(e.target as HTMLFormElement); + const fakeDates = randomDates(); const character: Character = { id: faker.string.uuid(), - name: inputRef.current?.value || "", - sex: "male", - isGuest: false, - ...randomDates(), + name: (formData.get("name") as any) || "", + sex: (formData.get("sex") as any) || "", + isGuest: (formData.get("is_guest") as any) || "", + birthDate: + new Date(formData.get("birthdate") as any) || fakeDates.birthDate, + firstAppearanceDate: + new Date(formData.get("appearance_dates_start") as any) || + fakeDates.firstAppearanceDate, + lastAppearanceDate: fakeDates.lastAppearanceDate, }; database.unshift(character); @@ -38,7 +45,7 @@ export const Create = ({ changePage }: PageProps) => { }; return ( -
+

Add a character

General Information

@@ -46,30 +53,35 @@ export const Create = ({ changePage }: PageProps) => { You are about to add a new character to the collection