284 lines
8.3 KiB
TypeScript
284 lines
8.3 KiB
TypeScript
import { useForm } from "@inertiajs/react";
|
|
import { ArrowRight } from "lucide-react";
|
|
import { useState } from "react";
|
|
|
|
import Checkbox from "@/front/Components/Form/Checkbox";
|
|
import FormSelect from "@/front/Components/Form/FormSelect";
|
|
import SuccessModel from "@/front/Components/Form/SuccessModel";
|
|
import TextArea from "@/front/Components/Form/TextArea";
|
|
import TextInput from "@/front/Components/Form/TextInput";
|
|
import CtaButton from "@/front/Components/Layout/CtaButton";
|
|
import { useToast } from "@/hooks/use-toast";
|
|
import useTrans from "@/hooks/use-translations";
|
|
import { GetTranslation } from "@/lib/utils";
|
|
|
|
import RecaptchaForm from "../cookie/recaptcha/RecaptchaForm";
|
|
|
|
interface Option {
|
|
label: string;
|
|
value: string;
|
|
}
|
|
|
|
interface JoinGroupFormProps {
|
|
communities: Option[];
|
|
}
|
|
|
|
export default function JoinGroupForm({
|
|
communities,
|
|
}: Readonly<JoinGroupFormProps>) {
|
|
const { data, setData, errors, post, processing, reset } = useForm({
|
|
lastName: "",
|
|
firstName: "",
|
|
email: "",
|
|
role: "",
|
|
company: "",
|
|
community: "",
|
|
phone: "",
|
|
message: "",
|
|
supportsManifesto: false,
|
|
acceptsUsage: false,
|
|
"g-recaptcha-response": "",
|
|
});
|
|
|
|
const { toast } = useToast();
|
|
const [showSuccess, setShowSuccess] = useState(false);
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
const handleSubmit: React.FormEventHandler<HTMLFormElement> = (e) => {
|
|
e.preventDefault();
|
|
|
|
post(route("front.join-group.store"), {
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
setShowSuccess(true);
|
|
reset();
|
|
window.grecaptcha?.reset();
|
|
},
|
|
onError: () => {
|
|
toast({
|
|
title: "Erreur",
|
|
variant: "destructive",
|
|
description:
|
|
"Une erreur est survenue. Veuillez vérifier les champs et réessayer.",
|
|
});
|
|
},
|
|
});
|
|
};
|
|
|
|
const submitLabel = useTrans("join_group_page.form.buttons.submit");
|
|
const submittingLabel = useTrans("join_group_page.form.buttons.submitting");
|
|
|
|
return (
|
|
<>
|
|
<RecaptchaForm
|
|
data={data}
|
|
onSubmit={handleSubmit}
|
|
classNames={{ formClassName: "flex flex-col gap-4" }}
|
|
footer={
|
|
<div className="mt-4 flex justify-center">
|
|
<CtaButton
|
|
type="submit"
|
|
icon={<ArrowRight />}
|
|
iconPosition="right"
|
|
color="rouge"
|
|
width="w-full lg:w-[280px]"
|
|
>
|
|
{processing ? submittingLabel : submitLabel}
|
|
</CtaButton>
|
|
</div>
|
|
}
|
|
>
|
|
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 lg:gap-30">
|
|
<div>
|
|
<TextInput
|
|
name="lastName"
|
|
label={useTrans("contact_page.form.placeholders.last_name")}
|
|
value={data.lastName}
|
|
onChange={(e) => {
|
|
setData("lastName", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.firstName}
|
|
/>
|
|
{errors.lastName && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.lastName}
|
|
</p>
|
|
)}
|
|
</div>
|
|
<div>
|
|
<TextInput
|
|
name="firstName"
|
|
label={useTrans("contact_page.form.placeholders.first_name")}
|
|
value={data.firstName}
|
|
onChange={(e) => {
|
|
setData("firstName", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.firstName}
|
|
/>
|
|
{errors.firstName && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.firstName}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<TextInput
|
|
name="email"
|
|
type="email"
|
|
label={useTrans("contact_page.form.placeholders.email")}
|
|
value={data.email}
|
|
onChange={(e) => {
|
|
setData("email", e.target.value.toLowerCase());
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.email}
|
|
/>
|
|
{errors.email && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.email}
|
|
</p>
|
|
)}
|
|
|
|
<TextInput
|
|
name="role"
|
|
label={useTrans("join_group_page.form.placeholders.role")}
|
|
value={data.role}
|
|
onChange={(e) => {
|
|
setData("role", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.role}
|
|
/>
|
|
{errors.role && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.role}
|
|
</p>
|
|
)}
|
|
|
|
<TextInput
|
|
name="company"
|
|
label={useTrans("contact_page.form.placeholders.company")}
|
|
value={data.company}
|
|
onChange={(e) => {
|
|
setData("company", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.company}
|
|
/>
|
|
{errors.company && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.company}
|
|
</p>
|
|
)}
|
|
|
|
<FormSelect
|
|
name="community"
|
|
label={useTrans("join_group_page.form.placeholders.community")}
|
|
options={communities}
|
|
value={data.community}
|
|
onChange={(e) => {
|
|
setData("community", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.community}
|
|
/>
|
|
{errors.community && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.community}
|
|
</p>
|
|
)}
|
|
|
|
<TextInput
|
|
name="phone"
|
|
type="tel"
|
|
label={useTrans("contact_page.form.placeholders.phone")}
|
|
value={data.phone}
|
|
onChange={(e) => {
|
|
setData("phone", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.phone}
|
|
/>
|
|
{errors.phone && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.phone}
|
|
</p>
|
|
)}
|
|
|
|
<div>
|
|
<TextArea
|
|
name="message"
|
|
label={useTrans("join_group_page.form.placeholders.message")}
|
|
value={data.message}
|
|
onChange={(e) => {
|
|
setData("message", e.target.value);
|
|
}}
|
|
required
|
|
disabled={processing}
|
|
error={errors.message}
|
|
/>
|
|
{errors.message && (
|
|
<p className="mt-1 font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.message}
|
|
</p>
|
|
)}
|
|
</div>
|
|
|
|
<div className="mt-2 flex flex-col gap-3">
|
|
<Checkbox
|
|
checked={data.supportsManifesto}
|
|
onChange={(e) => {
|
|
setData("supportsManifesto", e.target.checked);
|
|
}}
|
|
label={GetTranslation("join_group_page.form.checkboxes.manifesto")}
|
|
disabled={processing}
|
|
labelStyle="text-[14px] lg:text-body"
|
|
/>
|
|
|
|
<Checkbox
|
|
checked={data.acceptsUsage}
|
|
onChange={(e) => {
|
|
setData("acceptsUsage", e.target.checked);
|
|
}}
|
|
label={
|
|
<span
|
|
dangerouslySetInnerHTML={{
|
|
__html: GetTranslation(
|
|
"join_group_page.form.checkboxes.usage",
|
|
),
|
|
}}
|
|
/>
|
|
}
|
|
disabled={processing}
|
|
labelStyle="text-[14px] lg:text-body"
|
|
error={errors.acceptsUsage}
|
|
/>
|
|
{errors.acceptsUsage && (
|
|
<p className="font-poppins-regular text-[12px] lg:text-small text-rouge">
|
|
{errors.acceptsUsage}
|
|
</p>
|
|
)}
|
|
</div>
|
|
</RecaptchaForm>
|
|
|
|
<SuccessModel
|
|
isOpen={showSuccess}
|
|
onClose={() => {
|
|
setShowSuccess(false);
|
|
}}
|
|
title={useTrans("join_group_page.success.title")}
|
|
message={useTrans("join_group_page.success.message")}
|
|
/>
|
|
</>
|
|
);
|
|
}
|