// react import React from "react"; // next import Link from "next/link"; import type { NextPage } from "next"; import Image from "next/image"; // swr import useSWR from "swr"; // headless ui import { Disclosure, Listbox, Menu, Popover, Transition } from "@headlessui/react"; // layouts import AppLayout from "layouts/app-layout"; // hooks import useUser from "lib/hooks/useUser"; // headless ui // ui import { Spinner, Breadcrumbs, BreadcrumbItem, EmptySpace, EmptySpaceItem, HeaderButton } from "ui"; // icons import { CalendarDaysIcon, ChevronDownIcon, EllipsisHorizontalIcon, PlusIcon, RectangleStackIcon, } from "@heroicons/react/24/outline"; import User from "public/user.png"; // services import userService from "lib/services/user.service"; import issuesServices from "lib/services/issues.service"; import workspaceService from "lib/services/workspace.service"; // hooks import useIssuesProperties from "lib/hooks/useIssuesProperties"; // hoc import withAuth from "lib/hoc/withAuthWrapper"; import useMyIssuesProperties from "lib/hooks/useMyIssueFilter"; // components import ChangeStateDropdown from "components/project/issues/my-issues/ChangeStateDropdown"; // types import { IIssue, IWorkspaceMember, Properties } from "types"; // constants import { USER_ISSUE, WORKSPACE_MEMBERS } from "constants/fetch-keys"; import { addSpaceIfCamelCase, classNames, findHowManyDaysLeft, renderShortNumericDateFormat, replaceUnderscoreIfSnakeCase, } from "constants/common"; import { PRIORITIES } from "constants/"; const MyIssues: NextPage = () => { const { activeWorkspace, user, states } = useUser(); console.log(states); const { data: myIssues, mutate: mutateMyIssues } = useSWR( user && activeWorkspace ? USER_ISSUE(activeWorkspace.slug) : null, user && activeWorkspace ? () => userService.userIssues(activeWorkspace.slug) : null ); const { data: people } = useSWR( activeWorkspace ? WORKSPACE_MEMBERS : null, activeWorkspace ? () => workspaceService.workspaceMembers(activeWorkspace.slug) : null ); const [properties, setProperties] = useIssuesProperties( activeWorkspace?.slug, "21b5fab2-cb0c-4875-9496-619134bf1f32" ); const updateMyIssues = ( workspaceSlug: string, projectId: string, issueId: string, issue: Partial ) => { mutateMyIssues((prevData) => { return prevData?.map((prevIssue) => { if (prevIssue.id === issueId) { return { ...prevIssue, ...issue, state_detail: { ...prevIssue.state_detail, ...issue.state_detail, }, }; } return prevIssue; }); }, false); issuesServices .patchIssue(workspaceSlug, projectId, issueId, issue) .then((response) => { console.log(response); }) .catch((error) => { console.log(error); }); }; const { filteredIssues, setMyIssueGroupByProperty, setMyIssueProperty, groupByProperty } = useMyIssuesProperties(myIssues); return ( } right={
{({ open }) => ( <> View

Properties

{Object.keys(properties).map((key) => ( ))}
)}
{ const e = new KeyboardEvent("keydown", { key: "i", ctrlKey: true, }); document.dispatchEvent(e); }} />
} >
{myIssues ? ( <> {myIssues.length > 0 ? (
{({ open }) => (

My Issues

{myIssues.length}

{myIssues.map((issue: IIssue) => { const assignees = [ ...(issue?.assignees_list ?? []), ...(issue?.assignees ?? []), ]?.map((assignee) => { const tempPerson = people?.find( (p) => p.member.id === assignee )?.member; return { avatar: tempPerson?.avatar, first_name: tempPerson?.first_name, email: tempPerson?.email, }; }); return (
{properties.priority && ( { // partialUpdateIssue({ priority: data }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{issue.priority ?? "None"} {PRIORITIES?.map((priority) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer capitalize select-none px-3 py-2" ) } value={priority} > {priority} ))}
Priority
{issue.priority ?? "None"}
)}
)} {properties.state && ( { // partialUpdateIssue({ state: data }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{addSpaceIfCamelCase(issue.state_detail.name)} {states?.map((state) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer select-none px-3 py-2" ) } value={state.id} > {addSpaceIfCamelCase(state.name)} ))}
State
{issue.state_detail.name}
)}
)} {properties.start_date && (
{issue.start_date ? renderShortNumericDateFormat(issue.start_date) : "N/A"}
Started at
{renderShortNumericDateFormat(issue.start_date ?? "")}
)} {properties.due_date && (
{issue.target_date ? renderShortNumericDateFormat(issue.target_date) : "N/A"}
Due date
{renderShortNumericDateFormat(issue.target_date ?? "")}
{issue.target_date && (issue.target_date < new Date().toISOString() ? `Due date has passed by ${findHowManyDaysLeft( issue.target_date )} days` : findHowManyDaysLeft(issue.target_date) <= 3 ? `Due date is in ${findHowManyDaysLeft( issue.target_date )} days` : "Due date")}
)} {properties.assignee && ( { const newData = issue.assignees ?? []; if (newData.includes(data)) { newData.splice(newData.indexOf(data), 1); } else { newData.push(data); } // partialUpdateIssue({ assignees_list: newData }, issue.id); }} className="group relative flex-shrink-0" > {({ open }) => ( <>
{assignees.length > 0 ? ( assignees.map((assignee, index: number) => (
{assignee.avatar && assignee.avatar !== "" ? (
{assignee?.first_name}
) : (
{assignee.first_name?.charAt(0)}
)}
)) ) : (
No user
)}
{people?.map((person) => ( classNames( active ? "bg-indigo-50" : "bg-white", "cursor-pointer select-none p-2" ) } value={person.member.id} >
{person.member.avatar && person.member.avatar !== "" ? (
avatar
) : (
{person.member.first_name && person.member.first_name !== "" ? person.member.first_name.charAt(0) : person.member.email.charAt(0)}
)}

{person.member.first_name && person.member.first_name !== "" ? person.member.first_name : person.member.email}

))}
Assigned to
{issue.assignee_details?.length > 0 ? issue.assignee_details .map((assignee) => assignee.first_name) .join(", ") : "No one"}
)}
)}
); })}
)}
) : (
Use{" "}
Ctrl/Command + I
{" "} shortcut to create a new issue } Icon={PlusIcon} action={() => { const e = new KeyboardEvent("keydown", { key: "i", ctrlKey: true, }); document.dispatchEvent(e); }} />
)} ) : (
)}
); }; export default withAuth(MyIssues);