refactored code
This commit is contained in:
1 parent
5ed4c9a8ec
commit
d326361a03
46 files changed
+230
-592
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Clock, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { STATUS_BADGE_VARIANTS, isStatusValue, getStatusLabel, type StatusValue } from "@/constants/statusOptions";
|
||||
|
||||
export const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: Clock,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
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} />;
|
||||
}
|
||||
|
||||
export function ActiveStatusCell({ active }: { active: boolean }) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<StatusBadge
|
||||
label={active ? t("common.active", "Işjeň") : t("common.inactive", "Işjeň däl")}
|
||||
variant={active ? "success" : "default"}
|
||||
icon={active ? CheckCircle2 : XCircle}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user