From c6462b99561c13e5c6e549cccd7d834d6ae0040e Mon Sep 17 00:00:00 2001 From: "@jcarymuhammedow" Date: Fri, 8 May 2026 16:40:10 +0500 Subject: [PATCH] started refactor --- .../cardPins/components/cardPinForm.tsx | 2 +- .../components/loanOrderStatusBadge.tsx | 39 --- .../components/orderNewCardTable.tsx | 155 -------- .../components/sberPaymentsForm.tsx | 2 +- .../sberPayments/components/statusBadge.tsx | 59 ---- .../components/intlPaymentForm.tsx | 2 +- src/pages/cardDepartment/cardPins/index.tsx | 58 ++- .../cardDepartment/cardPinsView/index.tsx | 43 ++- .../cardDepartment/orderNewCard/index.tsx | 200 ++++++++--- .../sberPayments/index.tsx | 65 +++- .../sberPaymentsView/index.tsx | 331 ++++++++++++------ .../visaMasterPayments/index.tsx | 40 ++- .../visaMasterPaymentsView/index.tsx | 21 +- .../loanDepartment/loanOrderMobile/index.tsx | 22 +- .../loanOrderMobileView/index.tsx | 36 +- .../loanDepartment/loanOrderView/index.tsx | 37 +- src/pages/loanDepartment/loanOrders/index.tsx | 54 +-- 17 files changed, 634 insertions(+), 532 deletions(-) delete mode 100644 src/features/loanOrders/components/loanOrderStatusBadge.tsx delete mode 100644 src/features/orderNewCard/components/orderNewCardTable.tsx delete mode 100644 src/features/sberPayments/components/statusBadge.tsx diff --git a/src/features/cardPins/components/cardPinForm.tsx b/src/features/cardPins/components/cardPinForm.tsx index 8c5fd5d..464dcb7 100644 --- a/src/features/cardPins/components/cardPinForm.tsx +++ b/src/features/cardPins/components/cardPinForm.tsx @@ -193,7 +193,7 @@ export function CardPinForm({ mode, initialData, onSubmit, isSubmitting }: CardP : t('cardPin.editBtn', 'Kart pin bukja redaktirläň') return ( -
+

{title}

{/* ── Status & Note ────────────────────────────────────────────────── */} diff --git a/src/features/loanOrders/components/loanOrderStatusBadge.tsx b/src/features/loanOrders/components/loanOrderStatusBadge.tsx deleted file mode 100644 index 2dc5955..0000000 --- a/src/features/loanOrders/components/loanOrderStatusBadge.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useTranslation } from 'react-i18next' -import { AlertCircle, CheckCircle2, XCircle, Loader2 } from 'lucide-react' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import type { LoanOrderStatus } from '../api/loanOrdersApi' - -interface LoanOrderStatusConfig { - labelKey: string - variant: StatusBadgeVariant - icon: React.ElementType -} - -const STATUS_CONFIG: Record = { - GARAŞYLÝAR: { labelKey: 'loanOrderStatus.GARAŞYLÝAR', variant: 'warning', icon: AlertCircle }, - KANAGATLANDYRYLAN: { labelKey: 'loanOrderStatus.KANAGATLANDYRYLAN', variant: 'success', icon: CheckCircle2 }, - RED_EDILDI: { labelKey: 'loanOrderStatus.RED_EDILDI', variant: 'error', icon: XCircle }, - IŞLENÝÄR: { labelKey: 'loanOrderStatus.IŞLENÝÄR', variant: 'info', icon: Loader2 }, -} - -interface LoanOrderStatusBadgeProps { - status: LoanOrderStatus -} - -export function LoanOrderStatusBadge({ status }: LoanOrderStatusBadgeProps) { - const { t } = useTranslation() - const config = STATUS_CONFIG[status] - - if (!config) { - console.warn(`[LoanOrderStatusBadge] Unknown status: ${status}`); - return ( - - ) - } - - return -} \ No newline at end of file diff --git a/src/features/orderNewCard/components/orderNewCardTable.tsx b/src/features/orderNewCard/components/orderNewCardTable.tsx deleted file mode 100644 index 66f803a..0000000 --- a/src/features/orderNewCard/components/orderNewCardTable.tsx +++ /dev/null @@ -1,155 +0,0 @@ -import { Link } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import type { ColumnDef } from '@/components/dataTable' -import type { CardOrderListItem, CardOrderStatus } from '../api/orderNewCardApi' - -// ─── Status badge ───────────────────────────────────────────────────────────── - -const STATUS_CONFIG: Record< - CardOrderStatus, - { label: string; className: string } -> = { - PENDING: { - label: 'Garaşylýar', - className: - 'inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold tracking-wide ' + - 'bg-amber-500/10 text-amber-400 border border-amber-500/20', - }, - APPROVED: { - label: 'Tassyklandy', - className: - 'inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold tracking-wide ' + - 'bg-emerald-500/10 text-emerald-400 border border-emerald-500/20', - }, - REJECTED: { - label: 'Ýatyryldy', - className: - 'inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-[11px] font-bold tracking-wide ' + - 'bg-red-500/10 text-red-400 border border-red-500/20', - }, -} - -function StatusBadge({ status }: { status: CardOrderStatus }) { - const cfg = STATUS_CONFIG[status] - const icons: Record = { - PENDING: '⏳', - APPROVED: '✓', - REJECTED: '✕', - } - return ( - - {icons[status]} - {cfg.label} - - ) -} - -// ─── Coloured text helper ───────────────────────────────────────────────────── - -function HighlightText({ - value, - variant, -}: { - value: string - variant: 'teal' | 'cyan' | 'muted' -}) { - const cls = - variant === 'teal' ? 'text-teal-400 font-semibold' : - variant === 'cyan' ? 'text-cyan-400 font-semibold' : - 'text-muted-foreground' - return {value} -} - -// ─── useCardOrderColumns ────────────────────────────────────────────────────── - -export function useCardOrderColumns(): ColumnDef[] { - const { t } = useTranslation() - - return [ - { - accessorKey: 'id', - header: t('cardOrder.col.id', 'ID'), - cell: ({ row }) => ( - - {row.original.id} - - ), - size: 130, - }, - { - accessorKey: 'issuanceReasonName', - header: t('cardOrder.col.reason', 'Sebäp'), - cell: ({ row }) => ( - - {row.original.issuanceReasonName} - - ), - }, - { - accessorKey: 'createdAt', - header: t('cardOrder.col.createdAt', 'Döredilen wagty'), - cell: ({ row }) => ( - - {row.original.createdAt} - - ), - size: 160, - }, - { - accessorKey: 'cardTypeName', - header: t('cardOrder.col.cardType', 'Görnüşi'), - cell: ({ row }) => { - const isAltyn = row.original.cardTypeName === 'Altyn Asyr' - return ( - - ) - }, - }, - { - accessorKey: 'provinceName', - header: t('cardOrder.col.province', 'Welaýat'), - cell: ({ row }) => ( - {row.original.provinceName} - ), - }, - { - accessorKey: 'branchName', - header: t('cardOrder.col.branch', 'Şahamça'), - cell: ({ row }) => { - const specialBranches = [ - 'Köpetdag', 'Türkmenabat', 'Türkmenbaşy', - 'Seýdi', 'Çandybil', 'Balkan', 'Baş bank', - ] - const isSpecial = specialBranches.includes(row.original.branchName) - return ( - - ) - }, - }, - { - id: 'fullName', - header: t('cardOrder.col.name', 'Ady'), - cell: ({ row }) => ( - - {row.original.lastName} {row.original.firstName} - - ), - }, - { - accessorKey: 'status', - header: t('cardOrder.col.status', 'Status'), - cell: ({ row }) => , - size: 130, - }, - - ] -} \ No newline at end of file diff --git a/src/features/sberPayments/components/sberPaymentsForm.tsx b/src/features/sberPayments/components/sberPaymentsForm.tsx index ec02efe..280f60c 100644 --- a/src/features/sberPayments/components/sberPaymentsForm.tsx +++ b/src/features/sberPayments/components/sberPaymentsForm.tsx @@ -149,7 +149,7 @@ export function SberPaymentForm({ mode, initialData, orderId }: SberPaymentFormP } return ( -
+
{/* Status Section */}

Status

diff --git a/src/features/sberPayments/components/statusBadge.tsx b/src/features/sberPayments/components/statusBadge.tsx deleted file mode 100644 index 45bf1e8..0000000 --- a/src/features/sberPayments/components/statusBadge.tsx +++ /dev/null @@ -1,59 +0,0 @@ -import { cn } from '@/lib/utils' -import type { PaymentStatus, PaymentPaidStatus } from '@/features/sberPayments/api/sberPaymentsApi' - -interface StatusBadgeProps { - status: PaymentStatus - className?: string -} - -const statusConfig: Record = { - GARASYLYYAR: { - label: 'Garasylyyar', - className: 'bg-[oklch(0.75_0.18_85)] text-[oklch(0.20_0_0)]', - }, - KANAGATLANDYRYLAN: { - label: 'Kanagatlandyrylan', - className: 'bg-[oklch(0.72_0.19_160)] text-[oklch(0.15_0_0)]', - }, - RET_EDILEN: { - label: 'Ret edilen', - className: 'bg-destructive text-destructive-foreground', - }, -} - -export function StatusBadge({ status, className }: StatusBadgeProps) { - const config = statusConfig[status] - - return ( - - {config.label} - - ) -} - -interface PaidStatusBadgeProps { - status: PaymentPaidStatus - className?: string -} - -export function PaidStatusBadge({ status, className }: PaidStatusBadgeProps) { - const isPaid = status === 'Tolendi' - - return ( - - {status} - - ) -} diff --git a/src/features/visaMasterPayments/components/intlPaymentForm.tsx b/src/features/visaMasterPayments/components/intlPaymentForm.tsx index 18e6af5..aa09de8 100644 --- a/src/features/visaMasterPayments/components/intlPaymentForm.tsx +++ b/src/features/visaMasterPayments/components/intlPaymentForm.tsx @@ -230,7 +230,7 @@ export function IntlPaymentForm({ mode, initialData, onSubmit, isSubmitting }: I : t('intlPayment.editBtn', 'Visa/Master tölegler (talyplar üçin) redaktirläň') return ( -
+

{title}

{/* ── Status ────────────────────────────────────────────────────────── */} diff --git a/src/pages/cardDepartment/cardPins/index.tsx b/src/pages/cardDepartment/cardPins/index.tsx index 244dbe1..1448357 100644 --- a/src/pages/cardDepartment/cardPins/index.tsx +++ b/src/pages/cardDepartment/cardPins/index.tsx @@ -11,7 +11,7 @@ import type { CardPinStatus, } from "@/features/cardPins/api/cardPinApi"; import { Button } from "@/components/ui/button"; -import { Eye, Pencil, Trash2 } from "lucide-react"; +import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle } from "lucide-react"; import { AlertDialog, AlertDialogAction, @@ -22,38 +22,36 @@ import { AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; -import { cn } from "@/lib/utils"; // ─── Status Badge ───────────────────────────────────────────────────────────── -const STATUS_MAP: Record = - { - pending: { - label: "Garaşylýar", - className: "bg-yellow-500/20 text-yellow-400 border-yellow-500/30", - }, - approved: { - label: "Tassyklandy", - className: "bg-green-500/20 text-green-400 border-green-500/30", - }, - rejected: { - label: "Ret edildi", - className: "bg-red-500/20 text-red-400 border-red-500/30", - }, - }; +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -function StatusBadge({ status }: { status: CardPinStatus }) { - const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending; - return ( - - {cfg.label} - - ); + +// ─── Status badge ───────────────────────────────────────────────────────────── + +const STATUS_CONFIG = { + pending: { + label: 'Garaşylýar', + variant: 'warning' as StatusBadgeVariant, + icon: AlertCircle, + }, + approved: { + label: 'Tassyklandy', + variant: 'success' as StatusBadgeVariant, + icon: CheckCircle2, + }, + rejected: { + label: 'Ýatyryldy', + variant: 'error' as StatusBadgeVariant, + icon: XCircle, + }, +} satisfies Record + +function CardPinStatusStatusBadge({ status }: { status: CardPinStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return } // ─── Page ───────────────────────────────────────────────────────────────────── @@ -139,7 +137,7 @@ export default function CardPinsPage() { { accessorKey: "status", header: t("cardPin.status", "Status"), - cell: ({ row }) => , + cell: ({ row }) => , }, { id: "actions", diff --git a/src/pages/cardDepartment/cardPinsView/index.tsx b/src/pages/cardDepartment/cardPinsView/index.tsx index be93ccc..8680d52 100644 --- a/src/pages/cardDepartment/cardPinsView/index.tsx +++ b/src/pages/cardDepartment/cardPinsView/index.tsx @@ -16,24 +16,33 @@ import { AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog' -import { cn } from '@/lib/utils' +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' +import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' -// ─── Status Badge ───────────────────────────────────────────────────────────── +// ─── Status badge ───────────────────────────────────────────────────────────── -const STATUS_MAP: Record = { - pending: { label: 'Garaşylýar', className: 'bg-yellow-500/20 text-yellow-500 border-yellow-500/30' }, - approved: { label: 'Tassyklandy', className: 'bg-green-500/20 text-green-500 border-green-500/30' }, - rejected: { label: 'Ret edildi', className: 'bg-red-500/20 text-red-500 border-red-500/30' }, -} +const STATUS_CONFIG = { + pending: { + label: 'Garaşylýar', + variant: 'warning' as StatusBadgeVariant, + icon: AlertCircle, + }, + approved: { + label: 'Tassyklandy', + variant: 'success' as StatusBadgeVariant, + icon: CheckCircle2, + }, + rejected: { + label: 'Ýatyryldy', + variant: 'error' as StatusBadgeVariant, + icon: XCircle, + }, +} satisfies Record -function StatusBadge({ status }: { status: CardPinStatus }) { - const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending - return ( - - - {cfg.label} - - ) +function CardPinStatusBadge({ status }: { status: CardPinStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return } // ─── Field row ──────────────────────────────────────────────────────────────── @@ -102,7 +111,7 @@ export default function CardPinViewPage() { } return ( -
+
{/* Header */}

@@ -157,7 +166,7 @@ export default function CardPinViewPage() { {data.created_at} - + {data.note || '—'} diff --git a/src/pages/cardDepartment/orderNewCard/index.tsx b/src/pages/cardDepartment/orderNewCard/index.tsx index 8b4e483..f29f41c 100644 --- a/src/pages/cardDepartment/orderNewCard/index.tsx +++ b/src/pages/cardDepartment/orderNewCard/index.tsx @@ -1,22 +1,60 @@ import { useState, useMemo, useCallback } from 'react' -import { useNavigate } from 'react-router-dom' +import { useNavigate, Link } from 'react-router-dom' import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2 } from 'lucide-react' -import type { VisibilityState } from '@tanstack/react-table' +import { Eye, Pencil, Trash2, CheckCircle2, XCircle, AlertCircle } from 'lucide-react' +import type { ColumnDef, VisibilityState } from '@tanstack/react-table' import { DataTable } from '@/components/dataTable' -import { DataTableToolbar } from '@/components/dataTableToolbar' -import type { ActiveFilter, FilterField } from '@/components/dataTableToolbar' +import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar' import { useCardOrders, useDeleteCardOrder, useProvinces, useBranches, } from '@/features/orderNewCard/hooks/useOrderNewCard' -import { useCardOrderColumns } from '@/features/orderNewCard/components/orderNewCardTable' -import type { CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi' +import type { CardOrderListItem, CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi' +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -// ─── Column meta list (for toolbar toggle) ──────────────────────────────────── + +// ─── Status badge ───────────────────────────────────────────────────────────── + +const STATUS_CONFIG = { + PENDING: { + label: 'Garaşylýar', + variant: 'warning' as StatusBadgeVariant, + icon: AlertCircle, + }, + APPROVED: { + label: 'Tassyklandy', + variant: 'success' as StatusBadgeVariant, + icon: CheckCircle2, + }, + REJECTED: { + label: 'Ýatyryldy', + variant: 'error' as StatusBadgeVariant, + icon: XCircle, + }, +} satisfies Record + +function OrderNewCardStatusBadge({ status }: { status: CardOrderStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} + + + +// ─── Coloured text helper ───────────────────────────────────────────────────── + +function HighlightText({ value, variant }: { value: string; variant: 'teal' | 'cyan' | 'muted' }) { + const cls = + variant === 'teal' ? 'text-teal-400 font-semibold' : + variant === 'cyan' ? 'text-cyan-400 font-semibold' : + 'text-muted-foreground' + return {value} +} + +// ─── Column meta (toolbar toggle) ──────────────────────────────────────────── const COLUMN_META = [ { id: 'id', label: 'ID' }, @@ -29,13 +67,18 @@ const COLUMN_META = [ { id: 'status', label: 'Status' }, ] +const SPECIAL_BRANCHES = [ + 'Köpetdag', 'Türkmenabat', 'Türkmenbaşy', + 'Seýdi', 'Çandybil', 'Balkan', 'Baş bank', +] + const DEFAULT_ORDER = COLUMN_META.map((c) => c.id) // ─── CardOrdersPage ─────────────────────────────────────────────────────────── export default function CardOrdersPage() { - const { t } = useTranslation() - const navigate = useNavigate() + const { t } = useTranslation() + const navigate = useNavigate() const deleteMutation = useDeleteCardOrder() // ── State ────────────────────────────────────────────────────────────────── @@ -55,7 +98,7 @@ export default function CardOrdersPage() { const { data: provincesData } = useProvinces() const { data: branchesData } = useBranches(provinceId ? Number(provinceId) : undefined) - // ── Data ─────────────────────────────────────────────────────────────────── + // ── Query params ─────────────────────────────────────────────────────────── const queryParams = useMemo(() => { const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])) return { @@ -73,12 +116,11 @@ export default function CardOrdersPage() { // ── Handlers ─────────────────────────────────────────────────────────────── const handleFilterChange = useCallback((fieldId: string, value: string) => { setActiveFilters((prev) => { - const newFilters = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) - // Reset branch if province changes + const updated = prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)) if (fieldId === 'provinceId') { - return newFilters.map((f) => (f.fieldId === 'branchId' ? { ...f, value: '' } : f)) + return updated.map((f) => (f.fieldId === 'branchId' ? { ...f, value: '' } : f)) } - return newFilters + return updated }) setPage(1) }, []) @@ -97,15 +139,83 @@ export default function CardOrdersPage() { ) // ── Columns ──────────────────────────────────────────────────────────────── - const baseColumns = useCardOrderColumns() - const columns = useMemo( + const columns = useMemo[]>( () => [ - ...baseColumns, + { + accessorKey: 'id', + header: t('cardOrder.col.id', 'ID'), + cell: ({ row }) => ( + + {row.original.id} + + ), + size: 130, + }, + { + accessorKey: 'issuanceReasonName', + header: t('cardOrder.col.reason', 'Sebäp'), + cell: ({ row }) => ( + {row.original.issuanceReasonName} + ), + }, + { + accessorKey: 'createdAt', + header: t('cardOrder.col.createdAt', 'Döredilen wagty'), + cell: ({ row }) => ( + {row.original.createdAt} + ), + size: 160, + }, + { + accessorKey: 'cardTypeName', + header: t('cardOrder.col.cardType', 'Görnüşi'), + cell: ({ row }) => ( + + ), + }, + { + accessorKey: 'provinceName', + header: t('cardOrder.col.province', 'Welaýat'), + cell: ({ row }) => ( + {row.original.provinceName} + ), + }, + { + accessorKey: 'branchName', + header: t('cardOrder.col.branch', 'Şahamça'), + cell: ({ row }) => ( + + ), + }, + { + id: 'fullName', + header: t('cardOrder.col.name', 'Ady'), + cell: ({ row }) => ( + + {row.original.lastName} {row.original.firstName} + + ), + }, + { + accessorKey: 'status', + header: t('cardOrder.col.status', 'Status'), + cell: ({ row }) => , + size: 130, + }, { id: 'actions', header: '', enableHiding: false, - cell: ({ row }: { row: any }) => ( + cell: ({ row }) => (
), - cell: ({ row }) => , + cell: ({ row }) => , }, { accessorKey: 'paidStatus', header: 'Tolenen (sul ay)', - cell: ({ row }) => , + cell: ({ row }) => , }, { id: 'actions', @@ -298,15 +346,6 @@ export default function SberPaymentsListPage() { totalCount={data?.pagination.totalCount ?? 0} onPageChange={setPage} /> - - {/* Pagination Info */} -
- - {data?.pagination.currentPage && data?.pagination.perPage && data?.pagination.totalCount - ? `${(data.pagination.currentPage - 1) * data.pagination.perPage + 1}-${Math.min(data.pagination.currentPage * data.pagination.perPage, data.pagination.totalCount)} of ${data.pagination.totalCount}` - : ''} - -
) } diff --git a/src/pages/internationalPayments/sberPaymentsView/index.tsx b/src/pages/internationalPayments/sberPaymentsView/index.tsx index 1eb8c8b..a5f8365 100644 --- a/src/pages/internationalPayments/sberPaymentsView/index.tsx +++ b/src/pages/internationalPayments/sberPaymentsView/index.tsx @@ -1,69 +1,147 @@ +import { format } from "date-fns"; +import { + Trash2, + Edit, + Search, + Download, + Clock, + XCircle, + CheckCircle2, + AlertCircle, +} from "lucide-react"; -import { format } from 'date-fns' -import { Trash2, Edit, Search, Download, Clock } from 'lucide-react' - -import { useSberPaymentOrder, useDeleteSberPayment } from '@/features/sberPayments/hooks/useSberPayments' -import { StatusBadge, PaidStatusBadge } from '@/features/sberPayments/components/statusBadge' -import { Button } from '@/components/ui/button' -import { Spinner } from '@/components/ui/spinner' -import { cn } from '@/lib/utils' +import { + useSberPaymentOrder, + useDeleteSberPayment, +} from "@/features/sberPayments/hooks/useSberPayments"; +import type { + PaymentPaidStatus, + PaymentStatus, +} from "@/features/sberPayments/api/sberPaymentsApi"; +import { Button } from "@/components/ui/button"; +import { Spinner } from "@/components/ui/spinner"; +import { cn } from "@/lib/utils"; import { useParams, useNavigate } from "react-router-dom"; +import { + StatusBadge, + type StatusBadgeVariant, +} from "@/components/ui/statusBadge"; +const STATUS_CONFIG = { + GARASYLYYAR: { + label: "Garaşylýar", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, + }, + KANAGATLANDYRYLAN: { + label: "Tassyklandy", + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, + }, + RET_EDILEN: { + label: "Ýatyryldy", + variant: "error" as StatusBadgeVariant, + icon: XCircle, + }, +} satisfies Record< + PaymentStatus, + { label: string; variant: StatusBadgeVariant; icon: React.ElementType } +>; + +const PAID_STATUS_CONFIG = { + Tolenmedik: { + label: "Tölmedi", + variant: "error" as StatusBadgeVariant, + icon: XCircle, + }, + Tolendi: { + label: "Tölendi", + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, + }, +} satisfies Record< + PaymentPaidStatus, + { label: string; variant: StatusBadgeVariant; icon: React.ElementType } +>; + +function PaymentPaidStatusBadge({ status }: { status: PaymentPaidStatus }) { + const cfg = PAID_STATUS_CONFIG[status]; + if (!cfg) + return ( + {String(status)} + ); + return ( + + ); +} + +function PaymentStatusBadge({ status }: { status: PaymentStatus }) { + const cfg = STATUS_CONFIG[status]; + if (!cfg) + return ( + {String(status)} + ); + return ( + + ); +} // ─── Info Row Component ─────────────────────────────────────────────────────── -function InfoRow({ - label, - value, - highlight = false -}: { - label: string - value: React.ReactNode - highlight?: boolean +function InfoRow({ + label, + value, + highlight = false, +}: { + label: string; + value: React.ReactNode; + highlight?: boolean; }) { return (
- {label} - - {value || '—'} + + {label} + + + {value || "—"}
- ) + ); } // ─── Section Component ──────────────────────────────────────────────────────── -function Section({ - title, - children, - className -}: { - title: string - children: React.ReactNode - className?: string +function Section({ + title, + children, + className, +}: { + title: string; + children: React.ReactNode; + className?: string; }) { return ( -
+

{title}

-
- {children} -
+
{children}
- ) + ); } // ─── Document Item Component ────────────────────────────────────────────────── -function DocumentItem({ - label, - fileName, - fileUrl -}: { - label: string - fileName: string | null - fileUrl: string | null +function DocumentItem({ + label, + fileName, + fileUrl, +}: { + label: string; + fileName: string | null; + fileUrl: string | null; }) { return (
@@ -88,47 +166,51 @@ function DocumentItem({ )}
- ) + ); } // ─── View Page Component ────────────────────────────────────────────────────── export default function SberPaymentViewPage() { - const params = useParams() - const navigate = useNavigate() - const id = params.id as string - - const { data: order, isLoading } = useSberPaymentOrder(id) - const deleteMutation = useDeleteSberPayment() - + const params = useParams(); + const navigate = useNavigate(); + const id = params.id as string; + + const { data: order, isLoading } = useSberPaymentOrder(id); + const deleteMutation = useDeleteSberPayment(); + const handleDelete = async () => { - if (confirm('Bu tolegi pozmak isleyanizmi?')) { - await deleteMutation.mutateAsync(id) - navigate('/sber-payments') + if (confirm("Bu tolegi pozmak isleyanizmi?")) { + await deleteMutation.mutateAsync(id); + navigate("/sber-payments"); } - } - + }; + if (isLoading) { return (
- ) + ); } - + if (!order) { return (

Toleg tapylmady

-
- ) + ); } - + return ( -
+
{/* Header Actions */}
- + {/* Status Section */}
- } /> - } /> + } + /> + } + />
- + {/* Location Section */}
@@ -165,7 +253,7 @@ export default function SberPaymentViewPage() {
- + {/* Personal Info Section */}
@@ -176,17 +264,20 @@ export default function SberPaymentViewPage() {
- + {/* Payment Info Section */}
- + -
- +
Tolegi kabul edijinin maglumatlary @@ -201,13 +292,15 @@ export default function SberPaymentViewPage() {

{order.passportNumber}

- Ady Familiyasy Atasynyn ady + + Ady Familiyasy Atasynyn ady +

{order.fullName}

- + {/* Documents - Accepted */}

@@ -224,39 +317,43 @@ export default function SberPaymentViewPage() { ))}

- + {/* Documents - Sent */}

Ugradyjy boyunca resminamalary

- {order.documents?.slice(6).map((doc) => ( - - )) || ( + {order.documents + ?.slice(6) + .map((doc) => ( + + )) || (
Resminamalar yok
)}
- + {/* Payment History */}
-

Toleg taryhy

+

+ Toleg taryhy +

- +
@@ -266,28 +363,37 @@ export default function SberPaymentViewPage() { className="flex-1 bg-transparent text-sm placeholder:text-muted-foreground/50 focus:outline-none" />
- +
- +
-

Berlen kriteriyalara Toleg gabat gelmedi.

+

+ Berlen kriteriyalara Toleg gabat gelmedi. +

- +
- + {/* Activity Log */}
@@ -298,7 +404,7 @@ export default function SberPaymentViewPage() {
- +
{/* Table Header */}
@@ -309,27 +415,35 @@ export default function SberPaymentViewPage() { Analys statusy Sene
- + {/* Table Body */} {order.activityLog?.length ? ( order.activityLog.map((log) => ( -
- {log.id.split('-')[1] ?? '45384'} +
+ + {log.id.split("-")[1] ?? "45384"} + {log.analysisName} {log.createdBy} {log.target} - + {log.status} - {format(new Date(log.createdAt), 'dd/MM/yyyy, HH:mm:ss')} GMT+5 + {format(new Date(log.createdAt), "dd/MM/yyyy, HH:mm:ss")}{" "} + GMT+5
)) @@ -339,14 +453,7 @@ export default function SberPaymentViewPage() {
)}
- - {/* Pagination */} -
- Onki - 1-1 of 1 - Indiki -
- ) + ); } diff --git a/src/pages/internationalPayments/visaMasterPayments/index.tsx b/src/pages/internationalPayments/visaMasterPayments/index.tsx index 485faf9..44d26be 100644 --- a/src/pages/internationalPayments/visaMasterPayments/index.tsx +++ b/src/pages/internationalPayments/visaMasterPayments/index.tsx @@ -19,22 +19,32 @@ import { AlertDialogTitle, } from '@/components/ui/alert-dialog' import { cn } from '@/lib/utils' +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' +import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' +// ─── Status badge ───────────────────────────────────────────────────────────── -// ─── Status Badge ───────────────────────────────────────────────────────────── +const STATUS_CONFIG = { + pending: { + label: 'Garaşylýar', + variant: 'warning' as StatusBadgeVariant, + icon: AlertCircle, + }, + approved: { + label: 'Tassyklandy', + variant: 'success' as StatusBadgeVariant, + icon: CheckCircle2, + }, + rejected: { + label: 'Ýatyryldy', + variant: 'error' as StatusBadgeVariant, + icon: XCircle, + }, +} satisfies Record -const STATUS_MAP: Record = { - pending: { label: 'Garaşylýar', className: 'bg-yellow-500/20 text-yellow-400 border-yellow-500/30' }, - approved: { label: 'Tassyklandy', className: 'bg-green-500/20 text-green-400 border-green-500/30' }, - rejected: { label: 'Ret edildi', className: 'bg-red-500/20 text-red-400 border-red-500/30' }, -} - -function StatusBadge({ status }: { status: IntlPaymentStatus }) { - const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending - return ( - - {cfg.label} - - ) +function IntlPaymentStatusStatusBadge({ status }: { status: IntlPaymentStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return } // ─── Month selector (AÝ TOLEGI) ─────────────────────────────────────────────── @@ -153,7 +163,7 @@ export default function IntlPaymentsPage() { { accessorKey: 'status', header: t('intlPayment.status', 'Status'), - cell: ({ row }) => , + cell: ({ row }) => , }, { id: 'actions', diff --git a/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx b/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx index 7f9fac2..0008b48 100644 --- a/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx +++ b/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx @@ -16,24 +16,21 @@ import { AlertDialogTitle, AlertDialogTrigger, } from '@/components/ui/alert-dialog' -import { cn } from '@/lib/utils' import { useState } from 'react' +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' // ─── Status Badge ───────────────────────────────────────────────────────────── -const STATUS_MAP: Record = { - pending: { label: 'Garaşylýar', className: 'bg-yellow-500/20 text-yellow-500 border-yellow-500/30' }, - approved: { label: 'Tassyklandy', className: 'bg-green-500/20 text-green-500 border-green-500/30' }, - rejected: { label: 'Ret edildi', className: 'bg-red-500/20 text-red-500 border-red-500/30' }, +const STATUS_MAP: Record = { + pending: { label: 'Garaşylýar', variant: 'warning' }, + approved: { label: 'Tassyklandy', variant: 'success' }, + rejected: { label: 'Ret edildi', variant: 'error' }, } -function StatusBadge({ status }: { status: IntlPaymentStatus }) { +function PaymentStatusBadge({ status }: { status: IntlPaymentStatus }) { const cfg = STATUS_MAP[status] ?? STATUS_MAP.pending return ( - - - {cfg.label} - + ) } @@ -144,7 +141,7 @@ export default function IntlPaymentViewPage() { ] return ( -
+
{/* Header */}
{/* breadcrumb handled by layout */} @@ -193,7 +190,7 @@ export default function IntlPaymentViewPage() { {data.id} - + {data.created_at} diff --git a/src/pages/loanDepartment/loanOrderMobile/index.tsx b/src/pages/loanDepartment/loanOrderMobile/index.tsx index ab01d66..c987999 100644 --- a/src/pages/loanDepartment/loanOrderMobile/index.tsx +++ b/src/pages/loanDepartment/loanOrderMobile/index.tsx @@ -1,18 +1,34 @@ import { useState, useMemo, useCallback } from 'react' import { useTranslation } from 'react-i18next' -import { Eye, Pencil, Trash2 } from 'lucide-react' +import { Eye, Pencil, Trash2, AlertCircle, CheckCircle2, XCircle, Loader2 } 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 { DataTable } from '@/components/dataTable' import { DataTableToolbar, type ActiveFilter, type FilterField } from '@/components/dataTableToolbar' -import { LoanOrderStatusBadge } from '@/features/loanOrders/components/loanOrderStatusBadge' import { useLoanOrderMobiles, useDeleteLoanOrderMobile, } from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles' import type { LoanOrderMobile, LoanOrderMobileStatus } from '@/features/loanOrderMobiles/api/loanOrderMobilesApi' + + +// ─── 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 + +function LoanOrderStatusBadge({ status }: { status: LoanOrderMobileStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} + // ─── Column IDs ──────────────────────────────────────────────────────────────── const COLUMN_IDS = [ diff --git a/src/pages/loanDepartment/loanOrderMobileView/index.tsx b/src/pages/loanDepartment/loanOrderMobileView/index.tsx index 88edfa1..5c68c8f 100644 --- a/src/pages/loanDepartment/loanOrderMobileView/index.tsx +++ b/src/pages/loanDepartment/loanOrderMobileView/index.tsx @@ -2,10 +2,42 @@ import { useNavigate, useParams } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { Trash2, Pencil, Download, ChevronRight, Eye } from 'lucide-react' import { useLoanOrderMobileById, useDeleteLoanOrderMobile } from '@/features/loanOrderMobiles/hooks/useLoanOrderMobiles' -import { LoanOrderStatusBadge } from '@/features/loanOrders/components/loanOrderStatusBadge' import { CreditCardVisual } from '@/components/creditCardVisual' import { Skeleton } from '@/components/ui/skeleton' import { toast } from 'sonner' +import type { LoanOrderMobileStatus } from '@/features/loanOrderMobiles/api/loanOrderMobilesApi' +import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' +import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' +// ─── Status badge ───────────────────────────────────────────────────────────── + +const STATUS_CONFIG = { + GARAŞYLÝAR: { + label: 'Garaşylýar', + variant: 'warning' as StatusBadgeVariant, + icon: AlertCircle, + }, + KANAGATLANDYRYLAN: { + label: 'Tassyklandy', + variant: 'success' as StatusBadgeVariant, + icon: CheckCircle2, + }, + RED_EDILDI: { + label: 'Ýatyryldy', + variant: 'error' as StatusBadgeVariant, + icon: XCircle, + }, + IŞLENÝÄR: { + label: 'Işlenýär', + variant: 'warning' as StatusBadgeVariant, + icon: AlertCircle, + }, +} satisfies Record + +function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} // ─── Sub-component Types ────────────────────────────────────────────────────── @@ -212,7 +244,7 @@ export default function LoanOrderMobilesViewPage() { {t('loanOrders.columns.status', 'Status')} - +
+ +function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} + // ─── Sub-component Types ────────────────────────────────────────────────────── @@ -215,7 +248,7 @@ export default function LoanOrderViewPage() { {t('loanOrders.columns.status', 'Status')} - +
+ +function LoanOrderStatusBadge({ status }: { status: LoanOrderStatus }) { + const cfg = STATUS_CONFIG[status] + if (!cfg) return {String(status)} + return +} + // ─── Column meta for toggle dropdown ───────────────────────────────────────── const COLUMN_IDS = [ @@ -20,19 +35,19 @@ const COLUMN_IDS = [ // ─── Filter fields ──────────────────────────────────────────────────────────── const REGION_OPTIONS = [ - { value: 'Balkan', label: 'Balkan' }, - { value: 'Ahal', label: 'Ahal' }, - { value: 'Daşoguz', label: 'Daşoguz' }, - { value: 'Lebap', label: 'Lebap' }, - { value: 'Mary', label: 'Mary' }, - { value: 'Aşgabat', label: 'Aşgabat' }, + { value: 'Balkan', label: 'Balkan' }, + { value: 'Ahal', label: 'Ahal' }, + { value: 'Daşoguz', label: 'Daşoguz' }, + { value: 'Lebap', label: 'Lebap' }, + { value: 'Mary', label: 'Mary' }, + { 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' }, + { 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 ─────────────────────────────────────────────────────────── @@ -42,7 +57,6 @@ export default function LoanOrdersPage() { const navigate = useNavigate() const deleteMutation = useDeleteLoanOrder() - // ── State ────────────────────────────────────────────────────────────────── const [search, setSearch] = useState('') const [page, setPage] = useState(1) const [perPage, setPerPage] = useState(10) @@ -55,7 +69,6 @@ export default function LoanOrdersPage() { { fieldId: 'archived', value: '' }, ]) - // ── Query params ─────────────────────────────────────────────────────────── const queryParams = useMemo(() => { const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value])) return { @@ -70,10 +83,8 @@ export default function LoanOrdersPage() { }, [search, activeFilters, page, perPage]) const { data, isLoading } = useLoanOrders(queryParams) - const totalPages = data ? Math.ceil(data.total / perPage) : 1 - // ── Handlers ─────────────────────────────────────────────────────────────── const handleFilterChange = useCallback((fieldId: string, value: string) => { setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))) setPage(1) @@ -92,7 +103,6 @@ export default function LoanOrdersPage() { [deleteMutation, t] ) - // ── Columns ──────────────────────────────────────────────────────────────── const columns = useMemo[]>( () => [ { @@ -208,10 +218,9 @@ export default function LoanOrdersPage() { size: 100, }, ], - [t, handleDelete, deleteMutation.isPending] + [t, navigate, handleDelete, deleteMutation.isPending] ) - // ── Column meta for toolbar ──────────────────────────────────────────────── const toggleableColumns = useMemo( () => COLUMN_IDS.map((id) => ({ id, label: t(`loanOrders.columns.${id}`, id) })), [t] @@ -246,17 +255,14 @@ export default function LoanOrdersPage() { [t] ) - // ───────────────────────────────────────────────────────────────────────── return (
- {/* Page Header */}

{t('loanOrders.title', 'Karz sargytlary')}

- {/* Table Card */}
{ setPerPage(v); setPage(1) }} actionLabel={t('loanOrderMobiles.createButton', 'Karz sargyt dörediñ')} - onAction={() => { - navigate('/loan-orders/create') - }} + onAction={() => navigate('/loan-orders/create')} />