2023-04-14 14:10:00 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-02-08 04:43:07 +00:00
|
|
|
// ui
|
2023-02-22 06:12:17 +00:00
|
|
|
import { CustomDatePicker, Tooltip } from "components/ui";
|
2023-02-08 04:43:07 +00:00
|
|
|
// helpers
|
|
|
|
import { findHowManyDaysLeft } from "helpers/date-time.helper";
|
2023-04-06 06:38:52 +00:00
|
|
|
// services
|
|
|
|
import trackEventServices from "services/track-event.service";
|
2023-02-08 04:43:07 +00:00
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IIssue } from "types";
|
2023-02-08 04:43:07 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>, issueId: string) => void;
|
2023-06-06 16:06:00 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
2023-02-08 04:43:07 +00:00
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
2023-06-06 16:06:00 +00:00
|
|
|
export const ViewDueDateSelect: React.FC<Props> = ({
|
|
|
|
issue,
|
|
|
|
partialUpdateIssue,
|
|
|
|
user,
|
|
|
|
isNotAllowed,
|
|
|
|
}) => {
|
2023-04-14 14:10:00 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Tooltip tooltipHeading="Due Date" tooltipContent={issue.target_date ?? "N/A"}>
|
|
|
|
<div
|
2023-05-11 11:31:58 +00:00
|
|
|
className={`group relative max-w-[6.5rem] ${
|
2023-04-14 14:10:00 +00:00
|
|
|
issue.target_date === null
|
|
|
|
? ""
|
|
|
|
: issue.target_date < new Date().toISOString()
|
|
|
|
? "text-red-600"
|
|
|
|
: findHowManyDaysLeft(issue.target_date) <= 3 && "text-orange-400"
|
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<CustomDatePicker
|
2023-04-24 05:58:05 +00:00
|
|
|
placeholder="Due date"
|
2023-04-14 14:10:00 +00:00
|
|
|
value={issue?.target_date}
|
|
|
|
onChange={(val) => {
|
2023-05-10 20:57:14 +00:00
|
|
|
partialUpdateIssue(
|
|
|
|
{
|
|
|
|
target_date: val,
|
|
|
|
priority: issue.priority,
|
|
|
|
state: issue.state,
|
|
|
|
},
|
|
|
|
issue.id
|
|
|
|
);
|
2023-04-14 14:10:00 +00:00
|
|
|
trackEventServices.trackIssuePartialPropertyUpdateEvent(
|
|
|
|
{
|
|
|
|
workspaceSlug,
|
|
|
|
workspaceId: issue.workspace,
|
|
|
|
projectId: issue.project_detail.id,
|
|
|
|
projectIdentifier: issue.project_detail.identifier,
|
|
|
|
projectName: issue.project_detail.name,
|
|
|
|
issueId: issue.id,
|
|
|
|
},
|
2023-06-06 16:06:00 +00:00
|
|
|
"ISSUE_PROPERTY_UPDATE_DUE_DATE",
|
|
|
|
user
|
2023-04-14 14:10:00 +00:00
|
|
|
);
|
|
|
|
}}
|
2023-04-24 05:58:05 +00:00
|
|
|
className={issue?.target_date ? "w-[6.5rem]" : "w-[5rem] text-center"}
|
2023-04-14 14:10:00 +00:00
|
|
|
disabled={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|