Compare commits
3 Commits
cabf248c0e
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b96ecf9d9 | |||
| 4bb164be0f | |||
| 2f71b4c96c |
@@ -54,7 +54,7 @@ const Column: FC<Props> = ({
|
|||||||
const items = tasksData?.pages.flatMap((page) => page.data?.items ?? []) ?? [];
|
const items = tasksData?.pages.flatMap((page) => page.data?.items ?? []) ?? [];
|
||||||
|
|
||||||
return [...items]
|
return [...items]
|
||||||
.sort((a, b) => (a.order ?? a.priority ?? 0) - (b.order ?? b.priority ?? 0))
|
.sort((a, b) => (a.priority ?? a.order ?? 0) - (b.priority ?? b.order ?? 0))
|
||||||
.map((task, index) => mapTaskItemToTask(task as TaskItemType, column.id, index));
|
.map((task, index) => mapTaskItemToTask(task as TaskItemType, column.id, index));
|
||||||
}, [tasksData?.pages, column.id]);
|
}, [tasksData?.pages, column.id]);
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,83 @@
|
|||||||
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
|
import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react";
|
||||||
import { More } from "iconsax-react";
|
import { More } from "iconsax-react";
|
||||||
import { type FC } from "react";
|
import { type FC, useEffect, useState } from "react";
|
||||||
|
import { useTranslation } from "react-i18next";
|
||||||
import TaskDetailLabelCheckbox from "../labels/TaskDetailLabelCheckbox";
|
import TaskDetailLabelCheckbox from "../labels/TaskDetailLabelCheckbox";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
title: string;
|
title: string;
|
||||||
checked: boolean;
|
checked: boolean;
|
||||||
onToggle: () => void;
|
onToggle: () => void;
|
||||||
onEdit: () => void;
|
onSave: (title: string) => void;
|
||||||
onDelete: () => void;
|
onDelete: () => void;
|
||||||
|
isSaving?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const ChecklistItem: FC<Props> = ({ title, checked, onToggle, onEdit, onDelete }) => {
|
const ChecklistItem: FC<Props> = ({ title, checked, onToggle, onSave, onDelete, isSaving = false }) => {
|
||||||
|
const { t } = useTranslation("global");
|
||||||
|
const [isEditing, setIsEditing] = useState(false);
|
||||||
|
const [editTitle, setEditTitle] = useState(title);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isEditing) {
|
||||||
|
setEditTitle(title);
|
||||||
|
}
|
||||||
|
}, [title, isEditing]);
|
||||||
|
|
||||||
|
const handleSave = () => {
|
||||||
|
const trimmed = editTitle.trim();
|
||||||
|
if (!trimmed || trimmed === title) {
|
||||||
|
setIsEditing(false);
|
||||||
|
setEditTitle(title);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onSave(trimmed);
|
||||||
|
setIsEditing(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCancel = () => {
|
||||||
|
setIsEditing(false);
|
||||||
|
setEditTitle(title);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isEditing) {
|
||||||
|
return (
|
||||||
|
<div className="flex gap-1 items-center">
|
||||||
|
<TaskDetailLabelCheckbox checked={checked} onToggle={onToggle} />
|
||||||
|
|
||||||
|
<div className="flex-1 flex gap-2 items-center">
|
||||||
|
<input
|
||||||
|
value={editTitle}
|
||||||
|
onChange={(e) => setEditTitle(e.target.value)}
|
||||||
|
onKeyDown={(e) => {
|
||||||
|
if (e.key === "Enter") handleSave();
|
||||||
|
if (e.key === "Escape") handleCancel();
|
||||||
|
}}
|
||||||
|
autoFocus
|
||||||
|
disabled={isSaving}
|
||||||
|
className="flex-1 h-[27px] px-2 text-xs bg-white/50 rounded outline-none"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleSave}
|
||||||
|
disabled={!editTitle.trim() || isSaving}
|
||||||
|
className="h-7 px-3 rounded-lg bg-[#292D32] text-white text-[11px] disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{t("save")}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={handleCancel}
|
||||||
|
disabled={isSaving}
|
||||||
|
className="h-7 px-3 rounded-lg bg-white/50 text-[#292D32] text-[11px] border border-white disabled:opacity-50"
|
||||||
|
>
|
||||||
|
{t("cancel")}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-1 h-[27px] items-center">
|
<div className="flex gap-1 h-[27px] items-center">
|
||||||
<TaskDetailLabelCheckbox checked={checked} onToggle={onToggle} />
|
<TaskDetailLabelCheckbox checked={checked} onToggle={onToggle} />
|
||||||
@@ -24,14 +90,32 @@ const ChecklistItem: FC<Props> = ({ title, checked, onToggle, onEdit, onDelete }
|
|||||||
<More size={20} color="#000" />
|
<More size={20} color="#000" />
|
||||||
</PopoverButton>
|
</PopoverButton>
|
||||||
|
|
||||||
<PopoverPanel anchor="bottom end" className="z-[80] mt-1 rounded-[10px] bg-white shadow-md text-right p-3">
|
<PopoverPanel anchor="bottom end" className="z-[80] mt-1 rounded-[10px] bg-white shadow-md text-right p-3">
|
||||||
<button type="button" onClick={onEdit} className="w-full text-sm text-right">
|
{({ close }) => (
|
||||||
ویرایش
|
<>
|
||||||
</button>
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => {
|
||||||
|
close();
|
||||||
|
setIsEditing(true);
|
||||||
|
}}
|
||||||
|
className="w-full text-sm text-right"
|
||||||
|
>
|
||||||
|
ویرایش
|
||||||
|
</button>
|
||||||
|
|
||||||
<button type="button" onClick={onDelete} className="w-full mt-3 text-sm text-right text-[#FF0000]">
|
<button
|
||||||
پاک کردن
|
type="button"
|
||||||
</button>
|
onClick={() => {
|
||||||
|
close();
|
||||||
|
onDelete();
|
||||||
|
}}
|
||||||
|
className="w-full mt-3 text-sm text-right text-[#FF0000]"
|
||||||
|
>
|
||||||
|
پاک کردن
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</PopoverPanel>
|
</PopoverPanel>
|
||||||
</Popover>
|
</Popover>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { Edit } from "iconsax-react";
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import ModalConfrim from "../../../../../components/ModalConfrim";
|
import ModalConfrim from "../../../../../components/ModalConfrim";
|
||||||
import { toast } from '../../../../../components/Toast';
|
import { toast } from "../../../../../components/Toast";
|
||||||
import ProgressBar from "../../../../../components/ProgressBar";
|
import ProgressBar from "../../../../../components/ProgressBar";
|
||||||
import { ErrorType } from "../../../../../helpers/types";
|
import { ErrorType } from "../../../../../helpers/types";
|
||||||
import { useDeleteCheckListItem, useUpdateCheckListItem } from "../../../task/hooks/useTaskData";
|
import { useDeleteCheckListItem, useUpdateCheckListItem } from "../../../task/hooks/useTaskData";
|
||||||
@@ -37,12 +37,23 @@ const CheckLists = ({
|
|||||||
const doneCount = completedCheckListItemCount ?? items.filter((item) => item.checked).length;
|
const doneCount = completedCheckListItemCount ?? items.filter((item) => item.checked).length;
|
||||||
const progress = totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0;
|
const progress = totalCount > 0 ? Math.round((doneCount / totalCount) * 100) : 0;
|
||||||
|
|
||||||
const handleToggle = (id: string, checked: boolean) => {
|
const handleToggle = (id: string, title: string, checked: boolean) => {
|
||||||
updateCheckListItem.mutate(
|
updateCheckListItem.mutate(
|
||||||
{ id, params: { isDone: !checked }, taskId },
|
{ id, params: { title, isDone: !checked, taskId }, taskId },
|
||||||
{
|
{
|
||||||
onError: (error: ErrorType) => {
|
onError: (error: ErrorType) => {
|
||||||
toast(error.response?.data?.error.message[0], 'error');
|
toast(error.response?.data?.error.message[0], "error");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSave = (id: string, title: string, checked: boolean) => {
|
||||||
|
updateCheckListItem.mutate(
|
||||||
|
{ id, params: { title, isDone: checked, taskId }, taskId },
|
||||||
|
{
|
||||||
|
onError: (error: ErrorType) => {
|
||||||
|
toast(error.response?.data?.error.message[0], "error");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -58,7 +69,7 @@ const CheckLists = ({
|
|||||||
setDeleteItemId(null);
|
setDeleteItemId(null);
|
||||||
},
|
},
|
||||||
onError: (error: ErrorType) => {
|
onError: (error: ErrorType) => {
|
||||||
toast(error.response?.data?.error.message[0], 'error');
|
toast(error.response?.data?.error.message[0], "error");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -84,9 +95,10 @@ const CheckLists = ({
|
|||||||
key={item.id}
|
key={item.id}
|
||||||
title={item.title}
|
title={item.title}
|
||||||
checked={item.checked}
|
checked={item.checked}
|
||||||
onToggle={() => handleToggle(item.id, item.checked)}
|
onToggle={() => handleToggle(item.id, item.title, item.checked)}
|
||||||
onEdit={() => {}}
|
onSave={(title) => handleSave(item.id, title, item.checked)}
|
||||||
onDelete={() => setDeleteItemId(item.id)}
|
onDelete={() => setDeleteItemId(item.id)}
|
||||||
|
isSaving={updateCheckListItem.isPending}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -159,7 +159,13 @@ export const useUpdateCheckListItem = () => {
|
|||||||
if (!current?.data?.checkListItems) return current;
|
if (!current?.data?.checkListItems) return current;
|
||||||
|
|
||||||
const checkListItems = current.data.checkListItems.map((item) =>
|
const checkListItems = current.data.checkListItems.map((item) =>
|
||||||
item.id === id ? { ...item, isDone: params.isDone } : item,
|
item.id === id
|
||||||
|
? {
|
||||||
|
...item,
|
||||||
|
...(params.isDone !== undefined ? { isDone: params.isDone } : {}),
|
||||||
|
...(params.title !== undefined ? { title: params.title } : {}),
|
||||||
|
}
|
||||||
|
: item,
|
||||||
);
|
);
|
||||||
const completedCheckListItemCount = checkListItems.filter((item) => item.isDone).length;
|
const completedCheckListItemCount = checkListItems.filter((item) => item.isDone).length;
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,9 @@ export interface CreateCheckListItemResponse extends IResponse<{ checkListItem:
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type UpdateCheckListItemType = {
|
export type UpdateCheckListItemType = {
|
||||||
isDone: boolean;
|
title?: string;
|
||||||
|
isDone?: boolean;
|
||||||
|
taskId?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface UpdateCheckListItemResponse extends IResponse<{ checkListItem: TaskChecklistItemType }> {
|
export interface UpdateCheckListItemResponse extends IResponse<{ checkListItem: TaskChecklistItemType }> {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import type { TaskItemType } from "../types/TaskTypes";
|
|||||||
export const mapTaskItemToTask = (task: TaskItemType, taskPhaseId: string, fallbackOrder: number): Task => ({
|
export const mapTaskItemToTask = (task: TaskItemType, taskPhaseId: string, fallbackOrder: number): Task => ({
|
||||||
id: task.id,
|
id: task.id,
|
||||||
columnId: task.taskPhaseId ?? taskPhaseId,
|
columnId: task.taskPhaseId ?? taskPhaseId,
|
||||||
order: task.order ?? task.priority ?? fallbackOrder,
|
order: task.priority ?? task.order ?? fallbackOrder,
|
||||||
title: task.title,
|
title: task.title,
|
||||||
tag: task.tag ?? "",
|
tag: task.tag ?? "",
|
||||||
dateRange: task.dateRange ?? "",
|
dateRange: task.dateRange ?? "",
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { TaskItemType } from "../task/types/TaskTypes";
|
import type { TaskItemType } from "../task/types/TaskTypes";
|
||||||
|
import { getTaskSortOrder } from "./getTaskSortOrder";
|
||||||
const getTaskSortOrder = (task: TaskItemType) => task.order ?? task.priority ?? 0;
|
|
||||||
|
|
||||||
export const getPriorityDestinationTaskId = (
|
export const getPriorityDestinationTaskId = (
|
||||||
items: TaskItemType[],
|
items: TaskItemType[],
|
||||||
@@ -9,16 +8,19 @@ export const getPriorityDestinationTaskId = (
|
|||||||
removeSource = true,
|
removeSource = true,
|
||||||
): string | null => {
|
): string | null => {
|
||||||
const sorted = [...items].sort((a, b) => getTaskSortOrder(a) - getTaskSortOrder(b));
|
const sorted = [...items].sort((a, b) => getTaskSortOrder(a) - getTaskSortOrder(b));
|
||||||
const sourceIndex = sorted.findIndex((item) => item.id === sourceId);
|
|
||||||
|
|
||||||
if (removeSource && sourceIndex === destIndex) return null;
|
if (!removeSource) {
|
||||||
|
if (sorted.length === 0) return null;
|
||||||
const list = removeSource ? sorted.filter((item) => item.id !== sourceId) : sorted;
|
if (destIndex >= sorted.length) return sorted[sorted.length - 1].id;
|
||||||
if (list.length === 0) return null;
|
return sorted[destIndex].id;
|
||||||
|
|
||||||
if (destIndex >= list.length) {
|
|
||||||
return list[list.length - 1].id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return list[destIndex].id;
|
const sourceIndex = sorted.findIndex((item) => item.id === sourceId);
|
||||||
|
if (sourceIndex === -1 || sourceIndex === destIndex) return null;
|
||||||
|
|
||||||
|
// Dest is the task currently at the drop index (مقصد), not after removing source.
|
||||||
|
const destTask = sorted[destIndex];
|
||||||
|
if (!destTask || destTask.id === sourceId) return null;
|
||||||
|
|
||||||
|
return destTask.id;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import type { TaskItemType } from "../task/types/TaskTypes";
|
||||||
|
|
||||||
|
export const getTaskSortOrder = (task: Pick<TaskItemType, "priority" | "order">) =>
|
||||||
|
task.priority ?? task.order ?? 0;
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import type { TaskItemType } from "../task/types/TaskTypes";
|
import type { TaskItemType } from "../task/types/TaskTypes";
|
||||||
|
import { getTaskSortOrder } from "./getTaskSortOrder";
|
||||||
const getTaskSortOrder = (task: TaskItemType) => task.order ?? task.priority ?? 0;
|
|
||||||
|
|
||||||
export const reorderTaskItems = (
|
export const reorderTaskItems = (
|
||||||
tasks: TaskItemType[],
|
tasks: TaskItemType[],
|
||||||
|
|||||||
@@ -1,75 +1,73 @@
|
|||||||
import { FC, useState } from 'react'
|
import { FC, useState } from "react";
|
||||||
import { useGetUsers } from '../../users/hooks/useUserData'
|
import { useTranslation } from "react-i18next";
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useParams } from "react-router-dom";
|
||||||
import { UserItemType } from '../../users/types/UserTypes'
|
import Button from "../../../components/Button";
|
||||||
import CheckBoxComponent from '../../../components/CheckBoxComponent'
|
import CheckBoxComponent from "../../../components/CheckBoxComponent";
|
||||||
import { useParams } from 'react-router-dom'
|
import { toast } from "../../../components/Toast";
|
||||||
import { useReferTicket } from '../hooks/useTicketData'
|
import { ErrorType } from "../../../helpers/types";
|
||||||
import Button from '../../../components/Button'
|
import { useGetAdminsListAll } from "../../users/hooks/useUserData";
|
||||||
import { toast } from '../../../components/Toast';
|
import { UserItemType } from "../../users/types/UserTypes";
|
||||||
import { ErrorType } from '../../../helpers/types'
|
import { useReferTicket } from "../hooks/useTicketData";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
refetch: () => void
|
refetch: () => void;
|
||||||
}
|
};
|
||||||
|
|
||||||
const ReferTicket: FC<Props> = ({ refetch }) => {
|
const ReferTicket: FC<Props> = ({ refetch }) => {
|
||||||
|
const { t } = useTranslation("global");
|
||||||
|
const { id } = useParams();
|
||||||
|
const [userId, setUserId] = useState<string>("");
|
||||||
|
const getUsers = useGetAdminsListAll();
|
||||||
|
const referTicket = useReferTicket();
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
const handleReferTicket = () => {
|
||||||
const { id } = useParams()
|
referTicket.mutate(
|
||||||
const [userId, setUserId] = useState<string>('')
|
{ id: id as string, userId },
|
||||||
const getUsers = useGetUsers('', 'tickets')
|
{
|
||||||
const referTicket = useReferTicket()
|
onSuccess: () => {
|
||||||
|
refetch();
|
||||||
|
toast(t("ticket.refer_ticket_success"), "success");
|
||||||
|
},
|
||||||
|
onError: (error: ErrorType) => {
|
||||||
|
toast(error.response?.data?.error.message[0], "error");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const handleReferTicket = () => {
|
return (
|
||||||
referTicket.mutate({ id: id as string, userId }, {
|
<div className={"bg-white p-6 rounded-3xl mt-8"}>
|
||||||
onSuccess: () => {
|
<div className="flex justify-between">
|
||||||
refetch()
|
<div className="text-sm">{t("ticket.refer_ticket")}</div>
|
||||||
toast(t('ticket.refer_ticket_success'), 'success')
|
</div>
|
||||||
},
|
|
||||||
onError: (error: ErrorType) => {
|
|
||||||
toast(error.response?.data?.error.message[0], 'error')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
<div className="mt-4">
|
||||||
<div className={'bg-white p-6 rounded-3xl mt-8'}>
|
{getUsers.data?.data?.map((item: UserItemType) => (
|
||||||
<div className='flex justify-between'>
|
<div
|
||||||
<div className='text-sm'>
|
key={item.id}
|
||||||
{t('ticket.refer_ticket')}
|
className="flex gap-2 items-center"
|
||||||
</div>
|
>
|
||||||
</div>
|
<div>
|
||||||
|
<CheckBoxComponent
|
||||||
<div className="mt-4">
|
checked={userId === item.id}
|
||||||
{
|
onChange={(e) => setUserId(e.target.checked ? item.id : "")}
|
||||||
getUsers.data?.data?.users?.map((item: UserItemType) => (
|
/>
|
||||||
<div key={item.id} className='flex gap-2 items-center'>
|
|
||||||
<div>
|
|
||||||
<CheckBoxComponent
|
|
||||||
checked={userId === item.id}
|
|
||||||
onChange={(e) => setUserId(e.target.checked ? item.id : '')}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className='text-xs leading-5'>
|
|
||||||
{item.firstName + ' ' + item.lastName}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
<div className='flex justify-end mt-4'>
|
|
||||||
<Button
|
|
||||||
label={t('ticket.refer_ticket')}
|
|
||||||
onClick={handleReferTicket}
|
|
||||||
isLoading={referTicket.isPending}
|
|
||||||
className='w-fit px-7'
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<div className="text-xs leading-5">{item.firstName + " " + item.lastName}</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<div className="flex justify-end mt-4">
|
||||||
|
<Button
|
||||||
|
label={t("ticket.refer_ticket")}
|
||||||
|
onClick={handleReferTicket}
|
||||||
|
isLoading={referTicket.isPending}
|
||||||
|
className="w-fit px-7"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
</div>
|
||||||
}
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default ReferTicket
|
export default ReferTicket;
|
||||||
|
|||||||
Reference in New Issue
Block a user