feature/IO-3291-Tasks-Notifications: Checkpoint
This commit is contained in:
@@ -12,59 +12,83 @@ const TaskCenterComponent = forwardRef(({ visible, tasks, loading, onTaskClick,
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const virtuosoRef = useRef(null);
|
const virtuosoRef = useRef(null);
|
||||||
|
|
||||||
const sections = useMemo(() => {
|
const groupedItems = useMemo(() => {
|
||||||
const now = day();
|
const now = day();
|
||||||
const today = now.startOf("day");
|
const today = now.startOf("day");
|
||||||
|
|
||||||
const overdue = tasks.filter((task) => task.due_date && day(task.due_date).isBefore(today));
|
const overdue = tasks.filter((t) => t.due_date && day(t.due_date).isBefore(today));
|
||||||
const dueToday = tasks.filter((task) => task.due_date && day(task.due_date).isSame(today, "day"));
|
const dueToday = tasks.filter((t) => t.due_date && day(t.due_date).isSame(today, "day"));
|
||||||
const upcoming = tasks.filter((task) => task.due_date && day(task.due_date).isAfter(today));
|
const upcoming = tasks.filter((t) => t.due_date && day(t.due_date).isAfter(today));
|
||||||
const noDueDate = tasks.filter((task) => !task.due_date);
|
const noDueDate = tasks.filter((t) => !t.due_date);
|
||||||
|
|
||||||
|
const makeGroup = (label, data) =>
|
||||||
|
data.length ? [{ type: "header", label }, ...data.map((task) => ({ type: "task", task }))] : [];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{ title: t("tasks.labels.overdue"), data: overdue },
|
...makeGroup(t("tasks.labels.overdue"), overdue),
|
||||||
{ title: t("tasks.labels.due_today"), data: dueToday },
|
...makeGroup(t("tasks.labels.due_today"), dueToday),
|
||||||
{ title: t("tasks.labels.upcoming"), data: upcoming },
|
...makeGroup(t("tasks.labels.upcoming"), upcoming),
|
||||||
{ title: t("tasks.labels.no_due_date"), data: noDueDate }
|
...makeGroup(t("tasks.labels.no_due_date"), noDueDate)
|
||||||
].filter((section) => section.data.length > 0);
|
];
|
||||||
}, [tasks, t]);
|
}, [tasks, t]);
|
||||||
|
|
||||||
const renderTask = (index, task) => {
|
const renderTask = (index, task) => {
|
||||||
const handleClick = () => {
|
const handleClick = () => onTaskClick(task.id);
|
||||||
onTaskClick(task.id);
|
|
||||||
|
const getPriorityColor = (priority) => {
|
||||||
|
switch (priority) {
|
||||||
|
case 1:
|
||||||
|
return "red";
|
||||||
|
case 2:
|
||||||
|
return "orange";
|
||||||
|
case 3:
|
||||||
|
return "green";
|
||||||
|
default:
|
||||||
|
return null;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const priorityColor = getPriorityColor(task.priority);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={`${task.id}-${index}`} className="task-item task-incomplete" onClick={handleClick}>
|
<div key={`${task.id}-${index}`} className="task-item task-incomplete" onClick={handleClick}>
|
||||||
<Badge dot>
|
<Badge dot color={priorityColor || undefined} style={priorityColor ? {} : { display: "none" }}>
|
||||||
<div className="task-content">
|
<div className="task-content">
|
||||||
<Title level={5} className="task-title">
|
|
||||||
<span className="ro-number">
|
|
||||||
{t("notifications.labels.ro-number", {
|
|
||||||
ro_number: task.job?.ro_number || t("general.labels.na")
|
|
||||||
})}
|
|
||||||
</span>
|
|
||||||
<Text type="secondary" className="relative-time" title={DateTimeFormat(task.created_at)}>
|
|
||||||
{day(task.created_at).fromNow()}
|
|
||||||
</Text>
|
|
||||||
</Title>
|
|
||||||
<Text strong className="task-body">
|
<Text strong className="task-body">
|
||||||
{task.title}
|
{task.title}
|
||||||
</Text>
|
</Text>
|
||||||
|
|
||||||
|
<div className="task-meta">
|
||||||
|
<div className="ro-number">
|
||||||
|
{t("notifications.labels.ro-number", {
|
||||||
|
ro_number: task.job?.ro_number || t("general.labels.na")
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{task.due_date && (
|
||||||
|
<Text type="secondary" className="relative-time" title={DateTimeFormat(task.due_date)}>
|
||||||
|
{day(task.due_date).fromNow()}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Badge>
|
</Badge>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderSection = (section, sectionIndex) => (
|
const renderItem = (index, item) => {
|
||||||
<div key={`section-${sectionIndex}`} className="task-section">
|
if (item.type === "header") {
|
||||||
<Title level={4} className="section-title">
|
return (
|
||||||
{section.title}
|
<div key={`header-${index}`} className="task-section">
|
||||||
</Title>
|
<Title level={4} className="section-title">
|
||||||
{section.data.map((task, index) => renderTask(`${sectionIndex}-${index}`, task))}
|
{item.label}
|
||||||
</div>
|
</Title>
|
||||||
);
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return renderTask(index, item.task);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={`task-center ${visible ? "visible" : ""}`} ref={ref}>
|
<div className={`task-center ${visible ? "visible" : ""}`} ref={ref}>
|
||||||
@@ -72,13 +96,14 @@ const TaskCenterComponent = forwardRef(({ visible, tasks, loading, onTaskClick,
|
|||||||
<h3>{t("tasks.labels.my_tasks_center")}</h3>
|
<h3>{t("tasks.labels.my_tasks_center")}</h3>
|
||||||
{loading && <Spin spinning={loading} size="small" />}
|
{loading && <Spin spinning={loading} size="small" />}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
ref={virtuosoRef}
|
ref={virtuosoRef}
|
||||||
style={{ height: "400px", width: "100%" }}
|
style={{ height: "400px", width: "100%" }}
|
||||||
data={sections}
|
data={groupedItems}
|
||||||
totalCount={sections.length}
|
itemContent={renderItem}
|
||||||
itemContent={(index, section) => renderSection(section, index)}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{tasks.length < totalTasks && (
|
{tasks.length < totalTasks && (
|
||||||
<button onClick={onLoadMore} disabled={loading}>
|
<button onClick={onLoadMore} disabled={loading}>
|
||||||
{t("general.labels.load_more")}
|
{t("general.labels.load_more")}
|
||||||
@@ -89,5 +114,4 @@ const TaskCenterComponent = forwardRef(({ visible, tasks, loading, onTaskClick,
|
|||||||
});
|
});
|
||||||
|
|
||||||
TaskCenterComponent.displayName = "TaskCenterComponent";
|
TaskCenterComponent.displayName = "TaskCenterComponent";
|
||||||
|
|
||||||
export default TaskCenterComponent;
|
export default TaskCenterComponent;
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import { selectBodyshop, selectCurrentUser } from "../../redux/user/user.selecto
|
|||||||
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
import { useSocket } from "../../contexts/SocketIO/useSocket";
|
||||||
import { useIsEmployee } from "../../utils/useIsEmployee";
|
import { useIsEmployee } from "../../utils/useIsEmployee";
|
||||||
import TaskCenterComponent from "./task-center.component";
|
import TaskCenterComponent from "./task-center.component";
|
||||||
import dayjs from "../../utils/day";
|
|
||||||
import { setModalContext } from "../../redux/modals/modals.actions";
|
import { setModalContext } from "../../redux/modals/modals.actions";
|
||||||
import { QUERY_MY_ACTIVE_TASKS_PAGINATED } from "../../graphql/tasks.queries";
|
import { QUERY_MY_ACTIVE_TASKS_PAGINATED } from "../../graphql/tasks.queries";
|
||||||
|
|
||||||
const POLL_INTERVAL = 60; // seconds
|
const POLL_INTERVAL = 60 * 1000; // milliseconds
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
bodyshop: selectBodyshop,
|
bodyshop: selectBodyshop,
|
||||||
@@ -31,11 +30,7 @@ const TaskCenterContainer = ({ visible, onClose, bodyshop, currentUser, setTaskU
|
|||||||
return employee?.id || null;
|
return employee?.id || null;
|
||||||
}, [bodyshop, currentUser]);
|
}, [bodyshop, currentUser]);
|
||||||
|
|
||||||
const {
|
const { data, loading, fetchMore } = useQuery(QUERY_MY_ACTIVE_TASKS_PAGINATED, {
|
||||||
data,
|
|
||||||
loading: queryLoading,
|
|
||||||
fetchMore
|
|
||||||
} = useQuery(QUERY_MY_ACTIVE_TASKS_PAGINATED, {
|
|
||||||
variables: {
|
variables: {
|
||||||
bodyshop: bodyshop?.id,
|
bodyshop: bodyshop?.id,
|
||||||
assigned_to: assignedToId,
|
assigned_to: assignedToId,
|
||||||
@@ -45,7 +40,7 @@ const TaskCenterContainer = ({ visible, onClose, bodyshop, currentUser, setTaskU
|
|||||||
},
|
},
|
||||||
skip: !bodyshop?.id || !assignedToId || !isEmployee || !currentUser?.email,
|
skip: !bodyshop?.id || !assignedToId || !isEmployee || !currentUser?.email,
|
||||||
fetchPolicy: "cache-and-network",
|
fetchPolicy: "cache-and-network",
|
||||||
pollInterval: isConnected ? 0 : dayjs.duration(POLL_INTERVAL, "seconds").asMilliseconds(),
|
pollInterval: isConnected ? 0 : POLL_INTERVAL,
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.error("Query error:", error);
|
console.error("Query error:", error);
|
||||||
}
|
}
|
||||||
@@ -91,11 +86,12 @@ const TaskCenterContainer = ({ visible, onClose, bodyshop, currentUser, setTaskU
|
|||||||
visible={visible}
|
visible={visible}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
tasks={tasks}
|
tasks={tasks}
|
||||||
loading={queryLoading}
|
loading={loading}
|
||||||
onTaskClick={handleTaskClick}
|
onTaskClick={handleTaskClick}
|
||||||
onLoadMore={handleLoadMore}
|
onLoadMore={handleLoadMore}
|
||||||
totalTasks={data?.tasks_aggregate?.aggregate?.count}
|
totalTasks={data?.tasks_aggregate?.aggregate?.count || 0}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(mapStateToProps, mapDispatchToProps)(TaskCenterContainer);
|
export default connect(mapStateToProps, mapDispatchToProps)(TaskCenterContainer);
|
||||||
|
|||||||
@@ -44,13 +44,31 @@
|
|||||||
color: rgba(0, 0, 0, 0.85);
|
color: rgba(0, 0, 0, 0.85);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
border-bottom: 1px solid #e8e8e8;
|
border-bottom: 1px solid #e8e8e8;
|
||||||
|
position: sticky;
|
||||||
|
top: 0;
|
||||||
|
z-index: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.task-meta {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-top: 4px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: rgba(0, 0, 0, 0.45);
|
||||||
|
|
||||||
|
.ro-number {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.relative-time {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.task-item {
|
.task-item {
|
||||||
padding: 12px 16px;
|
padding: 12px 16px;
|
||||||
border-bottom: 1px solid #f0f0f0;
|
border-bottom: 1px solid #f0f0f0;
|
||||||
display: block;
|
display: block;
|
||||||
overflow: visible;
|
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
@@ -70,17 +88,16 @@
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
|
||||||
|
|
||||||
.ro-number {
|
.ro-number {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
color: #1677ff;
|
color: #1677ff;
|
||||||
|
font-weight: 500;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.relative-time {
|
.relative-time {
|
||||||
margin: 0;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
color: rgba(0, 0, 0, 0.45);
|
color: rgba(0, 0, 0, 0.45);
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@@ -93,10 +110,32 @@
|
|||||||
margin-top: 4px;
|
margin-top: 4px;
|
||||||
color: rgba(0, 0, 0, 0.85);
|
color: rgba(0, 0, 0, 0.85);
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.ant-badge {
|
.ant-badge {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
margin: 16px auto;
|
||||||
|
display: block;
|
||||||
|
padding: 8px 16px;
|
||||||
|
background-color: #1677ff;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 14px;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: #4096ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:disabled {
|
||||||
|
background-color: #d9d9d9;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user