2024-01-24 15:03:54 +00:00
|
|
|
import React from "react";
|
2024-02-15 14:01:38 +00:00
|
|
|
import { observer } from "mobx-react";
|
2024-01-24 15:03:54 +00:00
|
|
|
// constants
|
2024-04-08 13:41:47 +00:00
|
|
|
import { INBOX_STATUS } from "@/constants/inbox";
|
|
|
|
// helpers
|
|
|
|
import { cn } from "@/helpers/common.helper";
|
|
|
|
// store
|
|
|
|
import { IInboxIssueStore } from "@/store/inbox/inbox-issue.store";
|
2024-01-24 15:03:54 +00:00
|
|
|
|
|
|
|
type Props = {
|
2024-04-08 13:41:47 +00:00
|
|
|
inboxIssue: IInboxIssueStore;
|
2024-01-24 15:03:54 +00:00
|
|
|
iconSize?: number;
|
|
|
|
showDescription?: boolean;
|
|
|
|
};
|
|
|
|
|
2024-02-15 14:01:38 +00:00
|
|
|
export const InboxIssueStatus: React.FC<Props> = observer((props) => {
|
2024-04-08 13:41:47 +00:00
|
|
|
const { inboxIssue, iconSize = 16, showDescription = false } = props;
|
|
|
|
// derived values
|
|
|
|
const inboxIssueStatusDetail = INBOX_STATUS.find((s) => s.status === inboxIssue.status);
|
2024-01-24 15:03:54 +00:00
|
|
|
if (!inboxIssueStatusDetail) return <></>;
|
|
|
|
|
2024-04-08 13:41:47 +00:00
|
|
|
const isSnoozedDatePassed = inboxIssue.status === 0 && new Date(inboxIssue.snoozed_till ?? "") < new Date();
|
|
|
|
|
|
|
|
const description = inboxIssueStatusDetail.description(new Date(inboxIssue.snoozed_till ?? ""));
|
2024-01-24 15:03:54 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2024-04-08 13:41:47 +00:00
|
|
|
className={cn(
|
|
|
|
`relative flex flex-col gap-1 p-1.5 py-0.5 rounded ${inboxIssueStatusDetail.textColor(
|
|
|
|
isSnoozedDatePassed
|
|
|
|
)} ${inboxIssueStatusDetail.bgColor(isSnoozedDatePassed)}`
|
2024-01-24 15:03:54 +00:00
|
|
|
)}
|
2024-04-08 13:41:47 +00:00
|
|
|
>
|
|
|
|
<div className={`flex items-center gap-1`}>
|
2024-04-10 08:22:57 +00:00
|
|
|
<inboxIssueStatusDetail.icon size={iconSize} className="flex-shrink-0" />
|
|
|
|
<div className="font-medium text-xs whitespace-nowrap">
|
2024-04-08 13:41:47 +00:00
|
|
|
{inboxIssue?.status === 0 && inboxIssue?.snoozed_till
|
|
|
|
? inboxIssueStatusDetail.description(inboxIssue?.snoozed_till)
|
|
|
|
: inboxIssueStatusDetail.title}
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-04-10 08:22:57 +00:00
|
|
|
{showDescription && <div className="text-sm whitespace-nowrap">{description}</div>}
|
2024-01-24 15:03:54 +00:00
|
|
|
</div>
|
|
|
|
);
|
2024-02-15 14:01:38 +00:00
|
|
|
});
|