Uecko_ERP/modules/customer-invoices/src/web/components/customer-invoice-status-badge.tsx

68 lines
2.2 KiB
TypeScript
Raw Normal View History

2025-07-07 18:25:13 +00:00
import { Badge } from "@repo/shadcn-ui/components";
import { cn } from "@repo/shadcn-ui/lib/utils";
import { forwardRef } from "react";
2025-07-09 17:56:15 +00:00
import { useTranslation } from "../i18n";
2025-07-07 18:25:13 +00:00
2025-10-18 19:57:52 +00:00
export type CustomerInvoiceStatus = "draft" | "sent" | "approved" | "rejected" | "issued";
2025-07-07 18:25:13 +00:00
export type CustomerInvoiceStatusBadgeProps = {
2025-10-18 19:57:52 +00:00
status: string | CustomerInvoiceStatus; // permitir cualquier valor
dotVisible?: boolean;
2025-07-07 18:25:13 +00:00
className?: string;
};
const statusColorConfig: Record<CustomerInvoiceStatus, { badge: string; dot: string }> = {
draft: {
badge:
2025-10-18 19:57:52 +00:00
"bg-gray-500/10 dark:bg-gray-500/20 hover:bg-gray-500/10 text-gray-600 border-gray-400/60",
2025-07-07 18:25:13 +00:00
dot: "bg-gray-500",
},
sent: {
badge:
2025-10-18 19:57:52 +00:00
"bg-amber-500/10 dark:bg-amber-500/20 hover:bg-amber-500/10 text-amber-500 border-amber-600/60",
dot: "bg-amber-500",
2025-07-07 18:25:13 +00:00
},
2025-10-18 19:57:52 +00:00
approved: {
2025-07-07 18:25:13 +00:00
badge:
2025-10-18 19:57:52 +00:00
"bg-emerald-500/10 dark:bg-emerald-500/20 hover:bg-emerald-500/10 text-emerald-500 border-emerald-600/60",
2025-07-07 18:25:13 +00:00
dot: "bg-emerald-500",
},
rejected: {
2025-10-18 19:57:52 +00:00
badge:
"bg-red-500/10 dark:bg-red-500/20 hover:bg-red-500/10 text-red-500 border-red-600/60",
2025-07-07 18:25:13 +00:00
dot: "bg-red-500",
},
2025-10-18 19:57:52 +00:00
issued: {
badge:
"bg-blue-600/10 dark:bg-blue-600/20 hover:bg-blue-600/10 text-blue-500 border-blue-600/60",
dot: "bg-blue-500",
},
2025-07-07 18:25:13 +00:00
};
export const CustomerInvoiceStatusBadge = forwardRef<
HTMLDivElement,
CustomerInvoiceStatusBadgeProps
2025-10-18 19:57:52 +00:00
>(({ status, dotVisible, className, ...props }, ref) => {
2025-07-09 17:56:15 +00:00
const { t } = useTranslation();
2025-07-07 18:25:13 +00:00
const normalizedStatus = status.toLowerCase() as CustomerInvoiceStatus;
const config = statusColorConfig[normalizedStatus];
const commonClassName = "transition-colors duration-200 cursor-pointer shadow-none rounded-full";
if (!config) {
return (
<Badge ref={ref} className={cn(commonClassName, className)} {...props}>
{status}
</Badge>
);
}
return (
<Badge className={cn(commonClassName, config.badge, className)} {...props}>
2025-10-18 19:57:52 +00:00
{dotVisible && <div className={cn("h-1.5 w-1.5 rounded-full mr-2", config.dot)} />}
{t(`catalog.status.${normalizedStatus}`, { defaultValue: status })}
2025-07-07 18:25:13 +00:00
</Badge>
);
});
CustomerInvoiceStatusBadge.displayName = "CustomerInvoiceStatusBadge";