Files
sign/apps/remix/app/components/general/document/document-status.tsx

92 lines
2.3 KiB
TypeScript
Raw Normal View History

import type { HTMLAttributes } from 'react';
2023-06-09 18:21:18 +10:00
2024-08-27 20:34:39 +09:00
import type { MessageDescriptor } from '@lingui/core';
2025-01-02 15:33:37 +11:00
import { msg } from '@lingui/core/macro';
2024-08-27 20:34:39 +09:00
import { useLingui } from '@lingui/react';
2025-03-13 19:45:11 +00:00
import { CheckCircle2, Clock, File, Trash, XCircle } from 'lucide-react';
import type { LucideIcon } from 'lucide-react/dist/lucide-react';
2023-06-09 18:21:18 +10:00
import type { ExtendedDocumentStatus } from '@documenso/prisma/types/extended-document-status';
2023-08-24 16:50:40 +10:00
import { SignatureIcon } from '@documenso/ui/icons/signature';
2023-06-09 18:21:18 +10:00
import { cn } from '@documenso/ui/lib/utils';
type FriendlyStatus = {
2024-08-27 20:34:39 +09:00
label: MessageDescriptor;
labelExtended: MessageDescriptor;
2023-08-24 16:50:40 +10:00
icon?: LucideIcon;
2023-06-09 18:21:18 +10:00
color: string;
};
2024-02-12 17:30:23 +11:00
export const FRIENDLY_STATUS_MAP: Record<ExtendedDocumentStatus, FriendlyStatus> = {
2023-06-09 18:21:18 +10:00
PENDING: {
2024-08-27 20:34:39 +09:00
label: msg`Pending`,
labelExtended: msg`Document pending`,
2023-06-09 18:21:18 +10:00
icon: Clock,
2023-09-24 14:45:50 +10:00
color: 'text-blue-600 dark:text-blue-300',
2023-06-09 18:21:18 +10:00
},
COMPLETED: {
2024-08-27 20:34:39 +09:00
label: msg`Completed`,
labelExtended: msg`Document completed`,
2023-06-09 18:21:18 +10:00
icon: CheckCircle2,
2023-09-24 14:45:50 +10:00
color: 'text-green-500 dark:text-green-300',
2023-06-09 18:21:18 +10:00
},
2023-08-16 09:29:16 +02:00
DRAFT: {
2024-08-27 20:34:39 +09:00
label: msg`Draft`,
labelExtended: msg`Document draft`,
2023-08-16 09:29:16 +02:00
icon: File,
2023-09-24 14:45:50 +10:00
color: 'text-yellow-500 dark:text-yellow-200',
2023-08-16 09:29:16 +02:00
},
2025-03-13 19:45:11 +00:00
DELETED: {
label: msg`Deleted`,
labelExtended: msg`Document deleted`,
icon: Trash,
color: 'text-red-700 dark:text-red-500',
},
2023-08-24 16:50:40 +10:00
INBOX: {
2024-08-27 20:34:39 +09:00
label: msg`Inbox`,
labelExtended: msg`Document inbox`,
2023-08-24 16:50:40 +10:00
icon: SignatureIcon,
color: 'text-muted-foreground',
},
ALL: {
2024-08-27 20:34:39 +09:00
label: msg`All`,
labelExtended: msg`Document All`,
2023-08-24 16:50:40 +10:00
color: 'text-muted-foreground',
},
2025-03-13 19:45:11 +00:00
REJECTED: {
label: msg`Rejected`,
labelExtended: msg`Document rejected`,
icon: XCircle,
color: 'text-red-500 dark:text-red-300',
},
2023-06-09 18:21:18 +10:00
};
export type DocumentStatusProps = HTMLAttributes<HTMLSpanElement> & {
2023-08-24 16:50:40 +10:00
status: ExtendedDocumentStatus;
inheritColor?: boolean;
2023-06-09 18:21:18 +10:00
};
export const DocumentStatus = ({
className,
status,
inheritColor,
...props
}: DocumentStatusProps) => {
2024-08-27 20:34:39 +09:00
const { _ } = useLingui();
2023-06-09 18:21:18 +10:00
const { label, icon: Icon, color } = FRIENDLY_STATUS_MAP[status];
return (
<span className={cn('flex items-center', className)} {...props}>
2023-08-24 16:50:40 +10:00
{Icon && (
<Icon
className={cn('mr-2 inline-block h-4 w-4', {
[color]: !inheritColor,
})}
/>
)}
2024-08-27 20:34:39 +09:00
{_(label)}
2023-06-09 18:21:18 +10:00
</span>
);
};