import { useEffect, useState } from "react"; import { useRouter } from "next/router"; // react-datepicker import DatePicker from "react-datepicker"; // headless ui import { Popover } from "@headlessui/react"; // contexts import { useProjectMyMembership } from "contexts/project-member.context"; // hooks import useInboxView from "hooks/use-inbox-view"; import useUserAuth from "hooks/use-user-auth"; // components import { FiltersDropdown } from "components/inbox"; // ui import { PrimaryButton, SecondaryButton } from "components/ui"; // icons import { InboxIcon, StackedLayersHorizontalIcon } from "components/icons"; import { ChevronDownIcon, ChevronUpIcon, CheckCircleIcon, ClockIcon, XCircleIcon, TrashIcon, } from "@heroicons/react/24/outline"; // types import type { IInboxIssue } from "types"; type Props = { issueCount: number; currentIssueIndex: number; issue?: IInboxIssue; onAccept: () => Promise; onDecline: () => void; onMarkAsDuplicate: () => void; onSnooze: (date: Date | string) => void; onDelete: () => void; }; export const InboxActionHeader: React.FC = (props) => { const { issueCount, currentIssueIndex, onAccept, onDecline, onMarkAsDuplicate, onSnooze, onDelete, issue, } = props; const [isAccepting, setIsAccepting] = useState(false); const [date, setDate] = useState(new Date()); const router = useRouter(); const { inboxIssueId } = router.query; const { memberRole } = useProjectMyMembership(); const { filters, setFilters, filtersLength } = useInboxView(); const { user } = useUserAuth(); const handleAcceptIssue = () => { setIsAccepting(true); onAccept().finally(() => setIsAccepting(false)); }; useEffect(() => { if (!issue?.issue_inbox[0].snoozed_till) return; setDate(new Date(issue.issue_inbox[0].snoozed_till)); }, [issue]); const issueStatus = issue?.issue_inbox[0].status; const isAllowed = memberRole.isMember || memberRole.isOwner; const today = new Date(); const tomorrow = new Date(today); tomorrow.setDate(today.getDate() + 1); return (

Inbox

{ const key = option.key as keyof typeof filters; const valueExists = (filters[key] as any[])?.includes(option.value); if (valueExists) { setFilters({ [option.key]: ((filters[key] ?? []) as any[])?.filter( (val) => val !== option.value ), }); } else { setFilters({ [option.key]: [...((filters[key] ?? []) as any[]), option.value], }); } }} direction="right" height="rg" /> {filtersLength > 0 && (
{filtersLength}
)}
{inboxIssueId && (
{currentIssueIndex + 1}/{issueCount}
{isAllowed && (
Snooze {({ close }) => (
{ if (!val) return; setDate(val); }} dateFormat="dd-MM-yyyy" minDate={tomorrow} inline /> { close(); onSnooze(date); }} > Snooze
)}
)} {isAllowed && (
Mark as duplicate {isAccepting ? "Accepting..." : "Accept"} Decline
)} {(isAllowed || user?.id === issue?.created_by) && (
Delete
)}
)}
); };