From 432baf4c7c03c81999759be17b6b39e9c5e3f5e2 Mon Sep 17 00:00:00 2001 From: Owen Date: Wed, 10 Dec 2025 16:07:33 +0100 Subject: [PATCH] pass form data to server component --- .../[locale]/(main)/components/Calendar.tsx | 3 - src/app/[locale]/(main)/match/MatchForm.tsx | 62 +++++++++++++------ .../(main)/match/components/TeamSelection.tsx | 10 +-- src/schemas.ts | 2 +- src/server/generateFeuilleDeMatch.ts | 15 +++++ 5 files changed, 61 insertions(+), 31 deletions(-) create mode 100644 src/server/generateFeuilleDeMatch.ts diff --git a/src/app/[locale]/(main)/components/Calendar.tsx b/src/app/[locale]/(main)/components/Calendar.tsx index 046d825..698803b 100644 --- a/src/app/[locale]/(main)/components/Calendar.tsx +++ b/src/app/[locale]/(main)/components/Calendar.tsx @@ -4,12 +4,9 @@ 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; diff --git a/src/app/[locale]/(main)/match/MatchForm.tsx b/src/app/[locale]/(main)/match/MatchForm.tsx index f0f732a..a550529 100644 --- a/src/app/[locale]/(main)/match/MatchForm.tsx +++ b/src/app/[locale]/(main)/match/MatchForm.tsx @@ -1,49 +1,54 @@ "use client"; +import { useState } from "react"; + 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 { Button } from "@/components/Button"; +import InfoMessage, { InfoMessageType } from "@/components/InfoMessage"; import { TextField } from "@/components/form/TextField"; import { matchSchema } from "@/schemas"; +import { generateFeuilleDeMatch } from "@/server/generateFeuilleDeMatch"; import { Club } from "@/types"; -type MatchFormValues = z.infer; +export type MatchFormValues = z.infer; interface IProps { clubs: Club[]; } const MatchForm = ({ clubs }: IProps) => { + const [responseMessage, setResponseMessage] = useState<{ + type: InfoMessageType; + message: string; + } | null>(null); + const form = useForm({ - // resolver: zodResolver(addTournamentSchema), - // defaultValues: { - // tournament: { - // norm_tournament: false, - // coordinates: [47.0844, 2.3964], - // }, - // }, + resolver: zodResolver(matchSchema), }); const onSubmit = async (data: MatchFormValues) => { + console.log("submitting form with data: ", data); try { - console.log(data); - // await addTournament(data); - // setResponseMessage({ - // type: "success", - // message: t("success"), - // }); + await generateFeuilleDeMatch(data); + + setResponseMessage({ + type: "success", + message: "generated feuille de match", + }); // form.reset(); // do not reset the form } catch (err: unknown) { console.log(err); - // - // setResponseMessage({ - // type: "error", - // message: t("failure"), - // }); + + setResponseMessage({ + type: "error", + message: "error creating feuille de match", + }); } }; @@ -98,7 +103,24 @@ const MatchForm = ({ clubs }: IProps) => { className="col-span-3 space-y-4" /> - + +
+ + + +
+ + {responseMessage && ( + setResponseMessage(null)} + /> + )} ); diff --git a/src/app/[locale]/(main)/match/components/TeamSelection.tsx b/src/app/[locale]/(main)/match/components/TeamSelection.tsx index bf9255d..a1491c1 100644 --- a/src/app/[locale]/(main)/match/components/TeamSelection.tsx +++ b/src/app/[locale]/(main)/match/components/TeamSelection.tsx @@ -87,7 +87,6 @@ const TeamSelection = ({ name, label, clubOptions, className }: IProps) => { {label} - {/* Team/Club Select */} { )} /> - {/* Dynamic Player List */}
{fields.map((field, index) => (
(