check list
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
import { Edit } from "iconsax-react";
|
||||
import ProgressBar from "../../../../../components/ProgressBar";
|
||||
import TrashWithConfrim from "../../../../../components/TrashWithConfrim";
|
||||
import type { TaskChecklistType } from "../../../task/types/TaskTypes";
|
||||
import type { TaskChecklistItemType } from "../../../task/types/TaskTypes";
|
||||
import ChecklistItem from "./ChecklistItem";
|
||||
|
||||
type Props = {
|
||||
checklists?: TaskChecklistType[];
|
||||
checkListItems?: TaskChecklistItemType[];
|
||||
checkListItemCount?: number;
|
||||
completedCheckListItemCount?: number;
|
||||
};
|
||||
|
||||
const CheckLists = ({ checklists = [] }: Props) => {
|
||||
const items = checklists.flatMap((checklist) =>
|
||||
checklist.items.map((item) => ({
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
checked: item.isDone,
|
||||
})),
|
||||
);
|
||||
const CheckLists = ({
|
||||
checkListItems = [],
|
||||
checkListItemCount,
|
||||
completedCheckListItemCount,
|
||||
}: Props) => {
|
||||
const items = checkListItems.map((item) => ({
|
||||
id: item.id,
|
||||
title: item.title,
|
||||
checked: item.isDone,
|
||||
}));
|
||||
|
||||
const doneCount = items.filter((item) => item.checked).length;
|
||||
const progress = items.length > 0 ? Math.round((doneCount / items.length) * 100) : 0;
|
||||
const totalCount = checkListItemCount ?? items.length;
|
||||
const doneCount = completedCheckListItemCount ?? items.filter((item) => item.checked).length;
|
||||
const progress = totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0;
|
||||
|
||||
if (checklists.length === 0) return null;
|
||||
if (checkListItems.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="mt-6">
|
||||
|
||||
+10
-19
@@ -3,26 +3,21 @@ import { type FC, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Button from "../../../../../components/Button";
|
||||
import Input from "../../../../../components/Input";
|
||||
import Select from "../../../../../components/Select";
|
||||
import type { TaskChecklist } from "./types";
|
||||
|
||||
type Props = {
|
||||
checklists: TaskChecklist[];
|
||||
onClose: () => void;
|
||||
onSubmit: (title: string, copyFromId: string) => void;
|
||||
onSubmit: (title: string) => void;
|
||||
isSubmitting?: boolean;
|
||||
};
|
||||
|
||||
const TaskDetailChecklistForm: FC<Props> = ({ checklists, onClose, onSubmit }) => {
|
||||
const TaskDetailChecklistForm: FC<Props> = ({ onClose, onSubmit, isSubmitting = false }) => {
|
||||
const { t } = useTranslation("global");
|
||||
const [title, setTitle] = useState("");
|
||||
const [copyFromId, setCopyFromId] = useState("");
|
||||
|
||||
const copyFromItems = [{ value: "", label: t("taskmanager.task_detail.none") }, ...checklists.map((checklist) => ({ value: checklist.id, label: checklist.title }))];
|
||||
|
||||
const handleSubmit = () => {
|
||||
const trimmed = title.trim();
|
||||
if (!trimmed) return;
|
||||
onSubmit(trimmed, copyFromId);
|
||||
onSubmit(trimmed);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -36,20 +31,16 @@ const TaskDetailChecklistForm: FC<Props> = ({ checklists, onClose, onSubmit }) =
|
||||
|
||||
<Input label={t("taskmanager.task_detail.label_title")} value={title} onChange={(e) => setTitle(e.target.value)} className="h-8 bg-white/63 border-white" labelClassName="text-xs" />
|
||||
|
||||
<Select
|
||||
label={t("taskmanager.task_detail.copy_from")}
|
||||
labelClassName="text-xs"
|
||||
value={copyFromId}
|
||||
onChange={(e) => setCopyFromId(e.target.value)}
|
||||
items={copyFromItems}
|
||||
className="h-8 bg-white/63 border-white text-xs rounded-xl"
|
||||
/>
|
||||
|
||||
<div className="flex justify-end gap-2">
|
||||
<Button type="button" onClick={onClose} className="h-8 bg-[#E8E4F0] text-[#292D32] rounded-xl text-xs w-[95px]">
|
||||
{t("cancel")}
|
||||
</Button>
|
||||
<Button type="button" onClick={handleSubmit} disabled={!title.trim()} className="h-8 bg-[#292D32] text-white rounded-xl text-xs disabled:opacity-50 w-[95px]">
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={!title.trim() || isSubmitting}
|
||||
className="h-8 bg-[#292D32] text-white rounded-xl text-xs disabled:opacity-50 w-[95px]"
|
||||
>
|
||||
{t("save")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
+4
-5
@@ -1,15 +1,14 @@
|
||||
import { type FC } from "react";
|
||||
import TaskDetailChecklistForm from "./TaskDetailChecklistForm";
|
||||
import type { TaskChecklist } from "./types";
|
||||
|
||||
type Props = {
|
||||
checklists: TaskChecklist[];
|
||||
onClose: () => void;
|
||||
onSubmit: (title: string, copyFromId: string) => void;
|
||||
onSubmit: (title: string) => void;
|
||||
isSubmitting?: boolean;
|
||||
};
|
||||
|
||||
const TaskDetailChecklistPopover: FC<Props> = ({ checklists, onClose, onSubmit }) => {
|
||||
return <TaskDetailChecklistForm checklists={checklists} onClose={onClose} onSubmit={onSubmit} />;
|
||||
const TaskDetailChecklistPopover: FC<Props> = ({ onClose, onSubmit, isSubmitting }) => {
|
||||
return <TaskDetailChecklistForm onClose={onClose} onSubmit={onSubmit} isSubmitting={isSubmitting} />;
|
||||
};
|
||||
|
||||
export default TaskDetailChecklistPopover;
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { TaskChecklist } from "./types";
|
||||
|
||||
export const DEFAULT_CHECKLISTS: TaskChecklist[] = [
|
||||
{ id: "1", title: "چک لیست پروژه" },
|
||||
{ id: "2", title: "چک لیست انتشار" },
|
||||
];
|
||||
@@ -1,4 +0,0 @@
|
||||
export type TaskChecklist = {
|
||||
id: string;
|
||||
title: string;
|
||||
};
|
||||
Reference in New Issue
Block a user