From 234081733089885aa5fa6ee0063f34a46ed7ced0 Mon Sep 17 00:00:00 2001 From: Jelaletdin12 Date: Sat, 9 May 2026 08:53:59 +0500 Subject: [PATCH] refactored some page, created new shared components --- src/components/viewPageComponents.tsx | 221 +++++++++ .../cardDepartment/cardBalanceView/index.tsx | 199 ++++---- .../cardDepartment/cardPinsView/index.tsx | 228 +++++---- .../cardRequisitesView/index.tsx | 214 +++++---- .../cardTransactionsView/index.tsx | 110 ++--- .../cardDepartment/orderNewCardView/index.tsx | 311 ++++++------- .../sberPaymentsView/index.tsx | 60 +-- .../visaMasterPaymentsView/index.tsx | 69 +-- .../loanOrderMobileView/index.tsx | 439 +++++++++--------- .../loanDepartment/loanOrderView/index.tsx | 379 +++++++-------- .../loanRemainingView/index.tsx | 113 ++--- 11 files changed, 1222 insertions(+), 1121 deletions(-) create mode 100644 src/components/viewPageComponents.tsx diff --git a/src/components/viewPageComponents.tsx b/src/components/viewPageComponents.tsx new file mode 100644 index 0000000..f1d18ac --- /dev/null +++ b/src/components/viewPageComponents.tsx @@ -0,0 +1,221 @@ +import { Download, Eye, ChevronRight } from "lucide-react"; +import { useTranslation } from "react-i18next"; + +// ─── InfoRow ────────────────────────────────────────────────────────────────── +// Supports both: +// +// {data.id} + +export interface InfoRowProps { + label: string; + /** Plain string/number value — use this or children, not both */ + value?: string | number | null; + /** Arbitrary JSX — status badges, links, custom formatting, etc. */ + children?: React.ReactNode; + isLink?: boolean; +} + +export function InfoRow({ label, value, children, isLink }: InfoRowProps) { + const content = children ?? (value != null ? String(value) : null); + + return ( +
+ {label} + {content != null && content !== "" ? ( + typeof content === "string" ? ( + + {content} + + ) : ( +
{content}
+ ) + ) : ( + — + )} +
+ ); +} + +// ─── Section ────────────────────────────────────────────────────────────────── +// title is optional — omit or pass empty string to skip the heading + +export interface SectionProps { + title?: string; + children: React.ReactNode; +} + +export function Section({ title, children }: SectionProps) { + return ( +
+ {title ? ( +

+ {title} +

+ ) : null} +
+ {children} +
+
+ ); +} + +// ─── PassportImage ──────────────────────────────────────────────────────────── +// Accepts both `src` and `url` prop names for compatibility + +export interface PassportImageProps { + label: string; + src?: string | null; + url?: string | null; +} + +export function PassportImage({ label, src, url }: PassportImageProps) { + const { t } = useTranslation(); + const imageSrc = src ?? url ?? null; + + return ( +
+ {label} +
+ {imageSrc ? ( + {label} + ) : ( +
+ — +
+ )} + {imageSrc && ( + + + {t("common.download", "Göçürip al")} + + )} +
+
+ ); +} + +// ─── AuditRow ───────────────────────────────────────────────────────────────── + +export interface AuditRowProps { + id: string; + action: string; + by: string; + target: string; + status: string; + date: string; +} + +export function AuditRow({ + id, + action, + by, + target, + status, + date, +}: AuditRowProps) { + return ( + + {id} + {action} + {by} + {target} + + + + {status} + + + + {date} + + + + + + ); +} + +// ─── AuditLog (full collapsible table) ─────────────────────────────────────── + +export interface AuditLogProps { + logs: AuditRowProps[]; + defaultOpen?: boolean; +} + +export function AuditLog({ logs, defaultOpen = true }: AuditLogProps) { + const { t } = useTranslation(); + + const columns = [ + "ID", + t("audit.columns.action", "AMALYŇ ADY"), + t("audit.columns.by", "KIM TARAPYNDAN"), + t("audit.columns.target", "AMALYŇ NYŞANY (TARIBESI)"), + t("audit.columns.status", "AMALYŇ STATUSY"), + t("audit.columns.date", "SENE"), + "", + ]; + + return ( +
+
+ + {t("loanOrders.sections.audit", "Ammallar")} + + +
+
+ + + + {columns.map((col, i) => ( + + ))} + + + + {logs.length === 0 ? ( + + + + ) : ( + logs.map((log) => ) + )} + +
+ {col} +
+ {t("common.noData", "Maglumat ýok")} +
+
+
+ {t("common.prev", "Öňki")} + + 1–{logs.length} / {logs.length} + + {t("common.next", "Soňky")} +
+
+
+
+ ); +} diff --git a/src/pages/cardDepartment/cardBalanceView/index.tsx b/src/pages/cardDepartment/cardBalanceView/index.tsx index 8132d15..7cad1b9 100644 --- a/src/pages/cardDepartment/cardBalanceView/index.tsx +++ b/src/pages/cardDepartment/cardBalanceView/index.tsx @@ -1,9 +1,9 @@ -import { useState } from 'react' -import { useParams, useNavigate, Link } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Download, Trash2, Pencil, ChevronDown } from 'lucide-react' -import { Button } from '@/components/ui/button' -import { Spinner } from '@/components/ui/spinner' +import { useState } from "react"; +import { useParams, useNavigate, Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Download, Trash2, Pencil, ChevronDown } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Spinner } from "@/components/ui/spinner"; import { AlertDialog, AlertDialogAction, @@ -13,93 +13,83 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, -} from '@/components/ui/alert-dialog' +} from "@/components/ui/alert-dialog"; import { useCardBalance, useDeleteCardBalance, useDownloadCardBalance, -} from '@/features/cardBalance/hooks/useCardBalance' +} from "@/features/cardBalance/hooks/useCardBalance"; +import { InfoRow } from "@/components/viewPageComponents"; // ─── Types for operations table ─────────────────────────────────────────────── interface Operation { - id: number - action_name: string - performed_by: string - target: string - status: 'FINISHED' | 'PENDING' | 'FAILED' - date: string + id: number; + action_name: string; + performed_by: string; + target: string; + status: "FINISHED" | "PENDING" | "FAILED"; + date: string; } // ─── Status badge ───────────────────────────────────────────────────────────── const STATUS_STYLES: Record = { - FINISHED: 'bg-emerald-500/20 text-emerald-400 border border-emerald-500/30', - PENDING: 'bg-yellow-500/20 text-yellow-400 border border-yellow-500/30', - FAILED: 'bg-red-500/20 text-red-400 border border-red-500/30', -} + FINISHED: "bg-emerald-500/20 text-emerald-400 border border-emerald-500/30", + PENDING: "bg-yellow-500/20 text-yellow-400 border border-yellow-500/30", + FAILED: "bg-red-500/20 text-red-400 border border-red-500/30", +}; function OpStatusBadge({ status }: { status: string }) { return ( - + {status} - ) -} - -// ─── Detail row ─────────────────────────────────────────────────────────────── - -function DetailRow({ label, value }: { label: string; value: string | number }) { - return ( -
-
- {label} -
-
{value}
-
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function CardBalanceViewPage() { - const { t } = useTranslation() - const { id } = useParams<{ id: string }>() - const navigate = useNavigate() + const { t } = useTranslation(); + const { id } = useParams<{ id: string }>(); + const navigate = useNavigate(); - const [deleteOpen, setDeleteOpen] = useState(false) - const [opsExpanded, setOpsExpanded] = useState(true) - const [opsPage, setOpsPage] = useState(1) + const [deleteOpen, setDeleteOpen] = useState(false); + const [opsExpanded, setOpsExpanded] = useState(true); + const [opsPage, setOpsPage] = useState(1); - const numericId = Number(id) - const { data, isLoading } = useCardBalance(numericId) - const deleteMutation = useDeleteCardBalance() - const downloadMutation = useDownloadCardBalance() + const numericId = Number(id); + const { data, isLoading } = useCardBalance(numericId); + const deleteMutation = useDeleteCardBalance(); + const downloadMutation = useDownloadCardBalance(); // Placeholder operations — in real app fetch from API using numericId - const operations: Operation[] = [] - const opsTotal = operations.length + const operations: Operation[] = []; + const opsTotal = operations.length; const handleDelete = async () => { - await deleteMutation.mutateAsync(numericId) - navigate('/card-balances') - } + await deleteMutation.mutateAsync(numericId); + navigate("/card-balances"); + }; if (isLoading) { return (
- ) + ); } if (!data) { return (
- {t('Not found', 'Tapylmady')} + {t("Not found", "Tapylmady")}
- ) + ); } return ( @@ -107,18 +97,20 @@ export default function CardBalanceViewPage() { {/* Header */}

- {t('Card balance detail', 'Kart galyndysy giňişleýin')}: + {t("Card balance detail", "Kart galyndysy giňişleýin")}:

@@ -165,12 +172,12 @@ export default function CardBalanceViewPage() { {[ - t('ID', 'ID'), - t('Action name', 'AMALYŇ ADY'), - t('Performed by', 'KIM TARAPYNDAN'), - t('Target', 'AMALYŇ NYŞANY (TARGEDI)'), - t('Status', 'AMALYŇ STATUSY'), - t('Date', 'SENE'), + t("ID", "ID"), + t("Action name", "AMALYŇ ADY"), + t("Performed by", "KIM TARAPYNDAN"), + t("Target", "AMALYŇ NYŞANY (TARGEDI)"), + t("Status", "AMALYŇ STATUSY"), + t("Date", "SENE"), ].map((h) => ( {operations.length === 0 ? ( - - {t('No operations found', 'Amal tapylmady')} + + {t("No operations found", "Amal tapylmady")} ) : ( operations.map((op) => ( - - {op.id} + + + {op.id} + {op.action_name} {op.performed_by} {op.target} - - {op.date} + + + + + {op.date} + )) )} @@ -206,14 +225,20 @@ export default function CardBalanceViewPage() { {/* Ops pagination */}
- - {opsTotal === 0 ? '0' : `1–${opsTotal}`} {t('of', 'of')} {opsTotal} + {opsTotal === 0 ? "0" : `1–${opsTotal}`} {t("of", "of")}{" "} + {opsTotal}
@@ -224,25 +249,29 @@ export default function CardBalanceViewPage() { - {t('Are you sure?', 'Eminsiňizmi?')} + + {t("Are you sure?", "Eminsiňizmi?")} + {t( - 'This action cannot be undone.', - 'Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.', + "This action cannot be undone.", + "Bu amal yzyna gaýtarylmaz. Kart galyndysy hemişelik öçüriler.", )} - {t('Cancel', 'Ýatyr')} + {t("Cancel", "Ýatyr")} - {deleteMutation.isPending ? t('Deleting...', 'Öçürilýär...') : t('Delete', 'Öçür')} + {deleteMutation.isPending + ? t("Deleting...", "Öçürilýär...") + : t("Delete", "Öçür")}
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/cardDepartment/cardPinsView/index.tsx b/src/pages/cardDepartment/cardPinsView/index.tsx index 8680d52..ba26438 100644 --- a/src/pages/cardDepartment/cardPinsView/index.tsx +++ b/src/pages/cardDepartment/cardPinsView/index.tsx @@ -1,10 +1,13 @@ -import { useParams, useNavigate } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { useCardPin, useDeleteCardPin } from '@/features/cardPins/hooks/useCardPins' -import type { CardPinStatus } from '@/features/cardPins/api/cardPinApi' -import { Spinner } from '@/components/ui/spinner' -import { Button } from '@/components/ui/button' -import { Pencil, Trash2, Download } from 'lucide-react' +import { useParams, useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { + useCardPin, + useDeleteCardPin, +} from "@/features/cardPins/hooks/useCardPins"; +import type { CardPinStatus } from "@/features/cardPins/api/cardPinApi"; +import { Spinner } from "@/components/ui/spinner"; +import { Button } from "@/components/ui/button"; +import { Pencil, Trash2 } from "lucide-react"; import { AlertDialog, AlertDialogAction, @@ -15,99 +18,71 @@ import { AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger, -} from '@/components/ui/alert-dialog' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' - +} from "@/components/ui/alert-dialog"; +import { + StatusBadge, + type StatusBadgeVariant, +} from "@/components/ui/statusBadge"; +import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; +import { InfoRow, PassportImage } from "@/components/viewPageComponents"; // ─── Status badge ───────────────────────────────────────────────────────────── const STATUS_CONFIG = { pending: { - label: 'Garaşylýar', - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: "Garaşylýar", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, approved: { - label: 'Tassyklandy', - variant: 'success' as StatusBadgeVariant, - icon: CheckCircle2, + label: "Tassyklandy", + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, }, rejected: { - label: 'Ýatyryldy', - variant: 'error' as StatusBadgeVariant, - icon: XCircle, + label: "Ýatyryldy", + variant: "error" as StatusBadgeVariant, + icon: XCircle, }, -} satisfies Record +} satisfies Record< + CardPinStatus, + { label: string; variant: StatusBadgeVariant; icon: React.ElementType } +>; function CardPinStatusBadge({ status }: { status: CardPinStatus }) { - const cfg = STATUS_CONFIG[status] - if (!cfg) return {String(status)} - return -} - -// ─── Field row ──────────────────────────────────────────────────────────────── - -function FieldRow({ label, children }: { label: string; children: React.ReactNode }) { + const cfg = STATUS_CONFIG[status]; + if (!cfg) + return ( + {String(status)} + ); return ( -
- {label} - {children} -
- ) -} - -// ─── Passport image ─────────────────────────────────────────────────────────── - -function PassportImage({ label, url }: { label: string; url: string | null }) { - if (!url) return null - return ( -
-

{label}

- -
- ) + + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function CardPinViewPage() { - const { id } = useParams<{ id: string }>() - const navigate = useNavigate() - const { t } = useTranslation() + const { id } = useParams<{ id: string }>(); + const navigate = useNavigate(); + const { t } = useTranslation(); - const { data, isLoading, isError } = useCardPin(id!) - const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin() + const { data, isLoading, isError } = useCardPin(id!); + const { mutate: deletePin, isPending: isDeleting } = useDeleteCardPin(); if (isLoading) { return (
- ) + ); } if (isError || !data) { return (
- {t('common.notFound', 'Maglumat tapylmady')} + {t("common.notFound", "Maglumat tapylmady")}
- ) + ); } return ( @@ -115,32 +90,43 @@ export default function CardPinViewPage() { {/* Header */}

- {t('cardPin.viewTitle', 'Kart pin bukja giňişleýin')}: {data.id} + {t("cardPin.viewTitle", "Kart pin bukja giňişleýin")}: {data.id}

- - {t('cardPin.deleteTitle', 'Pozmak isleýärsiňizmi?')} + + {t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")} + - {t('cardPin.deleteDesc', 'Bu amal yzyna dolanyp bolmaz.')} {data.id} + {t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")}{" "} + {data.id} - {t('common.cancel', 'Ýatyr')} + {t("common.cancel", "Ýatyr")} deletePin(data.id, { onSuccess: () => navigate('/card-pins') })} + onClick={() => + deletePin(data.id, { + onSuccess: () => navigate("/card-pins"), + }) + } > - {t('common.delete', 'Poz')} + {t("common.delete", "Poz")} @@ -159,96 +145,108 @@ export default function CardPinViewPage() { {/* Main Info */}
- + {data.id} - - + + {data.created_at} - - + + - - - {data.note || '—'} - - - {data.created_by_label} - + + + {data.note || "—"} + + + + {data.created_by_label} + +
{/* Kart */}

- {t('cardPin.cardSection', 'Kart')} + {t("cardPin.cardSection", "Kart")}

- + {data.card_number} - - — - — + + + — + + + — +
{/* Lokasiýa */}

- {t('cardPin.locationSection', 'Lokasiýa')} + {t("cardPin.locationSection", "Lokasiýa")}

- {data.province_label} - - {data.branch_label} - + + {data.province_label} + + + + {data.branch_label} + +
{/* Şahsy maglumatlar */}

- {t('cardPin.personalSection', 'Şahsy maglumatlar')} + {t("cardPin.personalSection", "Şahsy maglumatlar")}

- + {`${data.last_name} ${data.first_name} ${data.father_name}`} - - {data.birth_date} - +{data.phone} + + + {data.birth_date} + + +{data.phone}
{/* Pasport */}

- {t('cardPin.passportSection', 'Pasport')} + {t("cardPin.passportSection", "Pasport")}

- + {data.passport_series} - - + + {data.passport_number} - +
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/cardDepartment/cardRequisitesView/index.tsx b/src/pages/cardDepartment/cardRequisitesView/index.tsx index b449b30..f2f63f0 100644 --- a/src/pages/cardDepartment/cardRequisitesView/index.tsx +++ b/src/pages/cardDepartment/cardRequisitesView/index.tsx @@ -1,9 +1,9 @@ -import { useState } from 'react' -import { useParams, useNavigate, Link } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Download, Trash2, Pencil, DownloadCloud } from 'lucide-react' -import { Button } from '@/components/ui/button' -import { Spinner } from '@/components/ui/spinner' +import { useState } from "react"; +import { useParams, useNavigate, Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Download, Trash2, Pencil, DownloadCloud } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Spinner } from "@/components/ui/spinner"; import { AlertDialog, AlertDialogAction, @@ -13,47 +13,43 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, -} from '@/components/ui/alert-dialog' +} from "@/components/ui/alert-dialog"; import { useCardRequisite, useDeleteCardRequisite, useDownloadCardRequisite, -} from '@/features/cardRequisites/hooks/useCardRequisites' -import type { CardRequisiteStatus } from '@/features/cardRequisites/api/cardRequisitesApi' - +} from "@/features/cardRequisites/hooks/useCardRequisites"; +import type { CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi"; +import { InfoRow } from "@/components/viewPageComponents"; // ─── Status badge ───────────────────────────────────────────────────────────── -const STATUS_BADGE: Record = { - pending: { label: 'GARAŞYLÝAR', className: 'bg-yellow-500/20 text-yellow-400 border border-yellow-500/30' }, - approved: { label: 'TASSYKLANAN', className: 'bg-emerald-500/20 text-emerald-400 border border-emerald-500/30' }, - rejected: { label: 'RET EDILEN', className: 'bg-red-500/20 text-red-400 border border-red-500/30' }, -} - -// ─── Detail row ─────────────────────────────────────────────────────────────── - -function DetailRow({ - label, - children, -}: { - label: string - children: React.ReactNode -}) { - return ( -
-
- {label} -
-
{children}
-
- ) -} +const STATUS_BADGE: Record< + CardRequisiteStatus, + { label: string; className: string } +> = { + pending: { + label: "GARAŞYLÝAR", + className: "bg-yellow-500/20 text-yellow-400 border border-yellow-500/30", + }, + approved: { + label: "TASSYKLANAN", + className: + "bg-emerald-500/20 text-emerald-400 border border-emerald-500/30", + }, + rejected: { + label: "RET EDILEN", + className: "bg-red-500/20 text-red-400 border border-red-500/30", + }, +}; // ─── Section header ─────────────────────────────────────────────────────────── function SectionTitle({ children }: { children: React.ReactNode }) { return ( -

{children}

- ) +

+ {children} +

+ ); } // ─── Passport image row ─────────────────────────────────────────────────────── @@ -78,7 +74,7 @@ function PassportImageRow({ label, url }: { label: string; url?: string }) { className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit" > - {( 'Göçürip al')} + {"Göçürip al"} ) : ( @@ -86,62 +82,64 @@ function PassportImageRow({ label, url }: { label: string; url?: string }) { )}
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function CardRequisiteViewPage() { - const { t } = useTranslation() - const { id } = useParams<{ id: string }>() - const navigate = useNavigate() + const { t } = useTranslation(); + const { id } = useParams<{ id: string }>(); + const navigate = useNavigate(); - const [deleteOpen, setDeleteOpen] = useState(false) + const [deleteOpen, setDeleteOpen] = useState(false); - const { data, isLoading } = useCardRequisite(id ?? '') - const deleteMutation = useDeleteCardRequisite() - const downloadMutation = useDownloadCardRequisite() + const { data, isLoading } = useCardRequisite(id ?? ""); + const deleteMutation = useDeleteCardRequisite(); + const downloadMutation = useDownloadCardRequisite(); const handleDelete = async () => { - await deleteMutation.mutateAsync(id ?? '') - navigate('/card-requisites') - } + await deleteMutation.mutateAsync(id ?? ""); + navigate("/card-requisites"); + }; if (isLoading) { return (
- ) + ); } if (!data) { return (
- {t('Not found', 'Tapylmady')} + {t("Not found", "Tapylmady")}
- ) + ); } - const statusCfg = STATUS_BADGE[data.status] ?? STATUS_BADGE.pending + const statusCfg = STATUS_BADGE[data.status] ?? STATUS_BADGE.pending; return (
{/* Header */}

- {t('Card requisite detail', 'Kart rekwizit giňişleýin')}: {data.id} + {t("Card requisite detail", "Kart rekwizit giňişleýin")}: {data.id}

- ) + ); } diff --git a/src/pages/cardDepartment/cardTransactionsView/index.tsx b/src/pages/cardDepartment/cardTransactionsView/index.tsx index e74c914..0bff606 100644 --- a/src/pages/cardDepartment/cardTransactionsView/index.tsx +++ b/src/pages/cardDepartment/cardTransactionsView/index.tsx @@ -1,9 +1,9 @@ -import { useState } from 'react' -import { useParams, useNavigate, Link } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Download, Trash2, Pencil } from 'lucide-react' -import { Button } from '@/components/ui/button' -import { Spinner } from '@/components/ui/spinner' +import { useState } from "react"; +import { useParams, useNavigate, Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Download, Trash2, Pencil } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { Spinner } from "@/components/ui/spinner"; import { AlertDialog, AlertDialogAction, @@ -13,59 +13,47 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, -} from '@/components/ui/alert-dialog' +} from "@/components/ui/alert-dialog"; import { useCardTransaction, useDeleteCardTransaction, useDownloadCardTransaction, -} from '@/features/cardTransactions/hooks/useCardTransactions' - -// ─── Detail row ─────────────────────────────────────────────────────────────── - -function DetailRow({ label, value }: { label: string; value: string | number }) { - return ( -
-
- {label} -
-
{value}
-
- ) -} +} from "@/features/cardTransactions/hooks/useCardTransactions"; +import { InfoRow } from "@/components/viewPageComponents"; // ─── Page ───────────────────────────────────────────────────────────────────── export default function CardTransactionViewPage() { - const { t } = useTranslation() - const { id } = useParams<{ id: string }>() - const navigate = useNavigate() + const { t } = useTranslation(); + const { id } = useParams<{ id: string }>(); + const navigate = useNavigate(); - const [deleteOpen, setDeleteOpen] = useState(false) + const [deleteOpen, setDeleteOpen] = useState(false); - const numericId = Number(id) - const { data, isLoading } = useCardTransaction(numericId) - const deleteMutation = useDeleteCardTransaction() - const downloadMutation = useDownloadCardTransaction() + const numericId = Number(id); + const { data, isLoading } = useCardTransaction(numericId); + const deleteMutation = useDeleteCardTransaction(); + const downloadMutation = useDownloadCardTransaction(); const handleDelete = async () => { - await deleteMutation.mutateAsync(numericId) - navigate('/card-transactions') - } + await deleteMutation.mutateAsync(numericId); + navigate("/card-transactions"); + }; if (isLoading) { return (
- ) + ); } if (!data) { return (
- {t('Not found', 'Tapylmady')} + {t("Not found", "Tapylmady")}
- ) + ); } return ( @@ -73,7 +61,7 @@ export default function CardTransactionViewPage() { {/* Header */}

- {t('Card transaction detail', 'Kart herekedi giňişleýin')}: + {t("Card transaction detail", "Kart herekedi giňişleýin")}:

-
- ) + ); } diff --git a/src/pages/cardDepartment/orderNewCardView/index.tsx b/src/pages/cardDepartment/orderNewCardView/index.tsx index 67d2a66..a436c18 100644 --- a/src/pages/cardDepartment/orderNewCardView/index.tsx +++ b/src/pages/cardDepartment/orderNewCardView/index.tsx @@ -1,8 +1,8 @@ -import { useState } from 'react' -import { useParams, useNavigate, Link } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Printer, Download, Trash2, Pencil } from 'lucide-react' -import { Button } from '@/components/ui/button' +import { useState } from "react"; +import { useParams, useNavigate, Link } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Printer, Download, Trash2, Pencil } from "lucide-react"; +import { Button } from "@/components/ui/button"; import { AlertDialog, AlertDialogAction, @@ -12,97 +12,52 @@ import { AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, -} from '@/components/ui/alert-dialog' -import { Skeleton } from '@/components/ui/skeleton' -import { useCardOrderById, useDeleteCardOrder } from '@/features/orderNewCard/hooks/useOrderNewCard' -import type { CardOrderStatus } from '@/features/orderNewCard/api/orderNewCardApi' - +} from "@/components/ui/alert-dialog"; +import { Skeleton } from "@/components/ui/skeleton"; +import { + useCardOrderById, + useDeleteCardOrder, +} from "@/features/orderNewCard/hooks/useOrderNewCard"; +import type { CardOrderStatus } from "@/features/orderNewCard/api/orderNewCardApi"; +import { + InfoRow, + Section, + PassportImage, +} from "@/components/viewPageComponents"; // ─── Status badge ───────────────────────────────────────────────────────────── -const STATUS_CFG: Record = { - PENDING: { label: 'Garaşylýar', icon: '⏳', className: 'bg-amber-500/10 text-amber-400 border border-amber-500/20' }, - APPROVED: { label: 'Tassyklandy', icon: '✓', className: 'bg-emerald-500/10 text-emerald-400 border border-emerald-500/20' }, - REJECTED: { label: 'Ýatyryldy', icon: '✕', className: 'bg-red-500/10 text-red-400 border border-red-500/20' }, -} +const STATUS_CFG: Record< + CardOrderStatus, + { label: string; className: string; icon: string } +> = { + PENDING: { + label: "Garaşylýar", + icon: "⏳", + className: "bg-amber-500/10 text-amber-400 border border-amber-500/20", + }, + APPROVED: { + label: "Tassyklandy", + icon: "✓", + className: + "bg-emerald-500/10 text-emerald-400 border border-emerald-500/20", + }, + REJECTED: { + label: "Ýatyryldy", + icon: "✕", + className: "bg-red-500/10 text-red-400 border border-red-500/20", + }, +}; function StatusBadge({ status }: { status: CardOrderStatus }) { - const cfg = STATUS_CFG[status] + const cfg = STATUS_CFG[status]; return ( - + {cfg.icon} {cfg.label} - ) -} - -// ─── Info row ───────────────────────────────────────────────────────────────── - -function InfoRow({ - label, - children, -}: { - label: string - children: React.ReactNode -}) { - return ( -
- {label} - {children} -
- ) -} - -// ─── Section ────────────────────────────────────────────────────────────────── - -function Section({ title, children }: { title: string; children: React.ReactNode }) { - return ( -
-

{title}

-
- {children} -
-
- ) -} - -// ─── Passport file card ─────────────────────────────────────────────────────── - -function PassportFileCard({ label, url }: { label: string; url: string | null }) { - const { t } = useTranslation() - - return ( -
- {label} -
- {url ? ( - <> -
- {label} { - ;(e.currentTarget as HTMLImageElement).style.display = 'none' - }} - /> -
- - - {t('common.download', 'Göçürip al')} - - - ) : ( - — - )} -
-
- ) + ); } // ─── Loading skeleton ───────────────────────────────────────────────────────── @@ -117,69 +72,74 @@ function DetailSkeleton() { ))}
- ) + ); } // ─── CardOrderDetailPage ────────────────────────────────────────────────────── export default function CardOrderDetailPage() { - const { id } = useParams<{ id: string }>() - const navigate = useNavigate() - const { t } = useTranslation() + const { id } = useParams<{ id: string }>(); + const navigate = useNavigate(); + const { t } = useTranslation(); - const [deleteOpen, setDeleteOpen] = useState(false) + const [deleteOpen, setDeleteOpen] = useState(false); - const { data: order, isLoading } = useCardOrderById(id ?? '') - const deleteMutation = useDeleteCardOrder() + const { data: order, isLoading } = useCardOrderById(id ?? ""); + const deleteMutation = useDeleteCardOrder(); const handleDelete = async () => { - if (!id) return - await deleteMutation.mutateAsync(id) - navigate('/order-new-card') - } + if (!id) return; + await deleteMutation.mutateAsync(id); + navigate("/order-new-card"); + }; - if (isLoading) return - if (!order) return ( -

- {t('common.notFound', 'Tapylmady')} -

- ) + if (isLoading) return ; + if (!order) + return ( +

+ {t("common.notFound", "Tapylmady")} +

+ ); return (
- {/* Header */}

- {t('cardOrder.detailTitle', 'Kart sargyt giriş üçin')}:{' '} + {t("cardOrder.detailTitle", "Kart sargyt giriş üçin")}:{" "} {order.id}

- - -
@@ -188,94 +148,119 @@ export default function CardOrderDetailPage() { {/* Main info */}
{order.id} - + {order.createdAt} - - + - {order.isPaid ? '✓' : '✕'} + {order.isPaid ? "✓" : "✕"} - + - - {order.note ?? '—'} + + {order.note ?? "—"} - + {order.createdBy}
{/* Kart */} -
- - {order.issuanceReasonName} +
+ + + {order.issuanceReasonName} + - - {order.cardTypeName} + + + {order.cardTypeName} +
{/* Lokasiýa */} -
- +
+ {order.provinceName} - + {order.branchName}
{/* Şahsy maglumatlar */} -
- - {[order.lastName, order.firstName, order.middleName].filter(Boolean).join(' ')} +
+ + {[order.lastName, order.firstName, order.middleName] + .filter(Boolean) + .join(" ")} - + {order.birthDate} - + {order.phone} - - {order.phoneExtra ?? '—'} + + {order.phoneExtra ?? "—"} - + {order.citizenship} - + {order.registeredAddress} - + {order.currentAddress} - + {order.workplace}
{/* Pasport faýýlar */} -
- + - - -
@@ -285,30 +270,28 @@ export default function CardOrderDetailPage() { - {t('cardOrder.deleteTitle', 'Pozmak isleýärsiňizmi?')} + {t("cardOrder.deleteTitle", "Pozmak isleýärsiňizmi?")} {t( - 'cardOrder.deleteDescription', - 'Bu kart sargyt hemişelik pozular. Bu işi yzyna gaýtaryp bolmaz.', + "cardOrder.deleteDescription", + "Bu kart sargyt hemişelik pozular. Bu işi yzyna gaýtaryp bolmaz.", )} - - {t('common.cancel', 'Ýatyr')} - + {t("common.cancel", "Ýatyr")} {deleteMutation.isPending - ? t('common.deleting', 'Pozulýar...') - : t('common.delete', 'Pozmak')} + ? t("common.deleting", "Pozulýar...") + : t("common.delete", "Pozmak")}
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/internationalPayments/sberPaymentsView/index.tsx b/src/pages/internationalPayments/sberPaymentsView/index.tsx index a5f8365..fb831a4 100644 --- a/src/pages/internationalPayments/sberPaymentsView/index.tsx +++ b/src/pages/internationalPayments/sberPaymentsView/index.tsx @@ -26,6 +26,7 @@ import { StatusBadge, type StatusBadgeVariant, } from "@/components/ui/statusBadge"; +import { InfoRow, Section } from "@/components/viewPageComponents"; const STATUS_CONFIG = { GARASYLYYAR: { @@ -87,50 +88,7 @@ function PaymentStatusBadge({ status }: { status: PaymentStatus }) { } // ─── Info Row Component ─────────────────────────────────────────────────────── -function InfoRow({ - label, - value, - highlight = false, -}: { - label: string; - value: React.ReactNode; - highlight?: boolean; -}) { - return ( -
- - {label} - - - {value || "—"} - -
- ); -} -// ─── Section Component ──────────────────────────────────────────────────────── - -function Section({ - title, - children, - className, -}: { - title: string; - children: React.ReactNode; - className?: string; -}) { - return ( -
-

{title}

-
{children}
-
- ); -} // ─── Document Item Component ────────────────────────────────────────────────── @@ -234,14 +192,12 @@ export default function SberPaymentViewPage() {
- } - /> - } - /> + + + + + +
@@ -250,7 +206,7 @@ export default function SberPaymentViewPage() {
- +
diff --git a/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx b/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx index 0008b48..5240a7b 100644 --- a/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx +++ b/src/pages/internationalPayments/visaMasterPaymentsView/index.tsx @@ -18,7 +18,7 @@ import { } from '@/components/ui/alert-dialog' import { useState } from 'react' import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' - +import { InfoRow, Section } from '@/components/viewPageComponents' // ─── Status Badge ───────────────────────────────────────────────────────────── const STATUS_MAP: Record = { @@ -34,27 +34,8 @@ function PaymentStatusBadge({ status }: { status: IntlPaymentStatus }) { ) } -// ─── FieldRow ───────────────────────────────────────────────────────────────── -function FieldRow({ label, children }: { label: string; children: React.ReactNode }) { - return ( -
- {label} - {children ?? '—'} -
- ) -} -// ─── Section ────────────────────────────────────────────────────────────────── - -function Section({ title, children }: { title: string; children: React.ReactNode }) { - return ( -
-

{title}

-
{children}
-
- ) -} // ─── DocFile row ───────────────────────────────────────────────────────────── @@ -183,63 +164,63 @@ export default function IntlPaymentViewPage() { {/* Status */}
- + {data.client_label} - - + + {data.id} - - + + - - + + {data.created_at} - - + + {data.note} - +
{/* Ýüztumanyň görnüşi */}
- + {data.currency_type_label} - +
{/* Lokasiýa */}
- {data.province_label} - + {data.province_label} + {data.branch_label} - +
{/* Şahsy maglumatlar */}
- {data.passport_first_name} - {data.passport_last_name} - +{data.phone} - {data.email} - {data.home_address} + {data.passport_first_name} + {data.passport_last_name} + +{data.phone} + {data.email} + {data.home_address}
{/* Töleg */}
- + {data.payer_full_name} - - + + {data.payer_account_number} - +
{/* Receiver table */}
diff --git a/src/pages/loanDepartment/loanOrderMobileView/index.tsx b/src/pages/loanDepartment/loanOrderMobileView/index.tsx index 5c68c8f..dc465e4 100644 --- a/src/pages/loanDepartment/loanOrderMobileView/index.tsx +++ b/src/pages/loanDepartment/loanOrderMobileView/index.tsx @@ -1,152 +1,71 @@ -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 { 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' +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 { 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"; + +import { + InfoRow, + Section, + PassportImage, +} from "@/components/viewPageComponents"; +import { AuditRow, type AuditRowProps } from "@/components/viewPageComponents"; // ─── Status badge ───────────────────────────────────────────────────────────── const STATUS_CONFIG = { GARAŞYLÝAR: { - label: 'Garaşylýar', - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: "Garaşylýar", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, KANAGATLANDYRYLAN: { - label: 'Tassyklandy', - variant: 'success' as StatusBadgeVariant, - icon: CheckCircle2, + label: "Tassyklandy", + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, }, RED_EDILDI: { - label: 'Ýatyryldy', - variant: 'error' as StatusBadgeVariant, - icon: XCircle, + label: "Ýatyryldy", + variant: "error" as StatusBadgeVariant, + icon: XCircle, }, IŞLENÝÄR: { - label: 'Işlenýär', - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: "Işlenýär", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, -} satisfies Record +} satisfies Record< + LoanOrderMobileStatus, + { label: string; variant: StatusBadgeVariant; icon: React.ElementType } +>; -function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { - const cfg = STATUS_CONFIG[status] - if (!cfg) return {String(status)} - return -} - -// ─── Sub-component Types ────────────────────────────────────────────────────── - -interface InfoRowProps { - label: string - value?: string | null - isLink?: boolean -} - -interface SectionProps { - title: string - children: React.ReactNode -} - -interface PassportImageProps { - label: string - src?: string | null -} - -interface AuditRowProps { - id: string - action: string - by: string - target: string - status: string - date: string +function LoanOrderMobileStatusBadge({ + status, +}: { + status: LoanOrderMobileStatus; +}) { + const cfg = STATUS_CONFIG[status]; + if (!cfg) + return ( + {String(status)} + ); + return ( + + ); } // ─── InfoRow ───────────────────────────────────────────────────────────────── -function InfoRow({ label, value, isLink }: InfoRowProps) { - return ( -
- {label} - {value ? ( - - {value} - - ) : ( - — - )} -
- ) -} - -// ─── Section ───────────────────────────────────────────────────────────────── - -function Section({ title, children }: SectionProps) { - return ( -
-

{title}

-
{children}
-
- ) -} - -// ─── PassportImage ──────────────────────────────────────────────────────────── - -function PassportImage({ label, src }: PassportImageProps) { - const { t } = useTranslation() - return ( -
- {label} -
- {src ? ( - {label} - ) : ( -
- — -
- )} - -
-
- ) -} - -// ─── AuditRow ───────────────────────────────────────────────────────────────── - -function AuditRow({ id, action, by, target, status, date }: AuditRowProps) { - return ( - - {id} - {action} - {by} - {target} - - - - {status} - - - {date} - - - - - ) -} - // ─── Skeleton ───────────────────────────────────────────────────────────────── function LoanOrderMobilesViewSkeleton() { @@ -154,7 +73,10 @@ function LoanOrderMobilesViewSkeleton() {
{[...Array(5)].map((_, i) => ( -
+
{[...Array(3)].map((_, j) => ( @@ -162,74 +84,81 @@ function LoanOrderMobilesViewSkeleton() {
))}
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanOrderMobilesViewPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const { id } = useParams<{ id: string }>() - const deleteMutation = useDeleteLoanOrderMobile() + const { t } = useTranslation(); + const navigate = useNavigate(); + const { id } = useParams<{ id: string }>(); + const deleteMutation = useDeleteLoanOrderMobile(); - const { data: order, isLoading } = useLoanOrderMobileById(id!) + const { data: order, isLoading } = useLoanOrderMobileById(id!); const handleDelete = () => { - if (!window.confirm(t('loanOrderMobiles.deleteConfirm', 'Bu sargyt pozulsynmy?'))) return + if ( + !window.confirm( + t("loanOrderMobiles.deleteConfirm", "Bu sargyt pozulsynmy?"), + ) + ) + return; deleteMutation.mutate(id!, { onSuccess: () => { - toast.success(t('loanOrderMobiles.deleteSuccess', 'Sargyt pozuldy')) - navigate('/loan-order-mobiles') + toast.success(t("loanOrderMobiles.deleteSuccess", "Sargyt pozuldy")); + navigate("/loan-order-mobiles"); }, onError: () => { - toast.error(t('loanOrderMobiles.deleteError', 'Pozma wagty ýalňyşlyk ýüze çykdy')) + toast.error( + t("loanOrderMobiles.deleteError", "Pozma wagty ýalňyşlyk ýüze çykdy"), + ); }, - }) - } + }); + }; - if (isLoading) return + if (isLoading) return ; if (!order) { return (
- {t('common.notFound', 'Tapylmady')} + {t("common.notFound", "Tapylmady")}
- ) + ); } // Replace with real audit data from API when available const auditLogs: AuditRowProps[] = [ { - id: '44548', - action: t('audit.actions.view', 'Görmek'), - by: order.createdBy ?? '', - target: `${t('loanOrderMobiles.title', 'Karz sargyt')}: ${order.id}`, - status: 'FINISHED', - date: order.createdAt ?? '', + id: "44548", + action: t("audit.actions.view", "Görmek"), + by: order.createdBy ?? "", + target: `${t("loanOrderMobiles.title", "Karz sargyt")}: ${order.id}`, + status: "FINISHED", + date: order.createdAt ?? "", }, - ] + ]; return (
{/* Page Header */}

- {t('loanOrderMobiles.view.title', 'Karz sargyt giriş')}: {order.id} + {t("loanOrderMobiles.view.title", "Karz sargyt giriş")}: {order.id}

@@ -242,186 +171,235 @@ export default function LoanOrderMobilesViewPage() { {/* Status row — special render */}
- {t('loanOrders.columns.status', 'Status')} + {t("loanOrders.columns.status", "Status")}
- - + +
{/* ── Card ───────────────────────────────────────────────────────────── */} {(order.cardNumber || order.cardName) && ( -
+
- +
- - + +
)} {/* ── Loan ───────────────────────────────────────────────────────────── */} -
+
{/* ── Location ───────────────────────────────────────────────────────── */} -
- +
+
{/* ── Personal Info ──────────────────────────────────────────────────── */} -
+
{/* ── Contacts ───────────────────────────────────────────────────────── */} -
+
- +
{/* ── Employment ─────────────────────────────────────────────────────── */} -
+
{/* ── Passport ───────────────────────────────────────────────────────── */} -
+
{/* ── Guarantor ──────────────────────────────────────────────────────── */} {(order.guarantor1Name || order.guarantor1CardNumber) && ( -
+
{order.guarantor1CardNumber && (
-
- {t('loanOrders.sections.audit', 'Ammallar')} + {t("loanOrders.sections.audit", "Ammallar")}
@@ -446,13 +424,13 @@ export default function LoanOrderMobilesViewPage() { {[ - 'ID', - t('audit.columns.action', 'AMALYŇ ADY'), - t('audit.columns.by', 'KIM TARAPYNDAN'), - t('audit.columns.target', 'AMALYŇ NYŞANY (TARIBESI)'), - t('audit.columns.status', 'AMALYŇ STATUSY'), - t('audit.columns.date', 'SENE'), - '', + "ID", + t("audit.columns.action", "AMALYŇ ADY"), + t("audit.columns.by", "KIM TARAPYNDAN"), + t("audit.columns.target", "AMALYŇ NYŞANY (TARIBESI)"), + t("audit.columns.status", "AMALYŇ STATUSY"), + t("audit.columns.date", "SENE"), + "", ].map((col, i) => (
- {t('common.prev', 'Öňki')} - 1–{auditLogs.length} / {auditLogs.length} - {t('common.next', 'Soňky')} + {t("common.prev", "Öňki")} + + 1–{auditLogs.length} / {auditLogs.length} + + {t("common.next", "Soňky")}
-
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/loanDepartment/loanOrderView/index.tsx b/src/pages/loanDepartment/loanOrderView/index.tsx index 31383b8..81f14ef 100644 --- a/src/pages/loanDepartment/loanOrderView/index.tsx +++ b/src/pages/loanDepartment/loanOrderView/index.tsx @@ -1,150 +1,64 @@ -import { useNavigate, useParams } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Trash2, Pencil, Download, ChevronRight, Eye } from 'lucide-react' -import { useLoanOrderById, useDeleteLoanOrder } from '@/features/loanOrders/hooks/useLoanOrders' -import { Skeleton } from '@/components/ui/skeleton' -import { toast } from 'sonner' -import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge' -import { AlertCircle, CheckCircle2, XCircle } from 'lucide-react' -import type { LoanOrderMobileStatus } from '@/features/loanOrderMobiles/api/loanOrderMobilesApi' - +import { useNavigate, useParams } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Trash2, Pencil, ChevronRight } from "lucide-react"; +import { + useLoanOrderById, + useDeleteLoanOrder, +} from "@/features/loanOrders/hooks/useLoanOrders"; +import { Skeleton } from "@/components/ui/skeleton"; +import { toast } from "sonner"; +import { + StatusBadge, + type StatusBadgeVariant, +} from "@/components/ui/statusBadge"; +import { AlertCircle, CheckCircle2, XCircle } from "lucide-react"; +import type { LoanOrderMobileStatus } from "@/features/loanOrderMobiles/api/loanOrderMobilesApi"; +import { + InfoRow, + Section, + PassportImage, +} from "@/components/viewPageComponents"; +import { AuditRow, type AuditRowProps } from "@/components/viewPageComponents"; const STATUS_CONFIG = { GARAŞYLÝAR: { - label: 'Garaşylýar', - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: "Garaşylýar", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, KANAGATLANDYRYLAN: { - label: 'Tassyklandy', - variant: 'success' as StatusBadgeVariant, - icon: CheckCircle2, + label: "Tassyklandy", + variant: "success" as StatusBadgeVariant, + icon: CheckCircle2, }, RED_EDILDI: { - label: 'Ýatyryldy', - variant: 'error' as StatusBadgeVariant, - icon: XCircle, + label: "Ýatyryldy", + variant: "error" as StatusBadgeVariant, + icon: XCircle, }, IŞLENÝÄR: { - label: 'Işlenýär', - variant: 'warning' as StatusBadgeVariant, - icon: AlertCircle, + label: "Işlenýär", + variant: "warning" as StatusBadgeVariant, + icon: AlertCircle, }, -} satisfies Record +} satisfies Record< + LoanOrderMobileStatus, + { label: string; variant: StatusBadgeVariant; icon: React.ElementType } +>; -function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) { - const cfg = STATUS_CONFIG[status] - if (!cfg) return {String(status)} - return -} - - -// ─── Sub-component Types ────────────────────────────────────────────────────── - -interface InfoRowProps { - label: string - value?: string | null - isLink?: boolean -} - -interface SectionProps { - title: string - children: React.ReactNode -} - -interface PassportImageProps { - label: string - src?: string | null -} - -interface AuditRowProps { - id: string - action: string - by: string - target: string - status: string - date: string -} - -// ─── InfoRow ───────────────────────────────────────────────────────────────── - -function InfoRow({ label, value, isLink }: InfoRowProps) { +function LoanOrderMobileStatusBadge({ + status, +}: { + status: LoanOrderMobileStatus; +}) { + const cfg = STATUS_CONFIG[status]; + if (!cfg) + return ( + {String(status)} + ); return ( -
- {label} - {value ? ( - - {value} - - ) : ( - — - )} -
- ) -} - -// ─── Section ───────────────────────────────────────────────────────────────── - -function Section({ title, children }: SectionProps) { - return ( -
-

{title}

-
{children}
-
- ) -} - -// ─── PassportImage ──────────────────────────────────────────────────────────── - -function PassportImage({ label, src }: PassportImageProps) { - const { t } = useTranslation() - return ( -
- {label} -
- {src ? ( - {label} - ) : ( -
- — -
- )} - -
-
- ) -} - -// ─── AuditRow ───────────────────────────────────────────────────────────────── - -function AuditRow({ id, action, by, target, status, date }: AuditRowProps) { - return ( - - {id} - {action} - {by} - {target} - - - - {status} - - - {date} - - - - - ) + + ); } // ─── Skeleton ───────────────────────────────────────────────────────────────── @@ -154,7 +68,10 @@ function LoanOrderViewSkeleton() {
{[...Array(5)].map((_, i) => ( -
+
{[...Array(3)].map((_, j) => ( @@ -162,74 +79,77 @@ function LoanOrderViewSkeleton() {
))}
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanOrderViewPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const { id } = useParams<{ id: string }>() - const deleteMutation = useDeleteLoanOrder() + const { t } = useTranslation(); + const navigate = useNavigate(); + const { id } = useParams<{ id: string }>(); + const deleteMutation = useDeleteLoanOrder(); - const { data: order, isLoading } = useLoanOrderById(id!) + const { data: order, isLoading } = useLoanOrderById(id!); const handleDelete = () => { - if (!window.confirm(t('loanOrders.deleteConfirm', 'Bu sargyt pozulsynmy?'))) return + if (!window.confirm(t("loanOrders.deleteConfirm", "Bu sargyt pozulsynmy?"))) + return; deleteMutation.mutate(id!, { onSuccess: () => { - toast.success(t('loanOrders.deleteSuccess', 'Sargyt pozuldy')) - navigate('/loan-orders') + toast.success(t("loanOrders.deleteSuccess", "Sargyt pozuldy")); + navigate("/loan-orders"); }, onError: () => { - toast.error(t('loanOrders.deleteError', 'Pozma wagty ýalňyşlyk ýüze çykdy')) + toast.error( + t("loanOrders.deleteError", "Pozma wagty ýalňyşlyk ýüze çykdy"), + ); }, - }) - } + }); + }; - if (isLoading) return + if (isLoading) return ; if (!order) { return (
- {t('common.notFound', 'Tapylmady')} + {t("common.notFound", "Tapylmady")}
- ) + ); } // Replace with real audit data from API when available const auditLogs: AuditRowProps[] = [ { - id: '44548', - action: t('audit.actions.view', 'Görmek'), - by: order.createdBy ?? '', - target: `${t('loanOrders.title', 'Karz sargyt')}: ${order.id}`, - status: 'FINISHED', - date: order.createdAt ?? '', + id: "44548", + action: t("audit.actions.view", "Görmek"), + by: order.createdBy ?? "", + target: `${t("loanOrders.title", "Karz sargyt")}: ${order.id}`, + status: "FINISHED", + date: order.createdAt ?? "", }, - ] + ]; return (
{/* Page Header */}

- {t('loanOrders.view.title', 'Karz sargyt giriş')}: {order.id} + {t("loanOrders.view.title", "Karz sargyt giriş")}: {order.id}

@@ -240,156 +160,188 @@ export default function LoanOrderViewPage() {
{/* Status row — special render */}
- {t('loanOrders.columns.status', 'Status')} + {t("loanOrders.columns.status", "Status")}
{/* ── Loan ───────────────────────────────────────────────────────────── */} -
+
{/* ── Location ───────────────────────────────────────────────────────── */} -
- +
+
{/* ── Personal Info ──────────────────────────────────────────────────── */} -
+
{/* ── Contacts ───────────────────────────────────────────────────────── */} -
+
- +
{/* ── Employment ─────────────────────────────────────────────────────── */} -
+
{/* ── Passport ───────────────────────────────────────────────────────── */} -
+
@@ -398,7 +350,7 @@ export default function LoanOrderViewPage() {
- {t('loanOrders.sections.audit', 'Ammallar')} + {t("loanOrders.sections.audit", "Ammallar")}
@@ -407,13 +359,13 @@ export default function LoanOrderViewPage() { {[ - 'ID', - t('audit.columns.action', 'AMALYŇ ADY'), - t('audit.columns.by', 'KIM TARAPYNDAN'), - t('audit.columns.target', 'AMALYŇ NYŞANY (TARIBESI)'), - t('audit.columns.status', 'AMALYŇ STATUSY'), - t('audit.columns.date', 'SENE'), - '', + "ID", + t("audit.columns.action", "AMALYŇ ADY"), + t("audit.columns.by", "KIM TARAPYNDAN"), + t("audit.columns.target", "AMALYŇ NYŞANY (TARIBESI)"), + t("audit.columns.status", "AMALYŇ STATUSY"), + t("audit.columns.date", "SENE"), + "", ].map((col, i) => (
- {t('common.prev', 'Öňki')} - 1–{auditLogs.length} / {auditLogs.length} - {t('common.next', 'Soňky')} + {t("common.prev", "Öňki")} + + 1–{auditLogs.length} / {auditLogs.length} + + {t("common.next", "Soňky")}
-
- ) -} \ No newline at end of file + ); +} diff --git a/src/pages/loanDepartment/loanRemainingView/index.tsx b/src/pages/loanDepartment/loanRemainingView/index.tsx index fc71cd9..64cefe9 100644 --- a/src/pages/loanDepartment/loanRemainingView/index.tsx +++ b/src/pages/loanDepartment/loanRemainingView/index.tsx @@ -1,49 +1,13 @@ -import { useNavigate, useParams } from 'react-router-dom' -import { useTranslation } from 'react-i18next' -import { Trash2, Pencil } from 'lucide-react' -import { useLoanRemainingById, useDeleteLoanRemaining } from '@/features/loanRemaining/hooks/useLoanRemaining' -import { Skeleton } from '@/components/ui/skeleton' -import { toast } from 'sonner' - -// ─── Sub-component Types ────────────────────────────────────────────────────── - -interface InfoRowProps { - label: string - value?: string | null -} - -interface SectionProps { - title: string - children: React.ReactNode -} - -// ─── InfoRow ───────────────────────────────────────────────────────────────── - -function InfoRow({ label, value }: InfoRowProps) { - return ( -
- {label} - {value ? ( - - {value} - - ) : ( - — - )} -
- ) -} - -// ─── Section ───────────────────────────────────────────────────────────────── - -function Section({ title, children }: SectionProps) { - return ( -
-

{title}

-
{children}
-
- ) -} +import { useNavigate, useParams } from "react-router-dom"; +import { useTranslation } from "react-i18next"; +import { Trash2, Pencil } from "lucide-react"; +import { + useLoanRemainingById, + useDeleteLoanRemaining, +} from "@/features/loanRemaining/hooks/useLoanRemaining"; +import { Skeleton } from "@/components/ui/skeleton"; +import { toast } from "sonner"; +import { InfoRow, Section } from "@/components/viewPageComponents"; // ─── Skeleton ───────────────────────────────────────────────────────────────── @@ -57,40 +21,50 @@ function LoanRemainingViewSkeleton() { ))}
- ) + ); } // ─── Page ───────────────────────────────────────────────────────────────────── export default function LoanRemainingViewPage() { - const { t } = useTranslation() - const navigate = useNavigate() - const { id } = useParams<{ id: string }>() - const deleteMutation = useDeleteLoanRemaining() + const { t } = useTranslation(); + const navigate = useNavigate(); + const { id } = useParams<{ id: string }>(); + const deleteMutation = useDeleteLoanRemaining(); - const { data: record, isLoading } = useLoanRemainingById(id!) + const { data: record, isLoading } = useLoanRemainingById(id!); const handleDelete = () => { - if (!window.confirm(t('loanRemaining.deleteConfirm', 'Bu ýazgy pozulsynmy?'))) return + if ( + !window.confirm(t("loanRemaining.deleteConfirm", "Bu ýazgy pozulsynmy?")) + ) + return; deleteMutation.mutate(Number(id!), { onSuccess: () => { - toast.success(t('loanRemaining.deleteSuccess', 'Ýazgy üstünlikli pozuldy')) - navigate('/loan-remaining') + toast.success( + t("loanRemaining.deleteSuccess", "Ýazgy üstünlikli pozuldy"), + ); + navigate("/loan-remaining"); }, onError: () => { - toast.error(t('loanRemaining.deleteError', 'Pozmak başartmady, gaýtadan synanyşyň')) + toast.error( + t( + "loanRemaining.deleteError", + "Pozmak başartmady, gaýtadan synanyşyň", + ), + ); }, - }) - } + }); + }; - if (isLoading) return + if (isLoading) return ; if (!record) { return (
- {t('common.notFound', 'Tapylmady')} + {t("common.notFound", "Tapylmady")}
- ) + ); } return ( @@ -98,21 +72,22 @@ export default function LoanRemainingViewPage() { {/* Page Header */}

- {t('loanRemaining.view.title', 'Karz galyndysy maglumaty')}: {record.id} + {t("loanRemaining.view.title", "Karz galyndysy maglumaty")}:{" "} + {record.id}

@@ -120,21 +95,21 @@ export default function LoanRemainingViewPage() {
{/* ── Basic Info ─────────────────────────────────────────────────────── */} -
+
- ) + ); }