2023-01-26 18:12:20 +00:00
|
|
|
import React from "react";
|
|
|
|
|
2023-03-23 19:41:42 +00:00
|
|
|
import { useRouter } from "next/router";
|
|
|
|
|
|
|
|
import useSWR from "swr";
|
|
|
|
|
|
|
|
// services
|
|
|
|
import issuesService from "services/issues.service";
|
|
|
|
import projectService from "services/project.service";
|
2023-03-15 06:14:44 +00:00
|
|
|
// hooks
|
|
|
|
import useIssuesView from "hooks/use-issues-view";
|
2023-03-31 15:50:23 +00:00
|
|
|
// component
|
|
|
|
import { Avatar } from "components/ui";
|
2023-01-26 18:12:20 +00:00
|
|
|
// icons
|
2023-02-28 09:12:46 +00:00
|
|
|
import { ArrowsPointingInIcon, ArrowsPointingOutIcon, PlusIcon } from "@heroicons/react/24/outline";
|
2023-03-31 15:50:23 +00:00
|
|
|
import { getPriorityIcon, getStateGroupIcon } from "components/icons";
|
2023-01-26 18:12:20 +00:00
|
|
|
// helpers
|
|
|
|
import { addSpaceIfCamelCase } from "helpers/string.helper";
|
|
|
|
// types
|
2023-03-23 19:41:42 +00:00
|
|
|
import { IIssueLabels, IState } from "types";
|
|
|
|
// fetch-keys
|
|
|
|
import { PROJECT_ISSUE_LABELS, PROJECT_MEMBERS } from "constants/fetch-keys";
|
|
|
|
|
2023-01-26 18:12:20 +00:00
|
|
|
type Props = {
|
2023-02-28 09:12:46 +00:00
|
|
|
currentState?: IState | null;
|
2023-01-26 18:12:20 +00:00
|
|
|
groupTitle: string;
|
|
|
|
addIssueToState: () => void;
|
2023-02-14 09:16:48 +00:00
|
|
|
isCollapsed: boolean;
|
|
|
|
setIsCollapsed: React.Dispatch<React.SetStateAction<boolean>>;
|
2023-03-23 17:12:08 +00:00
|
|
|
isCompleted?: boolean;
|
2023-01-26 18:12:20 +00:00
|
|
|
};
|
|
|
|
|
2023-02-05 11:27:37 +00:00
|
|
|
export const BoardHeader: React.FC<Props> = ({
|
2023-02-28 09:12:46 +00:00
|
|
|
currentState,
|
2023-01-26 18:12:20 +00:00
|
|
|
groupTitle,
|
|
|
|
addIssueToState,
|
2023-02-14 09:16:48 +00:00
|
|
|
isCollapsed,
|
|
|
|
setIsCollapsed,
|
2023-03-23 17:12:08 +00:00
|
|
|
isCompleted = false,
|
2023-02-14 09:16:48 +00:00
|
|
|
}) => {
|
2023-03-23 19:41:42 +00:00
|
|
|
const router = useRouter();
|
|
|
|
const { workspaceSlug, projectId } = router.query;
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
const { groupedByIssues, groupByProperty: selectedGroup } = useIssuesView();
|
|
|
|
|
2023-03-23 19:41:42 +00:00
|
|
|
const { data: issueLabels } = useSWR<IIssueLabels[]>(
|
|
|
|
workspaceSlug && projectId ? PROJECT_ISSUE_LABELS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => issuesService.getIssueLabels(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
|
|
|
const { data: members } = useSWR(
|
|
|
|
workspaceSlug && projectId ? PROJECT_MEMBERS(projectId as string) : null,
|
|
|
|
workspaceSlug && projectId
|
|
|
|
? () => projectService.projectMembers(workspaceSlug as string, projectId as string)
|
|
|
|
: null
|
|
|
|
);
|
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
let bgColor = "#000000";
|
|
|
|
if (selectedGroup === "state") bgColor = currentState?.color ?? "#000000";
|
2023-02-14 09:16:48 +00:00
|
|
|
|
2023-03-15 06:14:44 +00:00
|
|
|
if (selectedGroup === "priority")
|
|
|
|
groupTitle === "high"
|
|
|
|
? (bgColor = "#dc2626")
|
|
|
|
: groupTitle === "medium"
|
|
|
|
? (bgColor = "#f97316")
|
|
|
|
: groupTitle === "low"
|
|
|
|
? (bgColor = "#22c55e")
|
|
|
|
: (bgColor = "#ff0000");
|
2023-02-14 09:16:48 +00:00
|
|
|
|
2023-03-23 19:41:42 +00:00
|
|
|
const getGroupTitle = () => {
|
|
|
|
let title = addSpaceIfCamelCase(groupTitle);
|
|
|
|
|
|
|
|
switch (selectedGroup) {
|
|
|
|
case "state":
|
|
|
|
title = addSpaceIfCamelCase(currentState?.name ?? "");
|
|
|
|
break;
|
|
|
|
case "labels":
|
|
|
|
title = issueLabels?.find((label) => label.id === groupTitle)?.name ?? "None";
|
|
|
|
break;
|
|
|
|
case "created_by":
|
|
|
|
const member = members?.find((member) => member.member.id === groupTitle)?.member;
|
|
|
|
title =
|
|
|
|
member?.first_name && member.first_name !== ""
|
|
|
|
? `${member.first_name} ${member.last_name}`
|
|
|
|
: member?.email ?? "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return title;
|
|
|
|
};
|
|
|
|
|
2023-03-31 15:50:23 +00:00
|
|
|
const getGroupIcon = () => {
|
|
|
|
let icon;
|
|
|
|
|
|
|
|
switch (selectedGroup) {
|
|
|
|
case "state":
|
2023-04-17 19:45:10 +00:00
|
|
|
icon = currentState && getStateGroupIcon(currentState.group, "16", "16", bgColor);
|
2023-03-31 15:50:23 +00:00
|
|
|
break;
|
|
|
|
case "priority":
|
2023-04-17 19:45:10 +00:00
|
|
|
icon = getPriorityIcon(groupTitle, "text-lg");
|
2023-03-31 15:50:23 +00:00
|
|
|
break;
|
|
|
|
case "labels":
|
|
|
|
const labelColor =
|
|
|
|
issueLabels?.find((label) => label.id === groupTitle)?.color ?? "#000000";
|
|
|
|
icon = (
|
|
|
|
<span
|
2023-04-17 19:45:10 +00:00
|
|
|
className="h-3.5 w-3.5 flex-shrink-0 rounded-full"
|
2023-03-31 15:50:23 +00:00
|
|
|
style={{ backgroundColor: labelColor }}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case "created_by":
|
|
|
|
const member = members?.find((member) => member.member.id === groupTitle)?.member;
|
|
|
|
icon = <Avatar user={member} height="24px" width="24px" fontSize="12px" />;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return icon;
|
|
|
|
};
|
|
|
|
|
2023-02-14 09:16:48 +00:00
|
|
|
return (
|
|
|
|
<div
|
2023-04-20 12:43:21 +00:00
|
|
|
className={`flex items-center justify-between px-1 ${
|
|
|
|
!isCollapsed ? "flex-col rounded-md bg-brand-surface-1" : ""
|
2023-02-14 09:16:48 +00:00
|
|
|
}`}
|
|
|
|
>
|
|
|
|
<div className={`flex items-center ${!isCollapsed ? "flex-col gap-2" : "gap-1"}`}>
|
|
|
|
<div
|
2023-03-14 06:48:14 +00:00
|
|
|
className={`flex cursor-pointer items-center gap-x-3 ${
|
2023-02-14 09:16:48 +00:00
|
|
|
!isCollapsed ? "mb-2 flex-col gap-y-2 py-2" : ""
|
|
|
|
}`}
|
2023-01-26 18:12:20 +00:00
|
|
|
>
|
2023-03-31 15:50:23 +00:00
|
|
|
<span className="flex items-center">{getGroupIcon()}</span>
|
2023-02-14 09:16:48 +00:00
|
|
|
<h2
|
2023-03-14 06:48:14 +00:00
|
|
|
className="text-lg font-semibold capitalize"
|
2023-02-14 09:16:48 +00:00
|
|
|
style={{
|
|
|
|
writingMode: !isCollapsed ? "vertical-rl" : "horizontal-tb",
|
|
|
|
}}
|
|
|
|
>
|
2023-03-23 19:41:42 +00:00
|
|
|
{getGroupTitle()}
|
2023-02-14 09:16:48 +00:00
|
|
|
</h2>
|
2023-04-05 19:21:15 +00:00
|
|
|
<span
|
2023-04-17 19:45:10 +00:00
|
|
|
className={`${
|
|
|
|
isCollapsed ? "ml-0.5" : ""
|
2023-04-20 12:43:21 +00:00
|
|
|
} min-w-[2.5rem] rounded-full bg-brand-surface-2 py-1 text-center text-xs`}
|
2023-04-05 19:21:15 +00:00
|
|
|
>
|
2023-03-15 06:14:44 +00:00
|
|
|
{groupedByIssues?.[groupTitle].length ?? 0}
|
2023-02-28 09:12:46 +00:00
|
|
|
</span>
|
2023-02-14 09:16:48 +00:00
|
|
|
</div>
|
2023-01-26 18:12:20 +00:00
|
|
|
</div>
|
|
|
|
|
2023-02-14 09:16:48 +00:00
|
|
|
<div className={`flex items-center ${!isCollapsed ? "flex-col pb-2" : ""}`}>
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-20 08:11:24 +00:00
|
|
|
className="grid h-7 w-7 place-items-center rounded p-1 text-brand-secondary outline-none duration-300 hover:bg-brand-surface-2"
|
2023-02-14 09:16:48 +00:00
|
|
|
onClick={() => {
|
|
|
|
setIsCollapsed((prevData) => !prevData);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{isCollapsed ? (
|
|
|
|
<ArrowsPointingInIcon className="h-4 w-4" />
|
|
|
|
) : (
|
|
|
|
<ArrowsPointingOutIcon className="h-4 w-4" />
|
|
|
|
)}
|
|
|
|
</button>
|
2023-03-23 17:12:08 +00:00
|
|
|
{!isCompleted && (
|
|
|
|
<button
|
|
|
|
type="button"
|
2023-04-20 08:11:24 +00:00
|
|
|
className="grid h-7 w-7 place-items-center rounded p-1 text-brand-secondary outline-none duration-300 hover:bg-brand-surface-2"
|
2023-03-23 17:12:08 +00:00
|
|
|
onClick={addIssueToState}
|
|
|
|
>
|
|
|
|
<PlusIcon className="h-4 w-4" />
|
|
|
|
</button>
|
|
|
|
)}
|
2023-02-14 09:16:48 +00:00
|
|
|
</div>
|
2023-01-26 18:12:20 +00:00
|
|
|
</div>
|
2023-02-14 09:16:48 +00:00
|
|
|
);
|
|
|
|
};
|