mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Prepare endpoint
This commit is contained in:
@@ -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<typeof fetchTournamentResultsSchema>;
|
||||||
|
|
||||||
|
export const FetchResultsForm = () => {
|
||||||
|
const t = useTranslations("Elo");
|
||||||
|
const fetchResults = trpc.fetchTournamentResults.useMutation();
|
||||||
|
|
||||||
|
const form = useForm<FetchResultsFormValues>({
|
||||||
|
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 (
|
||||||
|
<FormProvider {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
||||||
|
<div className="flex items-end gap-4">
|
||||||
|
<TextField
|
||||||
|
name="url"
|
||||||
|
label={t("resultsUrlLabel")}
|
||||||
|
placeholder={t("resultsUrlLabel")}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
disabled={form.formState.isSubmitting}
|
||||||
|
type="submit"
|
||||||
|
className="rounded-lg border border-transparent bg-primary-600 px-5 py-3 text-center text-sm font-medium text-white hover:bg-primary-800 focus:outline-none focus:ring-4 focus:ring-primary-300 disabled:opacity-25 dark:text-white dark:hover:bg-primary-700 dark:focus:ring-primary-800 sm:w-fit"
|
||||||
|
>
|
||||||
|
{t("fetchResultsButton")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</FormProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import { de } from "date-fns/locale";
|
|
||||||
import { isEmpty, isNil, isNumber } from "lodash";
|
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { FormProvider, useFieldArray, useForm } from "react-hook-form";
|
import { FormProvider, useFieldArray, useForm } from "react-hook-form";
|
||||||
import { IoAdd, IoCloseOutline } from "react-icons/io5";
|
import { IoAdd, IoCloseOutline } from "react-icons/io5";
|
||||||
@@ -12,6 +10,8 @@ import { z } from "zod";
|
|||||||
import { SelectField } from "@/components/form/SelectField";
|
import { SelectField } from "@/components/form/SelectField";
|
||||||
import { TextField } from "@/components/form/TextField";
|
import { TextField } from "@/components/form/TextField";
|
||||||
|
|
||||||
|
import { FetchResultsForm } from "./FetchResultsForm";
|
||||||
|
|
||||||
const getNewRating = (
|
const getNewRating = (
|
||||||
rating: number,
|
rating: number,
|
||||||
opponentRating: number,
|
opponentRating: number,
|
||||||
@@ -125,6 +125,10 @@ export default function Elo() {
|
|||||||
{t("info")}
|
{t("info")}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
<div className="mb-10">
|
||||||
|
<FetchResultsForm />
|
||||||
|
</div>
|
||||||
|
|
||||||
<FormProvider {...form}>
|
<FormProvider {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
<div className="grid w-full grid-cols-1 gap-2 sm:grid-cols-2">
|
<div className="grid w-full grid-cols-1 gap-2 sm:grid-cols-2">
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { addTournament } from "./procedures/addTournament";
|
import { addTournament } from "./procedures/addTournament";
|
||||||
|
import { fetchTournamentResults } from "./procedures/fetchTournamentResults";
|
||||||
import { router } from "./trpc";
|
import { router } from "./trpc";
|
||||||
|
|
||||||
export const appRouter = router({
|
export const appRouter = router({
|
||||||
addTournament,
|
addTournament,
|
||||||
|
fetchTournamentResults,
|
||||||
});
|
});
|
||||||
|
|
||||||
export type AppRouter = typeof appRouter;
|
export type AppRouter = typeof appRouter;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
+5
-1
@@ -133,6 +133,10 @@
|
|||||||
"opponentEloPlaceholder": "Classement de l'adversaire",
|
"opponentEloPlaceholder": "Classement de l'adversaire",
|
||||||
"gameResultPlaceholder": "Résultat...",
|
"gameResultPlaceholder": "Résultat...",
|
||||||
"gameResult": "{result, select, win {Victoire} draw {Match nul} loss {Défaite} other {{result}}}",
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,3 +20,7 @@ export const addTournamentSchema = z.object({
|
|||||||
country: z.string().min(1, { message: "FormValidation.required" }),
|
country: z.string().min(1, { message: "FormValidation.required" }),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const fetchTournamentResultsSchema = z.object({
|
||||||
|
url: z.string().url({ message: "FormValidation.url" }),
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user