2023-05-10 20:57:14 +00:00
|
|
|
import React, { useState } from "react";
|
|
|
|
|
2023-09-22 10:01:54 +00:00
|
|
|
// next
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
2023-05-10 20:57:14 +00:00
|
|
|
// react-beautiful-dnd
|
|
|
|
import { Draggable } from "react-beautiful-dnd";
|
|
|
|
// component
|
|
|
|
import StrictModeDroppable from "components/dnd/StrictModeDroppable";
|
|
|
|
import { SingleCalendarIssue } from "./single-issue";
|
2023-09-22 10:01:54 +00:00
|
|
|
import { CalendarInlineCreateIssueForm } from "./inline-create-issue-form";
|
2023-05-10 20:57:14 +00:00
|
|
|
// icons
|
|
|
|
import { PlusSmallIcon } from "@heroicons/react/24/outline";
|
|
|
|
// helper
|
|
|
|
import { formatDate } from "helpers/calendar.helper";
|
|
|
|
// types
|
2023-06-06 16:06:00 +00:00
|
|
|
import { ICurrentUserResponse, IIssue } from "types";
|
2023-05-10 20:57:14 +00:00
|
|
|
|
|
|
|
type Props = {
|
2023-07-26 12:21:26 +00:00
|
|
|
handleIssueAction: (issue: IIssue, action: "copy" | "delete" | "edit") => void;
|
2023-05-10 20:57:14 +00:00
|
|
|
index: number;
|
|
|
|
date: {
|
|
|
|
date: string;
|
|
|
|
issues: IIssue[];
|
|
|
|
};
|
|
|
|
addIssueToDate: (date: string) => void;
|
|
|
|
showWeekEnds: boolean;
|
2023-06-06 16:06:00 +00:00
|
|
|
user: ICurrentUserResponse | undefined;
|
2023-05-10 20:57:14 +00:00
|
|
|
isNotAllowed: boolean;
|
|
|
|
};
|
|
|
|
|
2023-09-22 10:01:54 +00:00
|
|
|
export const SingleCalendarDate: React.FC<Props> = (props) => {
|
2023-09-27 09:11:32 +00:00
|
|
|
const { handleIssueAction, date, index, showWeekEnds, user, isNotAllowed } = props;
|
2023-09-22 10:01:54 +00:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
const { cycleId, moduleId } = router.query;
|
|
|
|
|
2023-05-10 20:57:14 +00:00
|
|
|
const [showAllIssues, setShowAllIssues] = useState(false);
|
2023-09-22 10:01:54 +00:00
|
|
|
const [isCreateIssueFormOpen, setIsCreateIssueFormOpen] = useState(false);
|
2023-05-10 20:57:14 +00:00
|
|
|
|
2023-09-27 03:21:29 +00:00
|
|
|
const [formPosition, setFormPosition] = useState({ x: 0, y: 0 });
|
|
|
|
|
2023-05-10 20:57:14 +00:00
|
|
|
const totalIssues = date.issues.length;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<StrictModeDroppable droppableId={date.date}>
|
|
|
|
{(provided) => (
|
|
|
|
<div
|
|
|
|
key={index}
|
|
|
|
ref={provided.innerRef}
|
|
|
|
{...provided.droppableProps}
|
2023-07-17 10:58:23 +00:00
|
|
|
className={`group relative flex min-h-[150px] flex-col gap-1.5 border-t border-custom-border-200 p-2.5 text-left text-sm font-medium hover:bg-custom-background-90 ${
|
2023-05-10 20:57:14 +00:00
|
|
|
showWeekEnds
|
|
|
|
? (index + 1) % 7 === 0
|
|
|
|
? ""
|
|
|
|
: "border-r"
|
|
|
|
: (index + 1) % 5 === 0
|
|
|
|
? ""
|
|
|
|
: "border-r"
|
|
|
|
}`}
|
|
|
|
>
|
2023-09-27 09:11:32 +00:00
|
|
|
<>
|
|
|
|
<span>{formatDate(new Date(date.date), "d")}</span>
|
|
|
|
{totalIssues > 0 &&
|
|
|
|
date.issues.slice(0, showAllIssues ? totalIssues : 4).map((issue: IIssue, index) => (
|
|
|
|
<Draggable key={issue.id} draggableId={issue.id} index={index}>
|
|
|
|
{(provided, snapshot) => (
|
|
|
|
<SingleCalendarIssue
|
|
|
|
key={index}
|
|
|
|
index={index}
|
|
|
|
provided={provided}
|
|
|
|
snapshot={snapshot}
|
|
|
|
issue={issue}
|
|
|
|
projectId={issue.project_detail.id}
|
|
|
|
handleEditIssue={() => handleIssueAction(issue, "edit")}
|
|
|
|
handleDeleteIssue={() => handleIssueAction(issue, "delete")}
|
|
|
|
user={user}
|
|
|
|
isNotAllowed={isNotAllowed}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Draggable>
|
|
|
|
))}
|
2023-09-27 09:32:35 +00:00
|
|
|
|
|
|
|
<CalendarInlineCreateIssueForm
|
|
|
|
isOpen={isCreateIssueFormOpen}
|
|
|
|
dependencies={[showWeekEnds]}
|
|
|
|
handleClose={() => setIsCreateIssueFormOpen(false)}
|
|
|
|
prePopulatedData={{
|
|
|
|
target_date: date.date,
|
|
|
|
...(cycleId && { cycle: cycleId.toString() }),
|
|
|
|
...(moduleId && { module: moduleId.toString() }),
|
2023-09-27 03:21:29 +00:00
|
|
|
}}
|
2023-09-27 09:32:35 +00:00
|
|
|
/>
|
2023-05-10 20:57:14 +00:00
|
|
|
|
2023-09-27 09:11:32 +00:00
|
|
|
{totalIssues > 4 && (
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="w-min whitespace-nowrap rounded-md border border-custom-border-200 bg-custom-background-80 px-1.5 py-1 text-xs"
|
|
|
|
onClick={() => setShowAllIssues((prevData) => !prevData)}
|
|
|
|
>
|
|
|
|
{showAllIssues ? "Hide" : totalIssues - 4 + " more"}
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div
|
|
|
|
className={`absolute top-2 right-2 flex items-center justify-center rounded-md bg-custom-background-80 p-1 text-xs text-custom-text-200 opacity-0 group-hover:opacity-100`}
|
2023-05-10 20:57:14 +00:00
|
|
|
>
|
2023-09-27 09:11:32 +00:00
|
|
|
<button
|
|
|
|
onClick={(e) => {
|
|
|
|
setIsCreateIssueFormOpen(true);
|
|
|
|
setFormPosition({ x: e.clientX, y: e.clientY });
|
|
|
|
}}
|
|
|
|
className="flex items-center justify-center gap-1 text-center"
|
|
|
|
>
|
|
|
|
<PlusSmallIcon className="h-4 w-4 text-custom-text-200" />
|
|
|
|
Add issue
|
|
|
|
</button>
|
|
|
|
</div>
|
2023-05-10 20:57:14 +00:00
|
|
|
|
2023-09-27 09:11:32 +00:00
|
|
|
{provided.placeholder}
|
|
|
|
</>
|
2023-05-10 20:57:14 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</StrictModeDroppable>
|
|
|
|
);
|
|
|
|
};
|