"use client"; import { SettingsSection, SettingsSectionBody, SettingsSectionDescription, SettingsSectionForm, SettingsSectionHeader, SettingsSectionTitle } from "@app/components/Settings"; import { useTranslations } from "next-intl"; import z from "zod"; import { type PolicyFormValues } from "."; import { SwitchInput } from "@app/components/SwitchInput"; import { Tag, TagInput } from "@app/components/tags/tag-input"; import { Alert, AlertDescription, AlertTitle } from "@app/components/ui/alert"; import { Button } from "@app/components/ui/button"; import { FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from "@app/components/ui/form"; import { InfoPopup } from "@app/components/ui/info-popup"; import { InfoIcon, Plus } from "lucide-react"; import { useState } from "react"; import { type UseFormReturn } from "react-hook-form"; // ─── CreatePolicyOtpEmailSectionForm ────────────────────────────────────────── export type CreatePolicyOtpEmailSectionFormProps = { form: UseFormReturn; emailEnabled: boolean; }; export function CreatePolicyOtpEmailSectionForm({ form, emailEnabled }: CreatePolicyOtpEmailSectionFormProps) { const t = useTranslations(); const [isOpen, setIsOpen] = useState(false); const [whitelistEnabled, setWhitelistEnabled] = useState(false); const [activeEmailTagIndex, setActiveEmailTagIndex] = useState< number | null >(null); if (!isOpen) { return ( {t("otpEmailTitle")} {t("otpEmailTitleDescription")} ); } return ( {t("otpEmailTitle")} {t("otpEmailTitleDescription")} {!emailEnabled && ( {t("otpEmailSmtpRequired")} {t("otpEmailSmtpRequiredDescription")} )} { setWhitelistEnabled(val); form.setValue("emailWhitelistEnabled", val); }} disabled={!emailEnabled} /> {whitelistEnabled && emailEnabled && ( ( {/* @ts-ignore */} { return z .email() .or( z .string() .regex( /^\*@[\w.-]+\.[a-zA-Z]{2,}$/, { message: t( "otpEmailErrorInvalid" ) } ) ) .safeParse(tag).success; }} setActiveTagIndex={ setActiveEmailTagIndex } placeholder={t("otpEmailEnter")} tags={form.getValues().emails} setTags={(newEmails) => { form.setValue( "emails", newEmails as [Tag, ...Tag[]] ); }} allowDuplicates={false} sortTags={true} /> {t("otpEmailEnterDescription")} )} /> )} ); }