// next import type { NextPage } from "next"; import Link from "next/link"; // react import React from "react"; // layouts import AppLayout from "layouts/app-layout"; // swr import useSWR from "swr"; // hooks import useUser from "lib/hooks/useUser"; // hoc import withAuthWrapper from "lib/hoc/withAuthWrapper"; // fetch keys import { USER_ISSUE } from "constants/fetch-keys"; // services import userService from "lib/services/user.service"; // ui import { Spinner } from "ui"; // icons import { ArrowRightIcon, CalendarDaysIcon } from "@heroicons/react/24/outline"; // types import type { IIssue } from "types"; import { addSpaceIfCamelCase, findHowManyDaysLeft, renderShortNumericDateFormat, } from "constants/common"; const Workspace: NextPage = () => { const { user, activeWorkspace, projects } = useUser(); const { data: myIssues } = useSWR( user && activeWorkspace ? USER_ISSUE(activeWorkspace.slug) : null, user && activeWorkspace ? () => userService.userIssues(activeWorkspace.slug) : null ); const cards = [ { id: 1, numbers: projects?.length ?? 0, title: "Projects", }, { id: 3, numbers: myIssues?.length ?? 0, title: "Issues", }, ]; const hours = new Date().getHours(); return (
{user ? (
Good{" "} {hours >= 4 && hours < 12 ? "Morning" : hours >= 12 && hours < 17 ? "Afternoon" : "Evening"} , {user.first_name}!!
) : (
)} {/* dashboard */}
{cards.map(({ id, title, numbers }) => (

#{title}

{numbers}

))}
{myIssues ? ( myIssues.length > 0 ? (

My Issues

{myIssues.length}

{myIssues.map((issue) => (
{issue.priority ?? "None"}
{addSpaceIfCamelCase(issue.state_detail.name)}
{issue.target_date ? renderShortNumericDateFormat(issue.target_date) : "N/A"}
Target date
{renderShortNumericDateFormat(issue.target_date ?? "")}
{issue.target_date && (issue.target_date < new Date().toISOString() ? `Target date has passed by ${findHowManyDaysLeft( issue.target_date )} days` : findHowManyDaysLeft(issue.target_date) <= 3 ? `Target date is in ${findHowManyDaysLeft( issue.target_date )} days` : "Target date")}
))}
) : (

No Issues Found

) ) : (
)}

PROJECTS

{projects && activeWorkspace ? ( projects.length > 0 ? ( projects .sort((a, b) => Date.parse(`${a.updated_at}`) - Date.parse(`${b.updated_at}`)) .map( (project, index) => index < 3 && (

{project.name}

) ) ) : (

No projects has been create for this workspace.

) ) : (
)}
); }; export default withAuthWrapper(Workspace);