diff --git a/app/[locale]/elo/FetchResultsForm.tsx b/app/[locale]/elo/FetchResultsForm.tsx new file mode 100644 index 0000000..8a552cc --- /dev/null +++ b/app/[locale]/elo/FetchResultsForm.tsx @@ -0,0 +1,54 @@ +"use client"; + +import { useState } from "react"; + +import { zodResolver } from "@hookform/resolvers/zod"; +import { useTranslations } from "next-intl"; +import { FormProvider, useForm } from "react-hook-form"; +import { z } from "zod"; + +import { TextField } from "@/components/form/TextField"; +import { fetchTournamentResultsSchema } from "@/schemas"; +import { trpc } from "@/utils/trpc"; + +type FetchResultsFormValues = z.infer; + +export const FetchResultsForm = () => { + const t = useTranslations("Elo"); + const fetchResults = trpc.fetchTournamentResults.useMutation(); + + const form = useForm({ + resolver: zodResolver(fetchTournamentResultsSchema), + }); + + const onSubmit = async (input: FetchResultsFormValues) => { + try { + const result = await fetchResults.mutateAsync(input); + console.log(result); + } catch (err: unknown) { + console.log(err); + } + }; + + return ( + +
+
+ + +
+
+
+ ); +}; diff --git a/app/[locale]/elo/page.tsx b/app/[locale]/elo/page.tsx index c010f09..5c5ff9f 100644 --- a/app/[locale]/elo/page.tsx +++ b/app/[locale]/elo/page.tsx @@ -1,8 +1,6 @@ "use client"; import { zodResolver } from "@hookform/resolvers/zod"; -import { de } from "date-fns/locale"; -import { isEmpty, isNil, isNumber } from "lodash"; import { useTranslations } from "next-intl"; import { FormProvider, useFieldArray, useForm } from "react-hook-form"; import { IoAdd, IoCloseOutline } from "react-icons/io5"; @@ -12,6 +10,8 @@ import { z } from "zod"; import { SelectField } from "@/components/form/SelectField"; import { TextField } from "@/components/form/TextField"; +import { FetchResultsForm } from "./FetchResultsForm"; + const getNewRating = ( rating: number, opponentRating: number, @@ -125,6 +125,10 @@ export default function Elo() { {t("info")}

+
+ +
+
diff --git a/app/server/appRouter.ts b/app/server/appRouter.ts index 5bfcc76..10dd13e 100644 --- a/app/server/appRouter.ts +++ b/app/server/appRouter.ts @@ -1,8 +1,10 @@ import { addTournament } from "./procedures/addTournament"; +import { fetchTournamentResults } from "./procedures/fetchTournamentResults"; import { router } from "./trpc"; export const appRouter = router({ addTournament, + fetchTournamentResults, }); export type AppRouter = typeof appRouter; diff --git a/app/server/procedures/fetchTournamentResults.ts b/app/server/procedures/fetchTournamentResults.ts new file mode 100644 index 0000000..f3c613a --- /dev/null +++ b/app/server/procedures/fetchTournamentResults.ts @@ -0,0 +1,19 @@ +import { fetchTournamentResultsSchema } from "@/schemas"; +import { errorLog } from "@/utils/logger"; + +import { publicProcedure } from "../trpc"; + +export const fetchTournamentResults = publicProcedure + .input(fetchTournamentResultsSchema) + .mutation(async ({ input }) => { + try { + console.log(input.url); + + // Fetch the tournament results using Python + + return true; + } catch (error) { + errorLog(error); + throw error; + } + }); diff --git a/messages/fr.json b/messages/fr.json index 17d7ee1..fc6d648 100644 --- a/messages/fr.json +++ b/messages/fr.json @@ -133,6 +133,10 @@ "opponentEloPlaceholder": "Classement de l'adversaire", "gameResultPlaceholder": "Résultat...", "gameResult": "{result, select, win {Victoire} draw {Match nul} loss {Défaite} other {{result}}}", - "addGameButton": "Ajouter un autre résultat de partie" + "addGameButton": "Ajouter un autre résultat de partie", + + "resultsUrlLabel": "Paste a link to the FFE results page", + "resultsUrlPlaceholder": "https://echecs.asso.fr/Resultats.aspx?URL=Tournois/Id/12345/12345&Action=Ga", + "fetchResultsButton": "Fetch" } } diff --git a/schemas.ts b/schemas.ts index e873f01..bce080b 100644 --- a/schemas.ts +++ b/schemas.ts @@ -20,3 +20,7 @@ export const addTournamentSchema = z.object({ country: z.string().min(1, { message: "FormValidation.required" }), }), }); + +export const fetchTournamentResultsSchema = z.object({ + url: z.string().url({ message: "FormValidation.url" }), +});