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
|
2023-07-04 12:49:19 +00:00
|
|
|
import { findHowManyDaysLeft, renderShortDateWithYearFormat } 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-07-11 09:48:47 +00:00
|
|
|
import useIssuesView from "hooks/use-issues-view";
|
2023-02-08 04:43:07 +00:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
issue: IIssue;
|
2023-06-24 12:39:06 +00:00
|
|
|
partialUpdateIssue: (formData: Partial<IIssue>, issue: IIssue) => void;
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition?: "top" | "bottom";
|
2023-06-23 11:50:05 +00:00
|
|
|
noBorder?: boolean;
|
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,
|
2023-06-28 11:57:43 +00:00
|
|
|
tooltipPosition = "top",
|
2023-06-23 11:50:05 +00:00
|
|
|
noBorder = false,
|
2023-06-06 16:06:00 +00:00
|
|
|
user,
|
|
|
|
isNotAllowed,
|
|
|
|
}) => {
|
2023-04-14 14:10:00 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug } = router.query;
|
|
|
|
|
2023-07-11 09:48:47 +00:00
|
|
|
const { issueView } = useIssuesView();
|
|
|
|
|
2023-04-14 14:10:00 +00:00
|
|
|
return (
|
2023-06-28 11:57:43 +00:00
|
|
|
<Tooltip
|
|
|
|
tooltipHeading="Due Date"
|
2023-07-04 12:49:19 +00:00
|
|
|
tooltipContent={
|
|
|
|
issue.target_date ? renderShortDateWithYearFormat(issue.target_date) ?? "N/A" : "N/A"
|
|
|
|
}
|
2023-06-28 11:57:43 +00:00
|
|
|
position={tooltipPosition}
|
|
|
|
>
|
2023-04-14 14:10:00 +00:00
|
|
|
<div
|
2023-07-31 11:52:48 +00:00
|
|
|
className={`group flex-shrink-0 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,
|
|
|
|
},
|
2023-06-24 12:39:06 +00:00
|
|
|
issue
|
2023-05-10 20:57:14 +00:00
|
|
|
);
|
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-07-11 09:48:47 +00:00
|
|
|
className={`${issue?.target_date ? "w-[6.5rem]" : "w-[5rem] text-center"} ${
|
|
|
|
issueView === "kanban" ? "bg-custom-background-90" : "bg-custom-background-100"
|
|
|
|
}`}
|
2023-06-23 11:50:05 +00:00
|
|
|
noBorder={noBorder}
|
2023-04-14 14:10:00 +00:00
|
|
|
disabled={isNotAllowed}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
|
|
|
};
|