Files
tbbank-frontend/src/constants/statusCells.tsx
2026-10-25 00:30:50 +05:00

70 lines
2.2 KiB
TypeScript

import { useTranslation } from "react-i18next";
import { CheckCircle2, XCircle } from "lucide-react";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
import { STATUS_ICONS, STATUS_BADGE_VARIANTS, isStatusValue, getStatusLabel } from "@/constants/statusOptions";
import {
GATEWAY_STATUS_BADGE_VARIANTS,
GATEWAY_STATUS_ICONS,
getGatewayStatusLabel,
isGatewayStatusValue,
} from "@/constants/paymentStatus";
interface StatusCellProps {
status: string;
prefix?: string;
fallbackLabels?: Record<string, string>;
fallbackVariants?: Record<string, StatusBadgeVariant>;
}
export function StatusCell({ status, prefix = "status", fallbackLabels, fallbackVariants }: StatusCellProps) {
const { t } = useTranslation();
if (isStatusValue(status)) {
return <StatusBadge label={getStatusLabel(status, t, prefix)} variant={STATUS_BADGE_VARIANTS[status]} icon={STATUS_ICONS[status]} />;
}
const label = (fallbackLabels && fallbackLabels[status]) ?? status;
const variant = (fallbackVariants && fallbackVariants[status]) ?? "default";
return <StatusBadge label={label} variant={variant} />;
}
interface ActiveStatusCellProps {
active?: boolean;
status?: boolean;
labelActive?: string;
labelInactive?: string;
}
export function ActiveStatusCell({ active, status, labelActive, labelInactive }: ActiveStatusCellProps) {
const { t } = useTranslation();
const isActive = Boolean(active ?? status);
return (
<StatusBadge
label={isActive ? (labelActive ?? t("common.active", "Işjeň")) : (labelInactive ?? t("common.inactive", "Işjeň däl"))}
variant={isActive ? "success" : "default"}
icon={isActive ? CheckCircle2 : XCircle}
/>
);
}
interface GatewayStatusCellProps {
status?: string | null;
}
export function GatewayStatusCell({ status }: GatewayStatusCellProps) {
const { t } = useTranslation();
const normalizedStatus = status || "unknown";
if (isGatewayStatusValue(normalizedStatus)) {
return (
<StatusBadge
label={getGatewayStatusLabel(normalizedStatus, t)}
variant={GATEWAY_STATUS_BADGE_VARIANTS[normalizedStatus]}
icon={GATEWAY_STATUS_ICONS[normalizedStatus]}
/>
);
}
return <StatusBadge label={normalizedStatus} variant="default" />;
}