import { type FC, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import Button from "../../../../../components/Button"; import Input from "../../../../../components/Input"; import Select from "../../../../../components/Select"; type InitialValues = { title: string; fileUrl?: string; type: "file" | "link"; }; type Props = { onClose: () => void; onSubmit: (data: { file?: File; title: string; linkId: string }) => void; isSubmitting?: boolean; initialValues?: InitialValues; submitLabel?: string; }; const TaskDetailAttachmentForm: FC = ({ onClose, onSubmit, isSubmitting = false, initialValues, submitLabel, }) => { const { t } = useTranslation("global"); const fileInputRef = useRef(null); const [file, setFile] = useState(null); const [title, setTitle] = useState(initialValues?.title ?? ""); const [linkId, setLinkId] = useState(initialValues?.type === "link" ? (initialValues.fileUrl ?? "") : ""); const isEdit = Boolean(initialValues); const linkItems = [{ value: "", label: t("taskmanager.task_detail.none") }]; const canSubmit = isEdit ? Boolean(title.trim()) || Boolean(file) : Boolean(file) || Boolean(title.trim()); const handleFileChange = (e: React.ChangeEvent) => { const selected = e.target.files?.[0]; if (selected) setFile(selected); }; const handleSubmit = () => { if (!canSubmit) return; onSubmit({ file: file ?? undefined, title: title.trim(), linkId, }); }; const currentFileLabel = file ? file.name : initialValues?.fileUrl ? initialValues.fileUrl : t("no_select_file"); return (

{t("taskmanager.task_detail.attachment")}

{currentFileLabel}
{t("taskmanager.task_detail.or")}
setTitle(e.target.value)} className="h-8 bg-white/63 border-white" labelClassName="text-xs" />