diff --git a/src/app/[locale]/(main)/components/Calendar.tsx b/src/app/[locale]/(main)/components/Calendar.tsx new file mode 100644 index 0000000..046d825 --- /dev/null +++ b/src/app/[locale]/(main)/components/Calendar.tsx @@ -0,0 +1,57 @@ +import { useState } from "react"; + +import { format } from "date-fns"; +import { fr } from "date-fns/locale"; +import { Calendar } from "react-date-range"; +import "react-date-range/dist/styles.css"; +// main style file +import "react-date-range/dist/theme/default.css"; +import { Control, useController } from "react-hook-form"; + +// theme css file + +interface DateCalendarProps { + control: Control; + name: string; + label?: string; +} + +const DateCalendar = ({ control, name, label }: DateCalendarProps) => { + const { + field: { value, onChange }, + } = useController({ + name, + control, + }); + + const [open, setOpen] = useState(false); + + const handleSelect = (newDate: Date) => { + onChange(newDate); + setOpen(false); + }; + + return ( +
+ {label && ( + + )} + setOpen((prev) => !prev)} + placeholder="Sélectionner une date" + /> + {open && ( +
+ +
+ )} +
+ ); +}; + +export default DateCalendar; diff --git a/src/app/[locale]/(main)/match/MatchForm.tsx b/src/app/[locale]/(main)/match/MatchForm.tsx index a42e76b..f0f732a 100644 --- a/src/app/[locale]/(main)/match/MatchForm.tsx +++ b/src/app/[locale]/(main)/match/MatchForm.tsx @@ -4,7 +4,9 @@ import { zodResolver } from "@hookform/resolvers/zod"; import { FormProvider, useForm } from "react-hook-form"; import { z } from "zod"; +import Calendar from "@/app/[locale]/(main)/components/Calendar"; import TeamSelection from "@/app/[locale]/(main)/match/components/TeamSelection"; +import { TextField } from "@/components/form/TextField"; import { matchSchema } from "@/schemas"; import { Club } from "@/types"; @@ -34,7 +36,7 @@ const MatchForm = ({ clubs }: IProps) => { // message: t("success"), // }); - form.reset(); + // form.reset(); // do not reset the form } catch (err: unknown) { console.log(err); // @@ -54,16 +56,46 @@ const MatchForm = ({ clubs }: IProps) => { return (
-
+
+
+ +
+
+ +
+
+ +
+
+ +
diff --git a/src/app/[locale]/(main)/match/components/TeamSelection.tsx b/src/app/[locale]/(main)/match/components/TeamSelection.tsx index c0faf8c..bf9255d 100644 --- a/src/app/[locale]/(main)/match/components/TeamSelection.tsx +++ b/src/app/[locale]/(main)/match/components/TeamSelection.tsx @@ -18,6 +18,7 @@ import { fetchClubPlayers } from "@/server/fetchClubPlayers"; interface IProps { name: string; label: string; + className?: string; clubOptions: { value: string; label: string; @@ -25,7 +26,7 @@ interface IProps { }[]; } -const TeamSelection = ({ name, label, clubOptions }: IProps) => { +const TeamSelection = ({ name, label, clubOptions, className }: IProps) => { const [isLoading, setIsLoading] = useState(false); const { control } = useFormContext(); @@ -81,7 +82,7 @@ const TeamSelection = ({ name, label, clubOptions }: IProps) => { })) || []; return ( -
+
diff --git a/src/schemas.ts b/src/schemas.ts index c84e46e..d69751c 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -60,23 +60,23 @@ export const zoneSchema = z path: ["features"], }); -// export const fetchClubPlayersSchema = z.array( -// z.object({ -// nrFFE: z.string(), -// name: z.string(), -// elo: z.string(), -// elo_rapid: z.string(), -// elo_blitz: z.string(), -// category: z.string(), -// club: z.string(), -// }), -// ); - export const fetchClubPlayersSchema = z.object({ clubId: z.string(), }); +const matchPlayerSchema = z.object({ + name: z.string(), + elo: z.string(), + nrFFE: z.string(), +}); + export const matchSchema = z.object({ + competition: z.string(), + date: z.string(), + ronde: z.number(), + lieu: z.string(), team1: z.string(), team2: z.string(), + team1_players: z.array(matchPlayerSchema), + team2_players: z.array(matchPlayerSchema), });