2023-08-11 11:48:33 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
// helpers
|
2023-09-07 07:23:49 +00:00
|
|
|
import { renderFullDate } from "helpers/date-time.helper";
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2023-09-07 07:23:49 +00:00
|
|
|
export const dueDateIconDetails = (
|
2023-09-01 11:12:30 +00:00
|
|
|
date: string,
|
|
|
|
stateGroup: string
|
|
|
|
): {
|
|
|
|
iconName: string;
|
|
|
|
className: string;
|
|
|
|
} => {
|
|
|
|
let iconName = "calendar_today";
|
|
|
|
let className = "";
|
|
|
|
|
|
|
|
if (!date || ["completed", "cancelled"].includes(stateGroup)) {
|
|
|
|
iconName = "calendar_today";
|
|
|
|
className = "";
|
|
|
|
} else {
|
2023-08-11 11:48:33 +00:00
|
|
|
const today = new Date();
|
2023-09-07 07:23:49 +00:00
|
|
|
today.setHours(0, 0, 0, 0);
|
|
|
|
const targetDate = new Date(date);
|
|
|
|
targetDate.setHours(0, 0, 0, 0);
|
2023-08-11 11:48:33 +00:00
|
|
|
|
2023-09-07 07:23:49 +00:00
|
|
|
const timeDifference = targetDate.getTime() - today.getTime();
|
|
|
|
|
|
|
|
if (timeDifference < 0) {
|
2023-09-01 11:12:30 +00:00
|
|
|
iconName = "event_busy";
|
2024-02-08 14:35:52 +00:00
|
|
|
className = "text-danger-text-medium";
|
2023-09-07 07:23:49 +00:00
|
|
|
} else if (timeDifference === 0) {
|
2023-09-01 11:12:30 +00:00
|
|
|
iconName = "today";
|
2024-02-08 14:35:52 +00:00
|
|
|
className = "text-danger-text-medium";
|
2023-09-07 07:23:49 +00:00
|
|
|
} else if (timeDifference === 24 * 60 * 60 * 1000) {
|
|
|
|
iconName = "event";
|
2024-02-09 10:42:42 +00:00
|
|
|
className = "text-warning-text-subtle";
|
2023-09-07 07:23:49 +00:00
|
|
|
} else {
|
|
|
|
iconName = "calendar_today";
|
|
|
|
className = "";
|
2023-09-01 11:12:30 +00:00
|
|
|
}
|
2023-08-11 11:48:33 +00:00
|
|
|
}
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
iconName,
|
|
|
|
className,
|
|
|
|
};
|
2023-08-11 11:48:33 +00:00
|
|
|
};
|
|
|
|
|
2023-09-01 11:12:30 +00:00
|
|
|
export const IssueBlockDueDate = ({ due_date, group }: { due_date: string; group: string }) => {
|
2023-09-07 07:23:49 +00:00
|
|
|
const iconDetails = dueDateIconDetails(due_date, group);
|
2023-09-01 11:12:30 +00:00
|
|
|
|
|
|
|
return (
|
2024-02-08 12:53:13 +00:00
|
|
|
<div className="flex items-center gap-1 rounded border-[0.5px] border-neutral-border-medium px-2.5 py-1 text-xs text-neutral-text-strong">
|
2023-12-10 10:18:10 +00:00
|
|
|
<span className={`material-symbols-rounded -my-0.5 text-sm ${iconDetails.className}`}>
|
2023-09-01 11:12:30 +00:00
|
|
|
{iconDetails.iconName}
|
|
|
|
</span>
|
|
|
|
{renderFullDate(due_date)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|