mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 04:26:57 +00:00
Use tRPC and react-hook-form
This commit is contained in:
@@ -1,56 +1,12 @@
|
||||
import { Dispatch, FormEvent, SetStateAction } from "react";
|
||||
|
||||
import { LatLngLiteral } from "leaflet";
|
||||
import { useTranslations } from "next-intl";
|
||||
|
||||
import { clearMessage } from "@/app/[lang]/components/InfoMessage";
|
||||
import discordWebhook from "@/lib/discordWebhook";
|
||||
import sendMail from "@/lib/sendMail";
|
||||
import tournamentFormToDB from "@/lib/tournamentFormToDB";
|
||||
import { ResponseMessage, TournamentFormProps } from "@/types";
|
||||
import { ResponseMessage } from "@/types";
|
||||
import { errorLog } from "@/utils/logger";
|
||||
|
||||
export const handleClearTournamentForm = (
|
||||
formRefs: TournamentFormProps,
|
||||
center: LatLngLiteral,
|
||||
) => {
|
||||
Object.values(formRefs).forEach((ref) => {
|
||||
if (ref.current) ref.current.value = "";
|
||||
});
|
||||
formRefs.setPosition(center);
|
||||
};
|
||||
|
||||
export const handleTournamentSubmit = async (
|
||||
e: FormEvent<HTMLFormElement>,
|
||||
t: ReturnType<typeof useTranslations>,
|
||||
setIsSending: Dispatch<SetStateAction<boolean>>,
|
||||
setResponseMessage: Dispatch<SetStateAction<ResponseMessage>>,
|
||||
formRefs: TournamentFormProps,
|
||||
) => {
|
||||
e.preventDefault();
|
||||
setIsSending(true);
|
||||
|
||||
try {
|
||||
await discordWebhook(formRefs); // send Discord notification
|
||||
await tournamentFormToDB(formRefs); // write to DB
|
||||
setIsSending(false);
|
||||
setResponseMessage({
|
||||
isSuccessful: true,
|
||||
message: t("success"),
|
||||
});
|
||||
clearMessage(setResponseMessage);
|
||||
} catch (error) {
|
||||
errorLog(error);
|
||||
setResponseMessage({
|
||||
isSuccessful: false,
|
||||
message: t("failure"),
|
||||
});
|
||||
clearMessage(setResponseMessage);
|
||||
} finally {
|
||||
setIsSending(false);
|
||||
}
|
||||
};
|
||||
|
||||
export const handleEmailSubmit = async (
|
||||
e: FormEvent<HTMLFormElement>,
|
||||
t: ReturnType<typeof useTranslations>,
|
||||
|
||||
Reference in New Issue
Block a user