frontAnswerer/lib/components/ViewPublicationPage/ContactForm/Inputs/Inputs.tsx

120 lines
3.2 KiB
TypeScript
Raw Normal View History

import { useQuizSettings } from "@contexts/QuizDataContext.ts";
import NameIcon from "@icons/ContactFormIcon/NameIcon.tsx";
import EmailIcon from "@icons/ContactFormIcon/EmailIcon.tsx";
import TextIcon from "@icons/ContactFormIcon/TextIcon.tsx";
import AddressIcon from "@icons/ContactFormIcon/AddressIcon.tsx";
2024-05-31 16:41:18 +00:00
import { Dispatch, SetStateAction } from "react";
import { CustomInput } from "@/components/ViewPublicationPage/ContactForm/CustomInput/CustomInput.tsx";
import PhoneIcon from "@icons/ContactFormIcon/PhoneIcon.tsx";
import PhoneInput from "react-phone-number-input";
2025-04-20 15:16:22 +00:00
import { useTranslation } from "react-i18next";
type InputsProps = {
2024-05-31 16:41:18 +00:00
name: string;
setName: Dispatch<SetStateAction<string>>;
email: string;
setEmail: Dispatch<SetStateAction<string>>;
phone: string;
setPhone: Dispatch<SetStateAction<string>>;
text: string;
setText: Dispatch<SetStateAction<string>>;
adress: string;
setAdress: Dispatch<SetStateAction<string>>;
crutch: {
disableEmail: boolean;
};
};
export const Inputs = ({
2024-05-31 16:41:18 +00:00
name,
setName,
email,
setEmail,
phone,
setPhone,
text,
setText,
adress,
setAdress,
crutch,
2024-05-31 16:41:18 +00:00
}: InputsProps) => {
const { settings } = useQuizSettings();
2025-04-20 15:16:22 +00:00
const { t } = useTranslation();
2024-05-31 16:41:18 +00:00
const FC = settings.cfg.formContact.fields;
2024-05-31 16:41:18 +00:00
if (!FC) return null;
const Name = (
<CustomInput
onChange={({ target }) => setName(target.value)}
id={name}
2025-04-20 15:16:22 +00:00
title={FC["name"].innerText || `${t("Enter")} ${t("Name").toLowerCase()}`}
desc={FC["name"].text || t("Name")}
2024-05-31 16:41:18 +00:00
Icon={NameIcon}
/>
);
const Email = (
<CustomInput
onChange={({ target }) => {
setEmail(target.value.replaceAll(/\s/g, ""));
}}
2024-05-31 16:41:18 +00:00
id={email}
2025-04-20 15:16:22 +00:00
title={FC["email"].innerText || `${t("Enter")} Email`}
2024-05-31 16:41:18 +00:00
desc={FC["email"].text || "Email"}
Icon={EmailIcon}
type="email"
2024-05-31 16:41:18 +00:00
/>
);
const Phone = (
<CustomInput
2024-07-11 20:12:13 +00:00
onChange={({ target }) => setText(target.value)}
onChangePhone={(phone: string) => {
setPhone(phone);
}}
value={phone}
2024-05-31 16:41:18 +00:00
id={phone}
2025-04-20 15:16:22 +00:00
title={FC["phone"].innerText || `${t("Enter")} ${t("Phone number").toLowerCase()}`}
desc={FC["phone"].text || t("Phone number")}
2024-05-31 16:41:18 +00:00
Icon={PhoneIcon}
isPhone={true}
/>
);
const Text = (
<CustomInput
onChange={({ target }) => setText(target.value)}
id={text}
2025-04-20 15:16:22 +00:00
title={FC["text"].text || `${t("Enter")} ${t("Last name").toLowerCase()}`}
desc={FC["text"].innerText || t("Last name")}
2024-05-31 16:41:18 +00:00
Icon={TextIcon}
/>
);
const Adress = (
<CustomInput
onChange={({ target }) => setAdress(target.value)}
id={adress}
2025-04-20 15:16:22 +00:00
title={FC["address"].innerText || `${t("Enter")} ${t("Address").toLowerCase()}`}
desc={FC["address"].text || t("Address")}
2024-05-31 16:41:18 +00:00
Icon={AddressIcon}
/>
);
if (Object.values(FC).some((data) => data.used)) {
return (
<>
{FC["name"].used ? Name : <></>}
{FC["email"].used && !crutch.disableEmail ? Email : <></>}
2024-05-31 16:41:18 +00:00
{FC["phone"].used ? Phone : <></>}
{FC["text"].used ? Text : <></>}
{FC["address"].used ? Adress : <></>}
</>
);
2024-05-31 16:41:18 +00:00
} else {
return (
<>
{Name}
{Email}
{Phone}
</>
);
2024-05-31 16:41:18 +00:00
}
};