delete and update a attachment in task

This commit is contained in:
hamid zarghami
2026-07-25 09:40:58 +03:30
parent 3537094e7c
commit df2f800b54
7 changed files with 201 additions and 21 deletions
@@ -4,22 +4,39 @@ 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<Props> = ({ onClose, onSubmit, isSubmitting = false }) => {
const TaskDetailAttachmentForm: FC<Props> = ({
onClose,
onSubmit,
isSubmitting = false,
initialValues,
submitLabel,
}) => {
const { t } = useTranslation("global");
const fileInputRef = useRef<HTMLInputElement>(null);
const [file, setFile] = useState<File | null>(null);
const [title, setTitle] = useState("");
const [linkId, setLinkId] = useState("");
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 = Boolean(file) || Boolean(title.trim());
const canSubmit = isEdit
? Boolean(title.trim()) || Boolean(file)
: Boolean(file) || Boolean(title.trim());
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const selected = e.target.files?.[0];
@@ -35,6 +52,12 @@ const TaskDetailAttachmentForm: FC<Props> = ({ onClose, onSubmit, isSubmitting =
});
};
const currentFileLabel = file
? file.name
: initialValues?.fileUrl
? initialValues.fileUrl
: t("no_select_file");
return (
<div className="flex flex-col gap-3">
<h3 className="text-xs font-bold text-center">{t("taskmanager.task_detail.attachment")}</h3>
@@ -43,7 +66,7 @@ const TaskDetailAttachmentForm: FC<Props> = ({ onClose, onSubmit, isSubmitting =
<button type="button" onClick={() => fileInputRef.current?.click()} className="shrink-0 h-6 rounded-lg text-[11px] px-3 bg-secondary">
{t("select_file")}
</button>
<span className="text-[11px] text-description truncate">{file ? file.name : t("no_select_file")}</span>
<span className="text-[11px] text-description truncate">{currentFileLabel}</span>
<input ref={fileInputRef} type="file" className="hidden" onChange={handleFileChange} />
</div>
@@ -69,7 +92,7 @@ const TaskDetailAttachmentForm: FC<Props> = ({ onClose, onSubmit, isSubmitting =
{t("cancel")}
</Button>
<Button type="button" onClick={handleSubmit} disabled={!canSubmit || isSubmitting} isLoading={isSubmitting} className="h-8 bg-[#292D32] text-white rounded-xl text-xs disabled:opacity-50 w-[95px]">
{t("taskmanager.task_detail.insert")}
{submitLabel ?? t("taskmanager.task_detail.insert")}
</Button>
</div>
</div>