import { LightButton } from "@/components/ui/buttons"; import Input from "@/components/ui/Input"; import { LocaleSelector } from "@/components/ui/LocaleSelector"; import { X } from "lucide-react"; import { useRef, useState } from "react"; import { useTranslations } from "next-intl"; import { TSharedPair } from "@/shared/folder-type"; import { ActionInputUpdatePairById } from "@/modules/folder"; interface UpdateTextPairModalProps { isOpen: boolean; onClose: () => void; textPair: TSharedPair; onUpdate: (id: number, tp: ActionInputUpdatePairById) => void; } export default function UpdateTextPairModal({ isOpen, onClose, onUpdate, textPair, }: UpdateTextPairModalProps) { const t = useTranslations("folder_id"); const input1Ref = useRef(null); const input2Ref = useRef(null); const [language1, setLanguage1] = useState(textPair.language1); const [language2, setLanguage2] = useState(textPair.language2); if (!isOpen) return null; const handleUpdate = () => { if ( !input1Ref.current?.value || !input2Ref.current?.value || !language1 || !language2 ) return; const text1 = input1Ref.current.value; const text2 = input2Ref.current.value; if ( typeof text1 === "string" && typeof text2 === "string" && typeof language1 === "string" && typeof language2 === "string" && text1.trim() !== "" && text2.trim() !== "" && language1.trim() !== "" && language2.trim() !== "" ) { onUpdate(textPair.id, { text1, text2, language1, language2 }); } }; return (
{ if (e.key === "Enter") { e.preventDefault(); handleUpdate(); } }} >

{t("updateTextPair")}

{t("text1")}
{t("text2")}
{t("language1")}
{t("language2")}
{t("update")}
); }