fixed some ux components, added constants
This commit is contained in:
1 parent
6da59f42d9
commit
5073166931
30 files changed
+409
-425
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { useState, useCallback, useMemo } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ColumnMeta, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
@@ -11,11 +12,12 @@ import { DeleteDialog } from "@/components/deleteDialog";
|
||||
|
||||
import { useCardPins, useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import type { CardPinOrder } from "@/features/cardPins/api/cardPinApi";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { getStatusLabel, getStatusOptions, isStatusValue, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Filter field IDs ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -26,56 +28,24 @@ const INITIAL_FILTERS: ActiveFilter[] = FILTER_IDS.map((fieldId) => ({ fieldId,
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function statusConfig(status: string): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
function statusConfig(status: string, t: TFunction): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
const key = status.trim().toLowerCase();
|
||||
if (PENDING_STATUSES.includes(key)) return { label: "Garaşylýar", variant: "warning", icon: AlertCircle };
|
||||
if (APPROVED_STATUSES.includes(key)) return { label: "Tassyklandy", variant: "success", icon: CheckCircle2 };
|
||||
if (REJECTED_STATUSES.includes(key)) return { label: "Ýatyryldy", variant: "error", icon: XCircle };
|
||||
if (isStatusValue(key)) {
|
||||
return { label: getStatusLabel(key, t, "cardPin.status"), variant: STATUS_BADGE_VARIANTS[key], icon: STATUS_ICONS[key] };
|
||||
}
|
||||
return { label: status, variant: "default" };
|
||||
}
|
||||
|
||||
function StatusCell({ status }: { status: string }) {
|
||||
const cfg = statusConfig(status);
|
||||
const { t } = useTranslation();
|
||||
const cfg = statusConfig(status, t);
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
@@ -219,11 +189,7 @@ export default function CardPinsPage() {
|
||||
{
|
||||
id: "status",
|
||||
label: t("cardPin.filter.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: t("cardPin.status.pending", "Garaşylýar") },
|
||||
{ value: "approved", label: t("cardPin.status.approved", "Tassyklandy") },
|
||||
{ value: "rejected", label: t("cardPin.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
options: getStatusOptions(t, "cardPin.status"),
|
||||
},
|
||||
{
|
||||
id: "branch_id",
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useParams, useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useCardPin, useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Pencil, Trash2 } from "lucide-react";
|
||||
@@ -19,59 +19,31 @@ import {
|
||||
AlertDialogTrigger,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import { getStatusLabel, isStatusValue, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function statusConfig(status: string): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
function statusConfig(
|
||||
status: string,
|
||||
t: (key: string, fallback?: string) => string,
|
||||
): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
const key = status.trim().toLowerCase();
|
||||
if (PENDING_STATUSES.includes(key)) return { label: "Garaşylýar", variant: "warning", icon: AlertCircle };
|
||||
if (APPROVED_STATUSES.includes(key)) return { label: "Tassyklandy", variant: "success", icon: CheckCircle2 };
|
||||
if (REJECTED_STATUSES.includes(key)) return { label: "Ýatyryldy", variant: "error", icon: XCircle };
|
||||
if (isStatusValue(key)) {
|
||||
return { label: getStatusLabel(key, t, "cardPin.status"), variant: STATUS_BADGE_VARIANTS[key], icon: STATUS_ICONS[key] };
|
||||
}
|
||||
return { label: status, variant: "default" };
|
||||
}
|
||||
|
||||
function CardPinStatusBadge({ status }: { status: string }) {
|
||||
const cfg = statusConfig(status);
|
||||
const { t } = useTranslation();
|
||||
const cfg = statusConfig(status, (key, fallback) => t(key, fallback ?? key));
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useNavigate, Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ColumnMeta, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
@@ -17,74 +17,26 @@ import type { CardOrder } from "@/features/orderNewCard/api/orderNewCardApi";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { useCardTypes } from "@/features/cardTypes/hooks/useCardTypes";
|
||||
import { getStatusLabel, getStatusOptions, isStatusValue, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
const PER_PAGE = 25;
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function CardOrderStatusBadge({ status }: { status: string }) {
|
||||
const { t } = useTranslation();
|
||||
const key = (status || "").trim().toLowerCase();
|
||||
|
||||
let variant: StatusBadgeVariant = "default";
|
||||
let icon: React.ElementType | undefined;
|
||||
let label = status;
|
||||
|
||||
if (PENDING_STATUSES.includes(key)) {
|
||||
variant = "warning";
|
||||
icon = AlertCircle;
|
||||
label = t("cardOrder.status.pending", "Garaşylýar");
|
||||
} else if (APPROVED_STATUSES.includes(key)) {
|
||||
variant = "success";
|
||||
icon = CheckCircle2;
|
||||
label = t("cardOrder.status.approved", "Tassyklandy");
|
||||
} else if (REJECTED_STATUSES.includes(key)) {
|
||||
variant = "error";
|
||||
icon = XCircle;
|
||||
label = t("cardOrder.status.rejected", "Ýatyryldy");
|
||||
} else {
|
||||
label = t(`cardOrder.status.${status}`, status);
|
||||
}
|
||||
const isKnown = isStatusValue(key);
|
||||
const variant: StatusBadgeVariant = isKnown ? STATUS_BADGE_VARIANTS[key] : "default";
|
||||
const icon = isKnown ? STATUS_ICONS[key] : undefined;
|
||||
const label = isKnown ? getStatusLabel(key, t, "cardOrder.status") : status;
|
||||
|
||||
return <StatusBadge label={label} variant={variant} icon={icon} />;
|
||||
}
|
||||
@@ -237,11 +189,7 @@ export default function CardOrdersPage() {
|
||||
{
|
||||
id: "status",
|
||||
label: t("cardOrder.filter.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: t("cardOrder.status.pending", "Garaşylýar") },
|
||||
{ value: "approved", label: t("cardOrder.status.approved", "Tassyklandy") },
|
||||
{ value: "rejected", label: t("cardOrder.status.rejected", "Ýatyryldy") },
|
||||
],
|
||||
options: getStatusOptions(t, "cardOrder.status"),
|
||||
},
|
||||
{
|
||||
id: "branch_id",
|
||||
|
||||
@@ -17,60 +17,32 @@ import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { useCardById, useDeleteCard } from "@/features/orderNewCard/hooks/useOrderNewCard";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { getStatusLabel, isStatusValue, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Status badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const PENDING_STATUSES = [
|
||||
"pending",
|
||||
"garaşylýar",
|
||||
"garaşilyar",
|
||||
"garasylýar",
|
||||
"garasilyar",
|
||||
"garasylyar",
|
||||
"kutilyor",
|
||||
"kutiliyor",
|
||||
"waiting",
|
||||
"beklemede",
|
||||
];
|
||||
const APPROVED_STATUSES = [
|
||||
"approved",
|
||||
"tassyklandy",
|
||||
"tassyklanan",
|
||||
"tassyklandy",
|
||||
"tassyklanyldy",
|
||||
"accepted",
|
||||
"confirmed",
|
||||
"success",
|
||||
"completed",
|
||||
"approve",
|
||||
];
|
||||
const REJECTED_STATUSES = [
|
||||
"rejected",
|
||||
"reject",
|
||||
"ret",
|
||||
"ýatyryldy",
|
||||
"yatyryldy",
|
||||
"canceled",
|
||||
"cancelled",
|
||||
"cancelled",
|
||||
"declined",
|
||||
"failed",
|
||||
"error",
|
||||
"reject",
|
||||
"red edildi",
|
||||
];
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function statusConfig(status: string): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
function statusConfig(
|
||||
status: string,
|
||||
t: (key: string, fallback?: string) => string,
|
||||
): { label: string; variant: StatusBadgeVariant; icon?: React.ElementType } {
|
||||
const key = status.trim().toLowerCase();
|
||||
if (PENDING_STATUSES.includes(key)) return { label: "Garaşylýar", variant: "warning", icon: AlertCircle };
|
||||
if (APPROVED_STATUSES.includes(key)) return { label: "Tassyklandy", variant: "success", icon: CheckCircle2 };
|
||||
if (REJECTED_STATUSES.includes(key)) return { label: "Ýatyryldy", variant: "error", icon: XCircle };
|
||||
if (isStatusValue(key)) {
|
||||
return { label: getStatusLabel(key, t, "cardOrder.status"), variant: STATUS_BADGE_VARIANTS[key], icon: STATUS_ICONS[key] };
|
||||
}
|
||||
return { label: status, variant: "default" };
|
||||
}
|
||||
|
||||
function CardOrderStatusBadge({ status }: { status: string }) {
|
||||
const cfg = statusConfig(status);
|
||||
const { t } = useTranslation();
|
||||
const cfg = statusConfig(status, (key, fallback) => t(key, fallback ?? key));
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AlertCircle, CheckCircle2, XCircle, Loader2 } from "lucide-react";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
@@ -12,20 +12,22 @@ import { TableActions } from "@/components/tableActions";
|
||||
import { useLoanOrderMobiles, useDeleteLoanOrderMobile } from "@/features/loanOrderMobiles/hooks/useLoanOrderMobiles";
|
||||
import type { LoanOrderMobile, LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { getStatusLabel, getStatusOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Status Badge (inline) ────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG = {
|
||||
GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle },
|
||||
KANAGATLANDYRYLAN: { label: "Kanagatlandyrylan", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 },
|
||||
RED_EDILDI: { label: "Red edildi", variant: "error" as StatusBadgeVariant, icon: XCircle },
|
||||
IŞLENÝÄR: { label: "Işlenýär", variant: "info" as StatusBadgeVariant, icon: Loader2 },
|
||||
} satisfies Record<LoanOrderMobileStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function LoanOrderStatusBadge({ status }: { status: LoanOrderMobileStatus }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<StatusBadge label={getStatusLabel(status, t, "loanOrderStatus")} variant={STATUS_BADGE_VARIANTS[status]} icon={STATUS_ICONS[status]} />
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Column IDs ────────────────────────────────────────────────────────────────
|
||||
@@ -36,7 +38,6 @@ const COLUMN_IDS = ["id", "loanType", "createdAt", "region", "branch", "firstNam
|
||||
|
||||
// ─── Filter options (Internal keys/values) ───────────────────────────────────
|
||||
const REGION_OPTIONS = ["Balkan", "Ahal", "Daşoguz", "Lebap", "Mary", "Aşgabat"];
|
||||
const STATUS_OPTIONS: LoanOrderMobileStatus[] = ["GARAŞYLÝAR", "KANAGATLANDYRYLAN", "RED_EDILDI", "IŞLENÝÄR"];
|
||||
|
||||
// ─── Page Component ────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -193,7 +194,7 @@ export default function LoanOrderMobilesPage() {
|
||||
{
|
||||
id: "status",
|
||||
label: t("loanOrderMobiles.filters.status", "STATUS"),
|
||||
options: STATUS_OPTIONS.map((v) => ({ value: v, label: t(`loanOrderStatus.${v}`) })),
|
||||
options: getStatusOptions(t, "loanOrderStatus"),
|
||||
},
|
||||
{
|
||||
id: "branch",
|
||||
|
||||
@@ -6,33 +6,26 @@ import { useLoanOrderMobileById, useDeleteLoanOrderMobile } from "@/features/loa
|
||||
import { CreditCardVisual } from "@/components/creditCardVisual";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import type { LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage, AuditLog, type AuditRowProps } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
import { getStatusLabel, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_VARIANT: Record<LoanOrderMobileStatus, StatusBadgeVariant> = {
|
||||
GARAŞYLÝAR: "warning",
|
||||
KANAGATLANDYRYLAN: "success",
|
||||
RED_EDILDI: "error",
|
||||
IŞLENÝÄR: "warning",
|
||||
};
|
||||
|
||||
const STATUS_ICON: Record<LoanOrderMobileStatus, React.ElementType> = {
|
||||
GARAŞYLÝAR: AlertCircle,
|
||||
KANAGATLANDYRYLAN: CheckCircle2,
|
||||
RED_EDILDI: XCircle,
|
||||
IŞLENÝÄR: AlertCircle,
|
||||
const STATUS_ICON: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) {
|
||||
const { t } = useTranslation();
|
||||
const variant = STATUS_VARIANT[status];
|
||||
const variant = STATUS_BADGE_VARIANTS[status];
|
||||
const Icon = STATUS_ICON[status];
|
||||
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(`loanOrderStatus.${status}`)} variant={variant} icon={Icon} />;
|
||||
return <StatusBadge label={getStatusLabel(status, t, "loanOrderStatus")} variant={variant} icon={Icon} />;
|
||||
}
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -4,34 +4,27 @@ import { useTranslation } from "react-i18next";
|
||||
import { Trash2, Pencil } from "lucide-react";
|
||||
import { useLoanOrderById, useDeleteLoanOrder } from "@/features/loanOrders/hooks/useLoanOrders";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import type { LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { BentoGrid, BentoCard, InfoRow, PassportImage, AuditLog, type AuditRowProps } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
import { getStatusLabel, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Status config ────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_VARIANT: Record<LoanOrderStatus, StatusBadgeVariant> = {
|
||||
GARAŞYLÝAR: "warning",
|
||||
KANAGATLANDYRYLAN: "success",
|
||||
RED_EDILDI: "error",
|
||||
IŞLENÝÄR: "warning",
|
||||
};
|
||||
|
||||
const STATUS_ICON: Record<LoanOrderStatus, React.ElementType> = {
|
||||
GARAŞYLÝAR: AlertCircle,
|
||||
KANAGATLANDYRYLAN: CheckCircle2,
|
||||
RED_EDILDI: XCircle,
|
||||
IŞLENÝÄR: AlertCircle,
|
||||
const STATUS_ICON: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderStatus }) {
|
||||
const { t } = useTranslation();
|
||||
const variant = STATUS_VARIANT[status];
|
||||
const variant = STATUS_BADGE_VARIANTS[status];
|
||||
const Icon = STATUS_ICON[status];
|
||||
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(`loanOrderStatus.${status}`)} variant={variant} icon={Icon} />;
|
||||
return <StatusBadge label={getStatusLabel(status, t, "loanOrderStatus")} variant={variant} icon={Icon} />;
|
||||
}
|
||||
|
||||
// ─── Skeleton ─────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AlertCircle, CheckCircle2, XCircle, Loader2 } from "lucide-react";
|
||||
import { AlertCircle, CheckCircle2, XCircle, CheckCheck } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
@@ -9,24 +9,26 @@ import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/compone
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { useLoanOrders, useDeleteLoanOrder } from "@/features/loanOrders/hooks/useLoanOrders";
|
||||
import type { LoanOrder, LoanOrderStatus } from "@/features/loanOrders/api/loanOrdersApi";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { getStatusLabel, getStatusOptions, STATUS_BADGE_VARIANTS, type StatusValue } from "@/constants";
|
||||
|
||||
// ─── Status Badge (inline) ────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG = {
|
||||
GARAŞYLÝAR: { label: "Garaşylýar", variant: "warning" as StatusBadgeVariant, icon: AlertCircle },
|
||||
KANAGATLANDYRYLAN: { label: "Kanagatlandyrylan", variant: "success" as StatusBadgeVariant, icon: CheckCircle2 },
|
||||
RED_EDILDI: { label: "Red edildi", variant: "error" as StatusBadgeVariant, icon: XCircle },
|
||||
IŞLENÝÄR: { label: "Işlenýär", variant: "info" as StatusBadgeVariant, icon: Loader2 },
|
||||
} satisfies Record<LoanOrderStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>;
|
||||
const STATUS_ICONS: Record<StatusValue, React.ElementType> = {
|
||||
pending: AlertCircle,
|
||||
approved: CheckCircle2,
|
||||
rejected: XCircle,
|
||||
completed: CheckCheck,
|
||||
};
|
||||
|
||||
function LoanOrderStatusBadge({ status }: { status: LoanOrderStatus }) {
|
||||
const cfg = STATUS_CONFIG[status];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>;
|
||||
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />;
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<StatusBadge label={getStatusLabel(status, t, "loanOrderStatus")} variant={STATUS_BADGE_VARIANTS[status]} icon={STATUS_ICONS[status]} />
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Column meta for toggle dropdown ─────────────────────────────────────────
|
||||
@@ -44,13 +46,6 @@ const REGION_OPTIONS = [
|
||||
{ value: "Aşgabat", label: "Aşgabat" },
|
||||
];
|
||||
|
||||
const STATUS_OPTIONS: { value: LoanOrderStatus; label: string }[] = [
|
||||
{ value: "GARAŞYLÝAR", label: "Garaşylýar" },
|
||||
{ value: "KANAGATLANDYRYLAN", label: "Kanagatlandyrylan" },
|
||||
{ value: "RED_EDILDI", label: "Red edildi" },
|
||||
{ value: "IŞLENÝÄR", label: "Işlenýär" },
|
||||
];
|
||||
|
||||
// ─── Page Component ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function LoanOrdersPage() {
|
||||
@@ -201,7 +196,7 @@ export default function LoanOrdersPage() {
|
||||
{
|
||||
id: "status",
|
||||
label: t("Status", "STATUS"),
|
||||
options: STATUS_OPTIONS,
|
||||
options: getStatusOptions(t, "loanOrderStatus"),
|
||||
},
|
||||
{
|
||||
id: "branch",
|
||||
|
||||
@@ -9,12 +9,13 @@ import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/compone
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { useLoanPaidOffLetters, useDeleteLoanPaidOffLetter } from "@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters";
|
||||
import type { LoanPaidOffLetter } from "@/features/loanPaidOffLetters/api/loanPaidOffLettersApi";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { useBranches } from "@/features/branches/hooks/useBranches";
|
||||
import { useDistricts } from "@/features/districts/hooks/useDistricts";
|
||||
import { getStatusOptions, STATUS_BADGE_VARIANTS } from "@/constants";
|
||||
|
||||
// ─── Column IDs ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -29,12 +30,6 @@ const INITIAL_FILTERS: ActiveFilter[] = FILTER_IDS.map((fieldId) => ({ fieldId,
|
||||
|
||||
// ─── Status badge helpers ──────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_VARIANT: Record<string, StatusBadgeVariant> = {
|
||||
pending: "warning",
|
||||
approved: "success",
|
||||
rejected: "error",
|
||||
};
|
||||
|
||||
// ─── Empty state component ─────────────────────────────────────────────────────
|
||||
|
||||
function EmptyState({ onCreate }: { onCreate: () => void }) {
|
||||
@@ -107,11 +102,7 @@ export default function LoanPaidOffLettersPage() {
|
||||
{
|
||||
id: "status",
|
||||
label: t("loanPaidOffLetters.filters.status", "Status"),
|
||||
options: [
|
||||
{ value: "pending", label: t("loanPaidOffLetters.status.pending", "Pending") },
|
||||
{ value: "approved", label: t("loanPaidOffLetters.status.approved", "Approved") },
|
||||
{ value: "rejected", label: t("loanPaidOffLetters.status.rejected", "Rejected") },
|
||||
],
|
||||
options: getStatusOptions(t, "loanPaidOffLetters.status"),
|
||||
},
|
||||
{
|
||||
id: "passport_id",
|
||||
@@ -202,7 +193,9 @@ export default function LoanPaidOffLettersPage() {
|
||||
header: t("loanPaidOffLetters.columns.status", "STATUS"),
|
||||
cell: ({ row }) => {
|
||||
const status = row.original.status;
|
||||
return <StatusBadge label={t(`loanPaidOffLetters.status.${status}`, status)} variant={STATUS_VARIANT[status] ?? "default"} />;
|
||||
return (
|
||||
<StatusBadge label={t(`loanPaidOffLetters.status.${status}`, status)} variant={STATUS_BADGE_VARIANTS[status] ?? "default"} />
|
||||
);
|
||||
},
|
||||
size: 120,
|
||||
},
|
||||
|
||||
@@ -3,17 +3,11 @@ import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Trash2, Pencil } from "lucide-react";
|
||||
import { useLoanPaidOffLetterById, useDeleteLoanPaidOffLetter } from "@/features/loanPaidOffLetters/hooks/useLoanPaidOffLetters";
|
||||
import type { StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { StatusBadge } from "@/components/ui/statusBadge";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
|
||||
const STATUS_VARIANT: Record<string, StatusBadgeVariant> = {
|
||||
pending: "warning",
|
||||
approved: "success",
|
||||
rejected: "error",
|
||||
};
|
||||
import { STATUS_BADGE_VARIANTS } from "@/constants";
|
||||
|
||||
function formatDate(value: string | null | undefined): string {
|
||||
if (!value) return "—";
|
||||
@@ -95,7 +89,7 @@ export default function LoanPaidOffLettersViewPage() {
|
||||
<InfoRow label={t("loanPaidOffLetters.fields.status", "Status")}>
|
||||
<StatusBadge
|
||||
label={t(`loanPaidOffLetters.status.${record.status}`, record.status)}
|
||||
variant={STATUS_VARIANT[record.status] ?? "default"}
|
||||
variant={STATUS_BADGE_VARIANTS[record.status] ?? "default"}
|
||||
/>
|
||||
</InfoRow>
|
||||
<InfoRow label={t("loanPaidOffLetters.fields.createdAt", "Döredilen wagty")} value={formatDate(record.createdAt)} />
|
||||
|
||||
@@ -27,7 +27,7 @@ export function CardReasonsListPage() {
|
||||
const [search, setSearch] = useState("");
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([{ fieldId: "isActive", value: "" }]);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "name", "value", "description", "isActive", "actions"]);
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>(["id", "name", "price", "notes", "isActive", "actions"]);
|
||||
|
||||
// ── Delete dialog ────────────────────────────────────────────────────────────
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
|
||||
@@ -60,11 +60,7 @@ function useLoanTypeColumns(
|
||||
header: t("loanTypes.columns.isActive", "IŞJEŇ"),
|
||||
size: 80,
|
||||
cell: ({ row }) =>
|
||||
row.original.active ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-muted-foreground" />
|
||||
),
|
||||
row.original.active ? <CheckCircle2 size={18} className="text-emerald-500" /> : <XCircle size={18} className="text-red-500" />,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
|
||||
Reference in new issue
Block a user