refactored some page, created new shared components

This commit is contained in:
Jelaletdin12
2026-05-09 08:53:59 +05:00
parent c6462b9956
commit 2340817330
11 changed files with 1222 additions and 1121 deletions

View File

@@ -0,0 +1,221 @@
import { Download, Eye, ChevronRight } from "lucide-react";
import { useTranslation } from "react-i18next";
// ─── InfoRow ──────────────────────────────────────────────────────────────────
// Supports both:
// <InfoRow label="ID" value={data.id} />
// <InfoRow label="ID">{data.id}</InfoRow>
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 (
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground">{label}</span>
{content != null && content !== "" ? (
typeof content === "string" ? (
<span
className={`text-sm ${isLink ? "text-primary font-medium" : "text-foreground"}`}
>
{content}
</span>
) : (
<div className="text-sm">{content}</div>
)
) : (
<span className="text-muted-foreground/40 text-sm">—</span>
)}
</div>
);
}
// ─── 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 (
<div className="mb-6">
{title ? (
<h2 className="text-base font-semibold text-foreground mb-2">
{title}
</h2>
) : null}
<div className="bg-card border border-border rounded-xl overflow-hidden">
{children}
</div>
</div>
);
}
// ─── 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 (
<div className="grid grid-cols-[220px_1fr] items-start py-3 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground pt-1">{label}</span>
<div className="flex flex-col gap-2">
{imageSrc ? (
<img
src={imageSrc}
alt={label}
className="w-28 h-20 object-cover rounded-md border border-border"
/>
) : (
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
<span className="text-xs text-muted-foreground">—</span>
</div>
)}
{imageSrc && (
<a
href={imageSrc}
download
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit"
>
<Download size={12} />
{t("common.download", "Göçürip al")}
</a>
)}
</div>
</div>
);
}
// ─── 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 (
<tr className="border-b border-border last:border-0 hover:bg-muted/30 transition-colors">
<td className="px-4 py-2.5 text-xs font-mono text-primary">{id}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{action}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{by}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{target}</td>
<td className="px-4 py-2.5">
<span className="inline-flex items-center gap-1.5 text-xs font-medium text-emerald-400 bg-emerald-400/10 border border-emerald-400/30 px-2 py-0.5 rounded-full">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
{status}
</span>
</td>
<td className="px-4 py-2.5 text-xs text-muted-foreground whitespace-nowrap">
{date}
</td>
<td className="px-4 py-2.5">
<button className="p-1 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors">
<Eye size={13} />
</button>
</td>
</tr>
);
}
// ─── 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 (
<div className="mb-6">
<details open={defaultOpen}>
<summary className="text-base font-semibold text-foreground mb-2 cursor-pointer select-none list-none flex items-center gap-1.5 w-fit">
{t("loanOrders.sections.audit", "Ammallar")}
<ChevronRight size={15} className="text-muted-foreground" />
</summary>
<div className="bg-card border border-border rounded-xl overflow-hidden mt-2">
<div className="overflow-x-auto">
<table className="w-full text-sm">
<thead>
<tr className="border-b border-border bg-muted/30">
{columns.map((col, i) => (
<th
key={i}
className="px-4 py-2.5 text-left text-xs font-medium text-muted-foreground uppercase tracking-wide whitespace-nowrap"
>
{col}
</th>
))}
</tr>
</thead>
<tbody>
{logs.length === 0 ? (
<tr>
<td
colSpan={columns.length}
className="text-center py-10 text-muted-foreground text-sm"
>
{t("common.noData", "Maglumat ýok")}
</td>
</tr>
) : (
logs.map((log) => <AuditRow key={log.id} {...log} />)
)}
</tbody>
</table>
</div>
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border text-xs text-muted-foreground">
<span>{t("common.prev", "Öňki")}</span>
<span>
1–{logs.length} / {logs.length}
</span>
<span>{t("common.next", "Soňky")}</span>
</div>
</div>
</details>
</div>
);
}

View File

@@ -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<string, string> = {
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 (
<span className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold ${STATUS_STYLES[status] ?? STATUS_STYLES.PENDING}`}>
<span
className={`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-semibold ${STATUS_STYLES[status] ?? STATUS_STYLES.PENDING}`}
>
<span className="w-1.5 h-1.5 rounded-full bg-current" />
{status}
</span>
)
}
// ─── Detail row ───────────────────────────────────────────────────────────────
function DetailRow({ label, value }: { label: string; value: string | number }) {
return (
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
{label}
</div>
<div className="px-4 py-3 text-sm text-foreground">{value}</div>
</div>
)
);
}
// ─── 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 (
<div className="flex items-center justify-center py-24">
<Spinner className="size-7 text-primary" />
</div>
)
);
}
if (!data) {
return (
<div className="text-center py-24 text-muted-foreground">
{t('Not found', 'Tapylmady')}
{t("Not found", "Tapylmady")}
</div>
)
);
}
return (
@@ -107,18 +97,20 @@ export default function CardBalanceViewPage() {
{/* Header */}
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold text-foreground">
{t('Card balance detail', 'Kart galyndysy giňişleýin')}:
{t("Card balance detail", "Kart galyndysy giňişleýin")}:
</h1>
<div className="flex items-center gap-2">
<Button
variant="outline" size="sm"
variant="outline"
size="sm"
onClick={() => downloadMutation.mutate(numericId)}
disabled={downloadMutation.isPending}
>
<Download size={14} />
</Button>
<Button
variant="outline" size="sm"
variant="outline"
size="sm"
className="text-destructive border-destructive/30 hover:bg-destructive/10"
onClick={() => setDeleteOpen(true)}
>
@@ -134,12 +126,27 @@ export default function CardBalanceViewPage() {
{/* Detail card */}
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('ID', 'ID')} value={data.id} />
<DetailRow label={t('Passport series', 'Pasport seriýasy')} value={data.passport_series} />
<DetailRow label={t('Passport number', 'Pasport belgisi')} value={data.passport_number} />
<DetailRow label={t('Card number', 'Kart belgisi')} value={data.card_number} />
<DetailRow label={t('Card expiry month', 'Kart Möhleti (aý)')} value={data.card_expiry_month} />
<DetailRow label={t('Card expiry year', 'Kart Möhleti (ýyl)')} value={data.card_expiry_year} />
<InfoRow label={t("ID", "ID")} value={data.id} />
<InfoRow
label={t("Passport series", "Pasport seriýasy")}
value={data.passport_series}
/>
<InfoRow
label={t("Passport number", "Pasport belgisi")}
value={data.passport_number}
/>
<InfoRow
label={t("Card number", "Kart belgisi")}
value={data.card_number}
/>
<InfoRow
label={t("Card expiry month", "Kart Möhleti (aý)")}
value={data.card_expiry_month}
/>
<InfoRow
label={t("Card expiry year", "Kart Möhleti (ýyl)")}
value={data.card_expiry_year}
/>
</div>
{/* Ammallar (Operations) collapsible section */}
@@ -150,11 +157,11 @@ export default function CardBalanceViewPage() {
onClick={() => setOpsExpanded((v) => !v)}
>
<span className="font-semibold text-foreground text-sm">
{t('Operations', 'Ammallar')}
{t("Operations", "Ammallar")}
</span>
<ChevronDown
size={15}
className={`text-muted-foreground transition-transform duration-200 ${opsExpanded ? 'rotate-180' : ''}`}
className={`text-muted-foreground transition-transform duration-200 ${opsExpanded ? "rotate-180" : ""}`}
/>
</button>
@@ -165,12 +172,12 @@ export default function CardBalanceViewPage() {
<thead>
<tr className="bg-muted/30 border-b border-border">
{[
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) => (
<th
key={h}
@@ -184,19 +191,31 @@ export default function CardBalanceViewPage() {
<tbody>
{operations.length === 0 ? (
<tr>
<td colSpan={6} className="text-center py-10 text-muted-foreground text-sm">
{t('No operations found', 'Amal tapylmady')}
<td
colSpan={6}
className="text-center py-10 text-muted-foreground text-sm"
>
{t("No operations found", "Amal tapylmady")}
</td>
</tr>
) : (
operations.map((op) => (
<tr key={op.id} className="border-b border-border/50 hover:bg-muted/20 transition-colors">
<td className="px-4 py-3 text-primary font-medium">{op.id}</td>
<tr
key={op.id}
className="border-b border-border/50 hover:bg-muted/20 transition-colors"
>
<td className="px-4 py-3 text-primary font-medium">
{op.id}
</td>
<td className="px-4 py-3">{op.action_name}</td>
<td className="px-4 py-3">{op.performed_by}</td>
<td className="px-4 py-3">{op.target}</td>
<td className="px-4 py-3"><OpStatusBadge status={op.status} /></td>
<td className="px-4 py-3 text-muted-foreground">{op.date}</td>
<td className="px-4 py-3">
<OpStatusBadge status={op.status} />
</td>
<td className="px-4 py-3 text-muted-foreground">
{op.date}
</td>
</tr>
))
)}
@@ -206,14 +225,20 @@ export default function CardBalanceViewPage() {
{/* Ops pagination */}
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border text-sm text-muted-foreground">
<Button variant="ghost" size="sm" disabled={opsPage <= 1} onClick={() => setOpsPage((p) => p - 1)}>
{t('Previous', 'Öňki')}
<Button
variant="ghost"
size="sm"
disabled={opsPage <= 1}
onClick={() => setOpsPage((p) => p - 1)}
>
{t("Previous", "Öňki")}
</Button>
<span>
{opsTotal === 0 ? '0' : `1–${opsTotal}`} {t('of', 'of')} {opsTotal}
{opsTotal === 0 ? "0" : `1–${opsTotal}`} {t("of", "of")}{" "}
{opsTotal}
</span>
<Button variant="ghost" size="sm" disabled={true}>
{t('Next', 'Indiki')}
{t("Next", "Indiki")}
</Button>
</div>
</>
@@ -224,25 +249,29 @@ export default function CardBalanceViewPage() {
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('Are you sure?', 'Eminsiňizmi?')}</AlertDialogTitle>
<AlertDialogTitle>
{t("Are you sure?", "Eminsiňizmi?")}
</AlertDialogTitle>
<AlertDialogDescription>
{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.",
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('Cancel', 'Ýatyr')}</AlertDialogCancel>
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteMutation.isPending ? t('Deleting...', 'Öçürilýär...') : t('Delete', 'Öçür')}
{deleteMutation.isPending
? t("Deleting...", "Öçürilýär...")
: t("Delete", "Öçür")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}
);
}

View File

@@ -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<CardPinStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
} satisfies Record<
CardPinStatus,
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
>;
function CardPinStatusBadge({ status }: { status: CardPinStatus }) {
const cfg = STATUS_CONFIG[status]
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
}
// ─── Field row ────────────────────────────────────────────────────────────────
function FieldRow({ label, children }: { label: string; children: React.ReactNode }) {
const cfg = STATUS_CONFIG[status];
if (!cfg)
return (
<span className="text-xs text-muted-foreground">{String(status)}</span>
);
return (
<div className="grid grid-cols-[200px_1fr] items-start py-3 border-b border-border last:border-0 gap-4">
<span className="text-sm text-muted-foreground">{label}</span>
<span className="text-sm text-foreground">{children}</span>
</div>
)
}
// ─── Passport image ───────────────────────────────────────────────────────────
function PassportImage({ label, url }: { label: string; url: string | null }) {
if (!url) return null
return (
<div className="space-y-2">
<p className="text-sm text-muted-foreground">{label}</p>
<div className="border border-border rounded-lg overflow-hidden inline-block">
<img
src={url}
alt={label}
className="max-w-[200px] max-h-[160px] object-cover block"
/>
<div className="px-3 py-2 bg-muted/40 border-t border-border">
<a
href={url}
download
className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors"
>
<Download size={12} />
Göçürip al
</a>
</div>
</div>
</div>
)
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
);
}
// ─── 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 (
<div className="flex items-center justify-center py-24">
<Spinner className="size-8 text-primary" />
</div>
)
);
}
if (isError || !data) {
return (
<div className="flex items-center justify-center py-24 text-muted-foreground">
{t('common.notFound', 'Maglumat tapylmady')}
{t("common.notFound", "Maglumat tapylmady")}
</div>
)
);
}
return (
@@ -115,32 +90,43 @@ export default function CardPinViewPage() {
{/* Header */}
<div className="flex items-start justify-between">
<h1 className="text-xl font-bold text-foreground">
{t('cardPin.viewTitle', 'Kart pin bukja giňişleýin')}: {data.id}
{t("cardPin.viewTitle", "Kart pin bukja giňişleýin")}: {data.id}
</h1>
<div className="flex items-center gap-2">
<AlertDialog>
<AlertDialogTrigger asChild>
<Button size="icon" variant="ghost" className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10">
<Button
size="icon"
variant="ghost"
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
>
<Trash2 size={15} />
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('cardPin.deleteTitle', 'Pozmak isleýärsiňizmi?')}</AlertDialogTitle>
<AlertDialogTitle>
{t("cardPin.deleteTitle", "Pozmak isleýärsiňizmi?")}
</AlertDialogTitle>
<AlertDialogDescription>
{t('cardPin.deleteDesc', 'Bu amal yzyna dolanyp bolmaz.')} {data.id}
{t("cardPin.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")}{" "}
{data.id}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isDeleting}>
{t('common.cancel', 'Ýatyr')}
{t("common.cancel", "Ýatyr")}
</AlertDialogCancel>
<AlertDialogAction
disabled={isDeleting}
className="bg-destructive hover:bg-destructive/90"
onClick={() => deletePin(data.id, { onSuccess: () => navigate('/card-pins') })}
onClick={() =>
deletePin(data.id, {
onSuccess: () => navigate("/card-pins"),
})
}
>
{t('common.delete', 'Poz')}
{t("common.delete", "Poz")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
@@ -159,96 +145,108 @@ export default function CardPinViewPage() {
{/* Main Info */}
<section className="bg-card border border-border rounded-lg px-6">
<FieldRow label="ID">
<InfoRow label="ID">
<span className="font-mono">{data.id}</span>
</FieldRow>
<FieldRow label={t('cardPin.createdAt', 'Döredilen wagty')}>
</InfoRow>
<InfoRow label={t("cardPin.createdAt", "Döredilen wagty")}>
{data.created_at}
</FieldRow>
<FieldRow label={t('cardPin.status', 'Status')}>
</InfoRow>
<InfoRow label={t("cardPin.status", "Status")}>
<CardPinStatusBadge status={data.status} />
</FieldRow>
<FieldRow label={t('cardPin.note', 'Bellik')}>
{data.note || '—'}
</FieldRow>
<FieldRow label={t('cardPin.createdBy', 'Sargyt eden')}>
<span className="text-primary font-medium">{data.created_by_label}</span>
</FieldRow>
</InfoRow>
<InfoRow label={t("cardPin.note", "Bellik")}>
{data.note || "—"}
</InfoRow>
<InfoRow label={t("cardPin.createdBy", "Sargyt eden")}>
<span className="text-primary font-medium">
{data.created_by_label}
</span>
</InfoRow>
</section>
{/* Kart */}
<section className="bg-card border border-border rounded-lg px-6 py-4">
<h2 className="text-base font-semibold text-foreground mb-2">
{t('cardPin.cardSection', 'Kart')}
{t("cardPin.cardSection", "Kart")}
</h2>
<div className="divide-y divide-border">
<FieldRow label={t('cardPin.cardNumber', 'Kart belgisi')}>
<InfoRow label={t("cardPin.cardNumber", "Kart belgisi")}>
<span className="font-mono tracking-wider">{data.card_number}</span>
</FieldRow>
<FieldRow label={t('cardPin.cardExpireMonth', 'Kart Möhleti (aý)')}>—</FieldRow>
<FieldRow label={t('cardPin.cardExpireYear', 'Kart Möhleti (ýyl)')}>—</FieldRow>
</InfoRow>
<InfoRow label={t("cardPin.cardExpireMonth", "Kart Möhleti (aý)")}>
—
</InfoRow>
<InfoRow label={t("cardPin.cardExpireYear", "Kart Möhleti (ýyl)")}>
—
</InfoRow>
</div>
</section>
{/* Lokasiýa */}
<section className="bg-card border border-border rounded-lg px-6 py-4">
<h2 className="text-base font-semibold text-foreground mb-2">
{t('cardPin.locationSection', 'Lokasiýa')}
{t("cardPin.locationSection", "Lokasiýa")}
</h2>
<div className="divide-y divide-border">
<FieldRow label={t('cardPin.province', 'Welaýat')}>{data.province_label}</FieldRow>
<FieldRow label={t('cardPin.branch', 'Şahamça')}>
<span className="text-primary font-medium">{data.branch_label}</span>
</FieldRow>
<InfoRow label={t("cardPin.province", "Welaýat")}>
{data.province_label}
</InfoRow>
<InfoRow label={t("cardPin.branch", "Şahamça")}>
<span className="text-primary font-medium">
{data.branch_label}
</span>
</InfoRow>
</div>
</section>
{/* Şahsy maglumatlar */}
<section className="bg-card border border-border rounded-lg px-6 py-4">
<h2 className="text-base font-semibold text-foreground mb-2">
{t('cardPin.personalSection', 'Şahsy maglumatlar')}
{t("cardPin.personalSection", "Şahsy maglumatlar")}
</h2>
<div className="divide-y divide-border">
<FieldRow label={t('cardPin.fullName', 'Doly ady')}>
<InfoRow label={t("cardPin.fullName", "Doly ady")}>
{`${data.last_name} ${data.first_name} ${data.father_name}`}
</FieldRow>
<FieldRow label={t('cardPin.birthDate', 'Doglan güni')}>{data.birth_date}</FieldRow>
<FieldRow label={t('cardPin.phone', 'Telefon')}>+{data.phone}</FieldRow>
</InfoRow>
<InfoRow label={t("cardPin.birthDate", "Doglan güni")}>
{data.birth_date}
</InfoRow>
<InfoRow label={t("cardPin.phone", "Telefon")}>+{data.phone}</InfoRow>
</div>
</section>
{/* Pasport */}
<section className="bg-card border border-border rounded-lg px-6 py-4">
<h2 className="text-base font-semibold text-foreground mb-2">
{t('cardPin.passportSection', 'Pasport')}
{t("cardPin.passportSection", "Pasport")}
</h2>
<div className="divide-y divide-border mb-4">
<FieldRow label={t('cardPin.passportSeries', 'Pasport seriýasy')}>
<InfoRow label={t("cardPin.passportSeries", "Pasport seriýasy")}>
{data.passport_series}
</FieldRow>
<FieldRow label={t('cardPin.passportNumber', 'Pasport belgisi')}>
</InfoRow>
<InfoRow label={t("cardPin.passportNumber", "Pasport belgisi")}>
{data.passport_number}
</FieldRow>
</InfoRow>
</div>
<div className="grid grid-cols-2 sm:grid-cols-4 gap-4">
<PassportImage
label={t('cardPin.passportFile1', 'Pasport (sahypa 1)')}
label={t("cardPin.passportFile1", "Pasport (sahypa 1)")}
url={data.passport_file_1}
/>
<PassportImage
label={t('cardPin.passportFile2', 'Pasport (2-3-nji sahypa)')}
label={t("cardPin.passportFile2", "Pasport (2-3-nji sahypa)")}
url={data.passport_file_2}
/>
<PassportImage
label={t('cardPin.passportFile3', 'Pasport (8-9 sahypa)')}
label={t("cardPin.passportFile3", "Pasport (8-9 sahypa)")}
url={data.passport_file_3}
/>
<PassportImage
label={t('cardPin.passportFile4', 'Pasport (32-nji sahypa)')}
label={t("cardPin.passportFile4", "Pasport (32-nji sahypa)")}
url={data.passport_file_4}
/>
</div>
</section>
</div>
)
}
);
}

View File

@@ -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<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' },
}
// ─── Detail row ───────────────────────────────────────────────────────────────
function DetailRow({
label,
children,
}: {
label: string
children: React.ReactNode
}) {
return (
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
{label}
</div>
<div className="px-4 py-3 text-sm text-foreground">{children}</div>
</div>
)
}
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 (
<h2 className="text-base font-semibold text-foreground mt-6 mb-3">{children}</h2>
)
<h2 className="text-base font-semibold text-foreground mt-6 mb-3">
{children}
</h2>
);
}
// ─── 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"
>
<DownloadCloud size={13} />
{( 'Göçürip al')}
{"Göçürip al"}
</a>
</>
) : (
@@ -86,62 +82,64 @@ function PassportImageRow({ label, url }: { label: string; url?: string }) {
)}
</div>
</div>
)
);
}
// ─── 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 (
<div className="flex items-center justify-center py-24">
<Spinner className="size-7 text-primary" />
</div>
)
);
}
if (!data) {
return (
<div className="text-center py-24 text-muted-foreground">
{t('Not found', 'Tapylmady')}
{t("Not found", "Tapylmady")}
</div>
)
);
}
const statusCfg = STATUS_BADGE[data.status] ?? STATUS_BADGE.pending
const statusCfg = STATUS_BADGE[data.status] ?? STATUS_BADGE.pending;
return (
<div className="space-y-0">
{/* Header */}
<div className="flex items-center justify-between mb-4">
<h1 className="text-xl font-semibold text-foreground">
{t('Card requisite detail', 'Kart rekwizit giňişleýin')}: {data.id}
{t("Card requisite detail", "Kart rekwizit giňişleýin")}: {data.id}
</h1>
<div className="flex items-center gap-2">
<Button
variant="outline" size="sm"
variant="outline"
size="sm"
onClick={() => downloadMutation.mutate(data.id)}
disabled={downloadMutation.isPending}
>
<Download size={14} />
</Button>
<Button
variant="outline" size="sm"
variant="outline"
size="sm"
className="text-destructive border-destructive/30 hover:bg-destructive/10"
onClick={() => setDeleteOpen(true)}
>
@@ -157,71 +155,95 @@ export default function CardRequisiteViewPage() {
{/* General info */}
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('ID', 'ID')}>{data.id}</DetailRow>
<DetailRow label={t('Created at', 'Döredilen wagty')}>{data.created_at}</DetailRow>
<DetailRow label={t('Status', 'Status')}>
<span className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold ${statusCfg.className}`}>
<InfoRow label={t("ID", "ID")}>{data.id}</InfoRow>
<InfoRow label={t("Created at", "Döredilen wagty")}>
{data.created_at}
</InfoRow>
<InfoRow label={t("Status", "Status")}>
<span
className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold ${statusCfg.className}`}
>
{statusCfg.label}
</span>
</DetailRow>
<DetailRow label={t('Note', 'Bellik')}>
{data.note || '—'}
</DetailRow>
<DetailRow label={t('Requested by', 'Sargyt eden:')}>
</InfoRow>
<InfoRow label={t("Note", "Bellik")}>{data.note || "—"}</InfoRow>
<InfoRow label={t("Requested by", "Sargyt eden:")}>
{data.first_name && data.last_name ? (
<span className="text-primary font-medium">
{data.last_name}_{data.first_name} ({data.first_name})
</span>
) : '—'}
</DetailRow>
) : (
"—"
)}
</InfoRow>
</div>
{/* Card */}
<SectionTitle>{t('Card', 'Kart')}</SectionTitle>
<SectionTitle>{t("Card", "Kart")}</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('Card number', 'Kart belgisi')}>{data.card_number}</DetailRow>
<DetailRow label={t('Card expiry month', 'Kart Möhleti (aý)')}>{data.card_expiry_month}</DetailRow>
<DetailRow label={t('Card expiry year', 'Kart Möhleti (ýyl)')}>{data.card_expiry_year}</DetailRow>
<InfoRow label={t("Card number", "Kart belgisi")}>
{data.card_number}
</InfoRow>
<InfoRow label={t("Card expiry month", "Kart Möhleti (aý)")}>
{data.card_expiry_month}
</InfoRow>
<InfoRow label={t("Card expiry year", "Kart Möhleti (ýyl)")}>
{data.card_expiry_year}
</InfoRow>
</div>
{/* Location */}
<SectionTitle>{t('Location', 'Lokasiýa')}</SectionTitle>
<SectionTitle>{t("Location", "Lokasiýa")}</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('Province', 'Welaýat')}>{data.province_name ?? '—'}</DetailRow>
<DetailRow label={t('Branch', 'Şahamça')}>
<span className="text-primary font-medium">{data.branch_name ?? '—'}</span>
</DetailRow>
<InfoRow label={t("Province", "Welaýat")}>
{data.province_name ?? "—"}
</InfoRow>
<InfoRow label={t("Branch", "Şahamça")}>
<span className="text-primary font-medium">
{data.branch_name ?? "—"}
</span>
</InfoRow>
</div>
{/* Personal */}
<SectionTitle>{t('Personal information', 'Şahsy maglumatlar')}</SectionTitle>
<SectionTitle>
{t("Personal information", "Şahsy maglumatlar")}
</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('Full name', 'Doly ady')}>
{[data.first_name, data.last_name, data.middle_name].filter(Boolean).join(' ')}
</DetailRow>
<DetailRow label={t('Birth date', 'Doglan güni')}>{data.birth_date}</DetailRow>
<DetailRow label={t('Phone', 'Telefon')}>{data.phone}</DetailRow>
<InfoRow label={t("Full name", "Doly ady")}>
{[data.first_name, data.last_name, data.middle_name]
.filter(Boolean)
.join(" ")}
</InfoRow>
<InfoRow label={t("Birth date", "Doglan güni")}>
{data.birth_date}
</InfoRow>
<InfoRow label={t("Phone", "Telefon")}>{data.phone}</InfoRow>
</div>
{/* Passport */}
<SectionTitle>{t('Passport', 'Pasport')}</SectionTitle>
<SectionTitle>{t("Passport", "Pasport")}</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('Passport series', 'Pasport seriýasy')}>{data.passport_series}</DetailRow>
<DetailRow label={t('Passport number', 'Pasport belgisi')}>{data.passport_number}</DetailRow>
<InfoRow label={t("Passport series", "Pasport seriýasy")}>
{data.passport_series}
</InfoRow>
<InfoRow label={t("Passport number", "Pasport belgisi")}>
{data.passport_number}
</InfoRow>
<PassportImageRow
label={t('Passport (page 1)', 'Pasport (sahypa 1)')}
label={t("Passport (page 1)", "Pasport (sahypa 1)")}
url={data.passport_page1_url}
/>
<PassportImageRow
label={t('Passport (pages 2-3)', 'Pasport (2-3-nji sahypa)')}
label={t("Passport (pages 2-3)", "Pasport (2-3-nji sahypa)")}
url={data.passport_page2_3_url}
/>
<PassportImageRow
label={t('Passport (pages 8-9)', 'Pasport (8-9 sahypa)')}
label={t("Passport (pages 8-9)", "Pasport (8-9 sahypa)")}
url={data.passport_page8_9_url}
/>
<PassportImageRow
label={t('Passport (page 32)', 'Pasport (32-nji sahypa)')}
label={t("Passport (page 32)", "Pasport (32-nji sahypa)")}
url={data.passport_page32_url}
/>
</div>
@@ -230,25 +252,29 @@ export default function CardRequisiteViewPage() {
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('Are you sure?', 'Eminsiňizmi?')}</AlertDialogTitle>
<AlertDialogTitle>
{t("Are you sure?", "Eminsiňizmi?")}
</AlertDialogTitle>
<AlertDialogDescription>
{t(
'This action cannot be undone.',
'Bu amal yzyna gaýtarylmaz. Kart rekwiziti hemişelik öçüriler.',
"This action cannot be undone.",
"Bu amal yzyna gaýtarylmaz. Kart rekwiziti hemişelik öçüriler.",
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('Cancel', 'Ýatyr')}</AlertDialogCancel>
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteMutation.isPending ? t('Deleting...', 'Öçürilýär...') : t('Delete', 'Öçür')}
{deleteMutation.isPending
? t("Deleting...", "Öçürilýär...")
: t("Delete", "Öçür")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
);
}

View File

@@ -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 (
<div className="grid grid-cols-[220px_1fr] border-b border-border/50 last:border-0">
<div className="px-4 py-3 text-sm text-muted-foreground font-medium bg-muted/10">
{label}
</div>
<div className="px-4 py-3 text-sm text-foreground">{value}</div>
</div>
)
}
} 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 (
<div className="flex items-center justify-center py-24">
<Spinner className="size-7 text-primary" />
</div>
)
);
}
if (!data) {
return (
<div className="text-center py-24 text-muted-foreground">
{t('Not found', 'Tapylmady')}
{t("Not found", "Tapylmady")}
</div>
)
);
}
return (
@@ -73,7 +61,7 @@ export default function CardTransactionViewPage() {
{/* Header */}
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold text-foreground">
{t('Card transaction detail', 'Kart herekedi giňişleýin')}:
{t("Card transaction detail", "Kart herekedi giňişleýin")}:
</h1>
<div className="flex items-center gap-2">
<Button
@@ -93,12 +81,7 @@ export default function CardTransactionViewPage() {
>
<Trash2 size={14} />
</Button>
<Button
variant="outline"
size="sm"
className="gap-1.5"
asChild
>
<Button variant="outline" size="sm" className="gap-1.5" asChild>
<Link to={`/card-transactions/${numericId}/edit`}>
<Pencil size={14} />
</Link>
@@ -108,39 +91,56 @@ export default function CardTransactionViewPage() {
{/* Detail card */}
<div className="rounded-lg border border-border bg-card overflow-hidden">
<DetailRow label={t('ID', 'ID')} value={data.id} />
<DetailRow label={t('Passport series', 'Pasport seriýasy')} value={data.passport_series} />
<DetailRow label={t('Passport number', 'Pasport belgisi')} value={data.passport_number} />
<DetailRow label={t('Card number', 'Kart belgisi')} value={data.card_number} />
<DetailRow label={t('Card expiry month', 'Kart Möhleti (aý)')} value={data.card_expiry_month} />
<DetailRow label={t('Card expiry year', 'Kart Möhleti (ýyl)')} value={data.card_expiry_year} />
<InfoRow label={t("ID", "ID")} value={data.id} />
<InfoRow
label={t("Passport series", "Pasport seriýasy")}
value={data.passport_series}
/>
<InfoRow
label={t("Passport number", "Pasport belgisi")}
value={data.passport_number}
/>
<InfoRow
label={t("Card number", "Kart belgisi")}
value={data.card_number}
/>
<InfoRow
label={t("Card expiry month", "Kart Möhleti (aý)")}
value={data.card_expiry_month}
/>
<InfoRow
label={t("Card expiry year", "Kart Möhleti (ýyl)")}
value={data.card_expiry_year}
/>
</div>
{/* Delete dialog */}
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('Are you sure?', 'Eminsiňizmi?')}</AlertDialogTitle>
<AlertDialogTitle>
{t("Are you sure?", "Eminsiňizmi?")}
</AlertDialogTitle>
<AlertDialogDescription>
{t(
'This action cannot be undone. This will permanently delete the card transaction.',
'Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.',
"This action cannot be undone. This will permanently delete the card transaction.",
"Bu amal yzyna gaýtarylmaz. Kart herekedi hemişelik öçüriler.",
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('Cancel', 'Ýatyr')}</AlertDialogCancel>
<AlertDialogCancel>{t("Cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteMutation.isPending
? t('Deleting...', 'Öçürilýär...')
: t('Delete', 'Öçür')}
? t("Deleting...", "Öçürilýär...")
: t("Delete", "Öçür")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
);
}

View File

@@ -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<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' },
}
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 (
<span className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[11px] font-bold tracking-wide ${cfg.className}`}>
<span
className={`inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-[11px] font-bold tracking-wide ${cfg.className}`}
>
<span className="text-[10px]">{cfg.icon}</span>
{cfg.label}
</span>
)
}
// ─── Info row ─────────────────────────────────────────────────────────────────
function InfoRow({
label,
children,
}: {
label: string
children: React.ReactNode
}) {
return (
<div className="grid grid-cols-[200px_1fr] gap-4 py-2.5 px-4 border-b border-border/60 last:border-0 items-start">
<span className="text-sm text-muted-foreground">{label}</span>
<span className="text-sm text-foreground">{children}</span>
</div>
)
}
// ─── Section ──────────────────────────────────────────────────────────────────
function Section({ title, children }: { title: string; children: React.ReactNode }) {
return (
<div className="mb-6">
<h3 className="text-base font-semibold text-foreground mb-3">{title}</h3>
<div className="bg-card border border-border rounded-xl overflow-hidden">
{children}
</div>
</div>
)
}
// ─── Passport file card ───────────────────────────────────────────────────────
function PassportFileCard({ label, url }: { label: string; url: string | null }) {
const { t } = useTranslation()
return (
<div className="grid grid-cols-[200px_1fr] gap-4 py-3 px-4 border-b border-border/60 last:border-0 items-start">
<span className="text-sm text-muted-foreground">{label}</span>
<div className="flex flex-col gap-2">
{url ? (
<>
<div className="w-20 h-14 rounded-lg overflow-hidden bg-muted border border-border">
<img
src={url}
alt={label}
className="w-full h-full object-cover"
onError={(e) => {
;(e.currentTarget as HTMLImageElement).style.display = 'none'
}}
/>
</div>
<a
href={url}
download
target="_blank"
rel="noopener noreferrer"
className="flex items-center gap-1.5 text-xs text-primary hover:text-primary/80 transition-colors w-fit"
>
<Download size={12} />
{t('common.download', 'Göçürip al')}
</a>
</>
) : (
<span className="text-sm text-muted-foreground">—</span>
)}
</div>
</div>
)
);
}
// ─── Loading skeleton ─────────────────────────────────────────────────────────
@@ -117,69 +72,74 @@ function DetailSkeleton() {
))}
</div>
</div>
)
);
}
// ─── 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 <DetailSkeleton />
if (!order) return (
<p className="text-muted-foreground text-sm">
{t('common.notFound', 'Tapylmady')}
</p>
)
if (isLoading) return <DetailSkeleton />;
if (!order)
return (
<p className="text-muted-foreground text-sm">
{t("common.notFound", "Tapylmady")}
</p>
);
return (
<div>
{/* Header */}
<div className="flex items-start justify-between mb-6 gap-4">
<div>
<h1 className="text-xl font-semibold text-foreground">
{t('cardOrder.detailTitle', 'Kart sargyt giriş üçin')}:{' '}
{t("cardOrder.detailTitle", "Kart sargyt giriş üçin")}:{" "}
<span className="text-primary font-mono">{order.id}</span>
</h1>
</div>
<div className="flex items-center gap-2 shrink-0">
<Button variant="outline" size="icon" title={t('common.print', 'Çap etmek')}>
<Button
variant="outline"
size="icon"
title={t("common.print", "Çap etmek")}
>
<Printer size={15} />
</Button>
<Button variant="outline" size="icon" title={t('common.export', 'Eksport')}>
<Button
variant="outline"
size="icon"
title={t("common.export", "Eksport")}
>
<Download size={15} />
</Button>
<Button
variant="outline"
size="icon"
className="text-destructive hover:text-destructive hover:bg-destructive/10 border-destructive/20"
title={t('common.delete', 'Pozmak')}
title={t("common.delete", "Pozmak")}
onClick={() => setDeleteOpen(true)}
>
<Trash2 size={15} />
</Button>
<Button
size="sm"
asChild
>
<Button size="sm" asChild>
<Link to={`/order-new-card/${order.id}/edit`}>
<Pencil size={14} className="mr-1.5" />
{t('common.edit', 'Düzetmek')}
{t("common.edit", "Düzetmek")}
</Link>
</Button>
</div>
@@ -188,94 +148,119 @@ export default function CardOrderDetailPage() {
{/* Main info */}
<Section title="">
<InfoRow label="ID">{order.id}</InfoRow>
<InfoRow label={t('cardOrder.field.createdAt', 'Döredilen wagty')}>
<InfoRow label={t("cardOrder.field.createdAt", "Döredilen wagty")}>
{order.createdAt}
</InfoRow>
<InfoRow label={t('cardOrder.field.isPaid', 'Tölenen')}>
<span className={`inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold
${order.isPaid
? 'bg-emerald-500/15 text-emerald-400'
: 'bg-red-500/15 text-red-400'
<InfoRow label={t("cardOrder.field.isPaid", "Tölenen")}>
<span
className={`inline-flex items-center justify-center w-5 h-5 rounded-full text-xs font-bold
${
order.isPaid
? "bg-emerald-500/15 text-emerald-400"
: "bg-red-500/15 text-red-400"
}`}
>
{order.isPaid ? '✓' : '✕'}
{order.isPaid ? "✓" : "✕"}
</span>
</InfoRow>
<InfoRow label={t('cardOrder.field.status', 'Status')}>
<InfoRow label={t("cardOrder.field.status", "Status")}>
<StatusBadge status={order.status} />
</InfoRow>
<InfoRow label={t('cardOrder.field.note', 'Bellik')}>
{order.note ?? '—'}
<InfoRow label={t("cardOrder.field.note", "Bellik")}>
{order.note ?? "—"}
</InfoRow>
<InfoRow label={t('cardOrder.field.createdBy', 'Sargyt eden')}>
<InfoRow label={t("cardOrder.field.createdBy", "Sargyt eden")}>
<span className="text-primary font-medium">{order.createdBy}</span>
</InfoRow>
</Section>
{/* Kart */}
<Section title={t('cardOrder.section.card', 'Kart')}>
<InfoRow label={t('cardOrder.field.issuanceReason', 'Kartyň çykarylmagynyň sebäbi')}>
<span className="text-primary font-medium">{order.issuanceReasonName}</span>
<Section title={t("cardOrder.section.card", "Kart")}>
<InfoRow
label={t(
"cardOrder.field.issuanceReason",
"Kartyň çykarylmagynyň sebäbi",
)}
>
<span className="text-primary font-medium">
{order.issuanceReasonName}
</span>
</InfoRow>
<InfoRow label={t('cardOrder.field.cardType', 'Kart görnüşi')}>
<span className="text-cyan-400 font-medium">{order.cardTypeName}</span>
<InfoRow label={t("cardOrder.field.cardType", "Kart görnüşi")}>
<span className="text-cyan-400 font-medium">
{order.cardTypeName}
</span>
</InfoRow>
</Section>
{/* Lokasiýa */}
<Section title={t('cardOrder.section.location', 'Lokasiýa')}>
<InfoRow label={t('cardOrder.field.province', 'Welaýat')}>
<Section title={t("cardOrder.section.location", "Lokasiýa")}>
<InfoRow label={t("cardOrder.field.province", "Welaýat")}>
{order.provinceName}
</InfoRow>
<InfoRow label={t('cardOrder.field.branch', 'Şahamça')}>
<InfoRow label={t("cardOrder.field.branch", "Şahamça")}>
<span className="text-cyan-400 font-medium">{order.branchName}</span>
</InfoRow>
</Section>
{/* Şahsy maglumatlar */}
<Section title={t('cardOrder.section.personal', 'Şahsy maglumatlar')}>
<InfoRow label={t('cardOrder.field.fullName', 'Doly ady')}>
{[order.lastName, order.firstName, order.middleName].filter(Boolean).join(' ')}
<Section title={t("cardOrder.section.personal", "Şahsy maglumatlar")}>
<InfoRow label={t("cardOrder.field.fullName", "Doly ady")}>
{[order.lastName, order.firstName, order.middleName]
.filter(Boolean)
.join(" ")}
</InfoRow>
<InfoRow label={t('cardOrder.field.birthDate', 'Doglan güni')}>
<InfoRow label={t("cardOrder.field.birthDate", "Doglan güni")}>
{order.birthDate}
</InfoRow>
<InfoRow label={t('cardOrder.field.phone', 'Telefon')}>
<InfoRow label={t("cardOrder.field.phone", "Telefon")}>
{order.phone}
</InfoRow>
<InfoRow label={t('cardOrder.field.phoneExtra', 'Telefon goşmaça')}>
{order.phoneExtra ?? '—'}
<InfoRow label={t("cardOrder.field.phoneExtra", "Telefon goşmaça")}>
{order.phoneExtra ?? "—"}
</InfoRow>
<InfoRow label={t('cardOrder.field.citizenship', 'Raýatlyk')}>
<InfoRow label={t("cardOrder.field.citizenship", "Raýatlyk")}>
{order.citizenship}
</InfoRow>
<InfoRow label={t('cardOrder.field.registeredAddress', 'Ýazgy edilen salgyňyz')}>
<InfoRow
label={t(
"cardOrder.field.registeredAddress",
"Ýazgy edilen salgyňyz",
)}
>
{order.registeredAddress}
</InfoRow>
<InfoRow label={t('cardOrder.field.currentAddress', 'Häzirki ýaşaýyş ýeri')}>
<InfoRow
label={t("cardOrder.field.currentAddress", "Häzirki ýaşaýyş ýeri")}
>
{order.currentAddress}
</InfoRow>
<InfoRow label={t('cardOrder.field.workplace', 'Işleýän ýeriňiz we wezipäňiz')}>
<InfoRow
label={t("cardOrder.field.workplace", "Işleýän ýeriňiz we wezipäňiz")}
>
{order.workplace}
</InfoRow>
</Section>
{/* Pasport faýýlar */}
<Section title={t('cardOrder.section.passportFiles', 'Pasport faýýlar')}>
<PassportFileCard
label={t('cardOrder.field.passportPage1', 'Pasport (sahypa 1)')}
<Section title={t("cardOrder.section.passportFiles", "Pasport faýýlar")}>
<PassportImage
label={t("cardOrder.field.passportPage1", "Pasport (sahypa 1)")}
url={order.passportFiles.page1}
/>
<PassportFileCard
label={t('cardOrder.field.passportPage23', 'Pasport (2-3-nji sahypa)')}
<PassportImage
label={t(
"cardOrder.field.passportPage23",
"Pasport (2-3-nji sahypa)",
)}
url={order.passportFiles.page23}
/>
<PassportFileCard
label={t('cardOrder.field.passportPage89', 'Pasport (8-9 sahypa)')}
<PassportImage
label={t("cardOrder.field.passportPage89", "Pasport (8-9 sahypa)")}
url={order.passportFiles.page89}
/>
<PassportFileCard
label={t('cardOrder.field.passportPage32', 'Pasport (32-nji sahypa)')}
<PassportImage
label={t("cardOrder.field.passportPage32", "Pasport (32-nji sahypa)")}
url={order.passportFiles.page32}
/>
</Section>
@@ -285,30 +270,28 @@ export default function CardOrderDetailPage() {
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
{t('cardOrder.deleteTitle', 'Pozmak isleýärsiňizmi?')}
{t("cardOrder.deleteTitle", "Pozmak isleýärsiňizmi?")}
</AlertDialogTitle>
<AlertDialogDescription>
{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.",
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>
{t('common.cancel', 'Ýatyr')}
</AlertDialogCancel>
<AlertDialogCancel>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteMutation.isPending
? t('common.deleting', 'Pozulýar...')
: t('common.delete', 'Pozmak')}
? t("common.deleting", "Pozulýar...")
: t("common.delete", "Pozmak")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}
);
}

View File

@@ -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 (
<div className="flex items-start py-2.5 border-b border-border last:border-b-0">
<span className="w-64 shrink-0 text-sm text-muted-foreground">
{label}
</span>
<span
className={cn(
"flex-1 text-sm",
highlight ? "text-primary font-medium" : "text-foreground",
)}
>
{value || "—"}
</span>
</div>
);
}
// ─── Section Component ────────────────────────────────────────────────────────
function Section({
title,
children,
className,
}: {
title: string;
children: React.ReactNode;
className?: string;
}) {
return (
<div className={cn("space-y-1", className)}>
<h2 className="text-base font-semibold text-foreground mb-3">{title}</h2>
<div className="bg-card rounded-lg border border-border">{children}</div>
</div>
);
}
// ─── Document Item Component ──────────────────────────────────────────────────
@@ -234,14 +192,12 @@ export default function SberPaymentViewPage() {
<Section title="Status">
<div className="px-4">
<InfoRow label="ID" value={order.id} />
<InfoRow
label="Status"
value={<PaymentStatusBadge status={order.status} />}
/>
<InfoRow
label="Tolenen (Sul ay)"
value={<PaymentPaidStatusBadge status={order.paidStatus} />}
/>
<InfoRow label="Status">
<PaymentStatusBadge status={order.status} />
</InfoRow>
<InfoRow label="Tolenen (Sul ay)">
<PaymentPaidStatusBadge status={order.paidStatus} />
</InfoRow>
<InfoRow label="Bellik" value={order.bellik} />
</div>
</Section>
@@ -250,7 +206,7 @@ export default function SberPaymentViewPage() {
<Section title="Lokasiya">
<div className="px-4">
<InfoRow label="Welayat" value={order.welayat} />
<InfoRow label="Sahamca" value={order.sahamca} highlight />
<InfoRow label="Sahamca" value={order.sahamca} isLink />
</div>
</Section>

View File

@@ -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<IntlPaymentStatus, { label: string; variant: StatusBadgeVariant }> = {
@@ -34,27 +34,8 @@ function PaymentStatusBadge({ status }: { status: IntlPaymentStatus }) {
)
}
// ─── FieldRow ─────────────────────────────────────────────────────────────────
function FieldRow({ label, children }: { label: string; children: React.ReactNode }) {
return (
<div className="grid grid-cols-[240px_1fr] items-start py-3 border-b border-border last:border-0 gap-4">
<span className="text-sm text-muted-foreground shrink-0">{label}</span>
<span className="text-sm text-foreground">{children ?? '—'}</span>
</div>
)
}
// ─── Section ──────────────────────────────────────────────────────────────────
function Section({ title, children }: { title: string; children: React.ReactNode }) {
return (
<section className="bg-card border border-border rounded-lg">
<h2 className="text-base font-semibold text-foreground px-6 pt-5 pb-3">{title}</h2>
<div className="px-6 pb-4">{children}</div>
</section>
)
}
// ─── DocFile row ─────────────────────────────────────────────────────────────
@@ -183,63 +164,63 @@ export default function IntlPaymentViewPage() {
{/* Status */}
<Section title={t('intlPayment.statusSection', 'Status')}>
<div className="divide-y divide-border">
<FieldRow label={t('intlPayment.client', 'Ulanyjy')}>
<InfoRow label={t('intlPayment.client', 'Ulanyjy')}>
<span className="text-primary font-medium">{data.client_label}</span>
</FieldRow>
<FieldRow label="ID">
</InfoRow>
<InfoRow label="ID">
<span className="font-mono">{data.id}</span>
</FieldRow>
<FieldRow label={t('intlPayment.status', 'Status')}>
</InfoRow>
<InfoRow label={t('intlPayment.status', 'Status')}>
<PaymentStatusBadge status={data.status} />
</FieldRow>
<FieldRow label={t('intlPayment.tilowanMonth', 'Tölewan (Aý/aý)')}>
</InfoRow>
<InfoRow label={t('intlPayment.tilowanMonth', 'Tölewan (Aý/aý)')}>
{data.created_at}
</FieldRow>
<FieldRow label={t('intlPayment.note', 'Bellik')}>
</InfoRow>
<InfoRow label={t('intlPayment.note', 'Bellik')}>
{data.note}
</FieldRow>
</InfoRow>
</div>
</Section>
{/* Ýüztumanyň görnüşi */}
<Section title={t('intlPayment.currencySection', 'Ýüztumanyň görnüşi')}>
<div className="divide-y divide-border">
<FieldRow label={t('intlPayment.currencyType', 'Ýüztumanyň görnüşi')}>
<InfoRow label={t('intlPayment.currencyType', 'Ýüztumanyň görnüşi')}>
{data.currency_type_label}
</FieldRow>
</InfoRow>
</div>
</Section>
{/* Lokasiýa */}
<Section title={t('intlPayment.locationSection', 'Lokasiýa')}>
<div className="divide-y divide-border">
<FieldRow label={t('intlPayment.province', 'Welaýat')}>{data.province_label}</FieldRow>
<FieldRow label={t('intlPayment.branch', 'Şahamça')}>
<InfoRow label={t('intlPayment.province', 'Welaýat')}>{data.province_label}</InfoRow>
<InfoRow label={t('intlPayment.branch', 'Şahamça')}>
<span className="text-primary font-medium">{data.branch_label}</span>
</FieldRow>
</InfoRow>
</div>
</Section>
{/* Şahsy maglumatlar */}
<Section title={t('intlPayment.personalSection', 'Şahsy maglumatlar')}>
<div className="divide-y divide-border">
<FieldRow label={t('intlPayment.passportFirstName', 'Pasportdaky ady')}>{data.passport_first_name}</FieldRow>
<FieldRow label={t('intlPayment.passportLastName', 'Pasportdaky familiýa')}>{data.passport_last_name}</FieldRow>
<FieldRow label={t('intlPayment.phone', 'Telefon')}>+{data.phone}</FieldRow>
<FieldRow label={t('intlPayment.email', 'E-poçta')}>{data.email}</FieldRow>
<FieldRow label={t('intlPayment.homeAddress', 'Häzirki ýaşyş ýeri')}>{data.home_address}</FieldRow>
<InfoRow label={t('intlPayment.passportFirstName', 'Pasportdaky ady')}>{data.passport_first_name}</InfoRow>
<InfoRow label={t('intlPayment.passportLastName', 'Pasportdaky familiýa')}>{data.passport_last_name}</InfoRow>
<InfoRow label={t('intlPayment.phone', 'Telefon')}>+{data.phone}</InfoRow>
<InfoRow label={t('intlPayment.email', 'E-poçta')}>{data.email}</InfoRow>
<InfoRow label={t('intlPayment.homeAddress', 'Häzirki ýaşyş ýeri')}>{data.home_address}</InfoRow>
</div>
</Section>
{/* Töleg */}
<Section title={t('intlPayment.paymentSection', 'Töleg')}>
<div className="divide-y divide-border mb-4">
<FieldRow label={t('intlPayment.payerFullName', 'Töleg upgradyjynyň maglumatlary')}>
<InfoRow label={t('intlPayment.payerFullName', 'Töleg upgradyjynyň maglumatlary')}>
{data.payer_full_name}
</FieldRow>
<FieldRow label={t('intlPayment.payerAccount', 'Töleg upgradyjynyň goşun hasaby')}>
</InfoRow>
<InfoRow label={t('intlPayment.payerAccount', 'Töleg upgradyjynyň goşun hasaby')}>
{data.payer_account_number}
</FieldRow>
</InfoRow>
</div>
{/* Receiver table */}
<div className="border border-border rounded-lg overflow-hidden">

View File

@@ -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<LoanOrderMobileStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
} satisfies Record<
LoanOrderMobileStatus,
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
>;
function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) {
const cfg = STATUS_CONFIG[status]
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
}
// ─── 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 (
<span className="text-xs text-muted-foreground">{String(status)}</span>
);
return (
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
);
}
// ─── InfoRow ─────────────────────────────────────────────────────────────────
function InfoRow({ label, value, isLink }: InfoRowProps) {
return (
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground">{label}</span>
{value ? (
<span className={`text-sm ${isLink ? 'text-primary font-medium' : 'text-foreground'}`}>
{value}
</span>
) : (
<span className="text-muted-foreground/40 text-sm">—</span>
)}
</div>
)
}
// ─── Section ─────────────────────────────────────────────────────────────────
function Section({ title, children }: SectionProps) {
return (
<div className="mb-6">
<h2 className="text-base font-semibold text-foreground mb-2">{title}</h2>
<div className="bg-card border border-border rounded-xl overflow-hidden">{children}</div>
</div>
)
}
// ─── PassportImage ────────────────────────────────────────────────────────────
function PassportImage({ label, src }: PassportImageProps) {
const { t } = useTranslation()
return (
<div className="grid grid-cols-[220px_1fr] items-start py-3 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground pt-1">{label}</span>
<div className="flex flex-col gap-2">
{src ? (
<img
src={src}
alt={label}
className="w-28 h-20 object-cover rounded-md border border-border"
/>
) : (
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
<span className="text-xs text-muted-foreground">—</span>
</div>
)}
<button className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit">
<Download size={12} />
{t('common.download', 'Göçürip al')}
</button>
</div>
</div>
)
}
// ─── AuditRow ─────────────────────────────────────────────────────────────────
function AuditRow({ id, action, by, target, status, date }: AuditRowProps) {
return (
<tr className="border-b border-border last:border-0 hover:bg-muted/30 transition-colors">
<td className="px-4 py-2.5 text-xs font-mono text-primary">{id}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{action}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{by}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{target}</td>
<td className="px-4 py-2.5">
<span className="inline-flex items-center gap-1.5 text-xs font-medium text-emerald-400 bg-emerald-400/10 border border-emerald-400/30 px-2 py-0.5 rounded-full">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
{status}
</span>
</td>
<td className="px-4 py-2.5 text-xs text-muted-foreground whitespace-nowrap">{date}</td>
<td className="px-4 py-2.5">
<button className="p-1 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors">
<Eye size={13} />
</button>
</td>
</tr>
)
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
function LoanOrderMobilesViewSkeleton() {
@@ -154,7 +73,10 @@ function LoanOrderMobilesViewSkeleton() {
<div className="flex flex-col gap-4">
<Skeleton className="h-7 w-64" />
{[...Array(5)].map((_, i) => (
<div key={i} className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
<div
key={i}
className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3"
>
<Skeleton className="h-4 w-32 mb-1" />
{[...Array(3)].map((_, j) => (
<Skeleton key={j} className="h-4 w-full" />
@@ -162,74 +84,81 @@ function LoanOrderMobilesViewSkeleton() {
</div>
))}
</div>
)
);
}
// ─── 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 <LoanOrderMobilesViewSkeleton />
if (isLoading) return <LoanOrderMobilesViewSkeleton />;
if (!order) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
{t('common.notFound', 'Tapylmady')}
{t("common.notFound", "Tapylmady")}
</div>
)
);
}
// 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 (
<div className="flex flex-col">
{/* Page Header */}
<div className="flex items-center justify-between mb-5">
<h1 className="text-xl font-semibold text-foreground">
{t('loanOrderMobiles.view.title', 'Karz sargyt giriş')}: {order.id}
{t("loanOrderMobiles.view.title", "Karz sargyt giriş")}: {order.id}
</h1>
<div className="flex items-center gap-1.5">
<button
onClick={handleDelete}
disabled={deleteMutation.isPending}
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
title={t('common.delete', 'Poz')}
title={t("common.delete", "Poz")}
>
<Trash2 size={16} />
</button>
<button
onClick={() => navigate(`/loan-order-mobiles/${order.id}/edit`)}
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Redaktirle')}
title={t("common.edit", "Redaktirle")}
>
<Pencil size={16} />
</button>
@@ -242,186 +171,235 @@ export default function LoanOrderMobilesViewPage() {
{/* Status row — special render */}
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border">
<span className="text-sm text-muted-foreground">
{t('loanOrders.columns.status', 'Status')}
{t("loanOrders.columns.status", "Status")}
</span>
<LoanOrderMobileStatusBadge status={order.status} />
</div>
<InfoRow
label={t('loanOrders.columns.createdAt', 'Döredilen wagty')}
label={t("loanOrders.columns.createdAt", "Döredilen wagty")}
value={order.createdAt}
/>
<InfoRow label={t('loanOrders.columns.branch', 'Şahamça')} value={order.branch} isLink />
<InfoRow label={t('loanOrders.fields.note', 'Bellik')} value={order.note || '-'} />
<InfoRow
label={t("loanOrders.columns.branch", "Şahamça")}
value={order.branch}
isLink
/>
<InfoRow
label={t("loanOrders.fields.note", "Bellik")}
value={order.note || "-"}
/>
</div>
{/* ── Card ───────────────────────────────────────────────────────────── */}
{(order.cardNumber || order.cardName) && (
<Section title={t('loanOrders.sections.card', 'Kart')}>
<Section title={t("loanOrders.sections.card", "Kart")}>
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-b border-border flex items-center justify-center">
<CreditCardVisual
cardNumber={order.cardNumber}
cardName={order.cardName}
expMonth={order.cardExpMonth}
expYear={order.cardExpYear}
variant="primary"
/>
<CreditCardVisual
cardNumber={order.cardNumber}
cardName={order.cardName}
expMonth={order.cardExpMonth}
expYear={order.cardExpYear}
variant="primary"
/>
</div>
<InfoRow label={t('loanOrders.fields.cardNumber', 'Kart belgisi')} value={order.cardNumber} />
<InfoRow label={t('loanOrders.fields.cardName', 'Kartdaky ady')} value={order.cardName} />
<InfoRow
label={t("loanOrders.fields.cardNumber", "Kart belgisi")}
value={order.cardNumber}
/>
<InfoRow
label={t("loanOrders.fields.cardName", "Kartdaky ady")}
value={order.cardName}
/>
</Section>
)}
{/* ── Loan ───────────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.loan', 'Karz')}>
<Section title={t("loanOrders.sections.loan", "Karz")}>
<InfoRow
label={t('loanOrders.columns.loanType', 'Karz görnüşi')}
label={t("loanOrders.columns.loanType", "Karz görnüşi")}
value={order.loanType}
isLink
/>
<InfoRow
label={t('loanOrders.fields.loanAmount', 'Karz möçberi')}
label={t("loanOrders.fields.loanAmount", "Karz möçberi")}
value={order.loanAmount ? String(order.loanAmount) : undefined}
/>
</Section>
{/* ── Location ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.location', 'Lokasiýa')}>
<InfoRow label={t('loanOrders.columns.region', 'Welaýat')} value={order.region} />
<Section title={t("loanOrders.sections.location", "Lokasiýa")}>
<InfoRow
label={t("loanOrders.columns.region", "Welaýat")}
value={order.region}
/>
</Section>
{/* ── Personal Info ──────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.personal', 'Şahsy maglumatlar')}>
<Section title={t("loanOrders.sections.personal", "Şahsy maglumatlar")}>
<InfoRow
label={t('loanOrders.fields.fullName', 'Doly ady')}
value={`${order.firstName} ${order.lastName} ${order.patronicName || ''}`.trim()}
label={t("loanOrders.fields.fullName", "Doly ady")}
value={`${order.firstName} ${order.lastName} ${order.patronicName || ""}`.trim()}
/>
<InfoRow
label={t('loanOrders.fields.education', 'Bilimi')}
label={t("loanOrders.fields.education", "Bilimi")}
value={order.education ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.maritalStatus', 'Maşgala ýagdaýy')}
label={t("loanOrders.fields.maritalStatus", "Maşgala ýagdaýy")}
value={order.marriageStatus ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.birthDate', 'Doglan güni')}
label={t("loanOrders.fields.birthDate", "Doglan güni")}
value={order.dateOfBirth ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.registeredAddress', 'Ýazgy edilen salgyňyz')}
label={t(
"loanOrders.fields.registeredAddress",
"Ýazgy edilen salgyňyz",
)}
value={order.residence ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.currentAddress', 'Häzirki ýaşaýyş ýeri')}
label={t("loanOrders.fields.currentAddress", "Häzirki ýaşaýyş ýeri")}
value={order.currentResidence ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.loanHistory', 'Karz taryhy')}
label={t("loanOrders.fields.loanHistory", "Karz taryhy")}
value={order.loanHistory ?? undefined}
isLink
/>
</Section>
{/* ── Contacts ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.contacts', 'Habarlaşmak üçin maglumatlar')}>
<Section
title={t(
"loanOrders.sections.contacts",
"Habarlaşmak üçin maglumatlar",
)}
>
<InfoRow
label={t('loanOrders.fields.email', 'E-poçta')}
label={t("loanOrders.fields.email", "E-poçta")}
value={order.email ?? undefined}
/>
<InfoRow label={t('loanOrders.columns.phone', 'Telefon')} value={order.phone} />
<InfoRow
label={t('loanOrders.fields.phoneAlt', 'Telefon goşmaça')}
label={t("loanOrders.columns.phone", "Telefon")}
value={order.phone}
/>
<InfoRow
label={t("loanOrders.fields.phoneAlt", "Telefon goşmaça")}
value={order.phoneAdditional ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.homePhone', 'Öý telefony')}
label={t("loanOrders.fields.homePhone", "Öý telefony")}
value={order.homePhone ?? undefined}
/>
</Section>
{/* ── Employment ─────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.employment', 'Iş')}>
<Section title={t("loanOrders.sections.employment", "Iş")}>
<InfoRow
label={t('loanOrders.fields.employer', 'Işleýän edaranyň/kärhananyn ady')}
label={t(
"loanOrders.fields.employer",
"Işleýän edaranyň/kärhananyn ady",
)}
value={order.workCompany ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.deptPhone', 'Işgärler bölüminiň iş belgisi')}
label={t(
"loanOrders.fields.deptPhone",
"Işgärler bölüminiň iş belgisi",
)}
value={order.workHrPhone ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.workRegion', 'Işleýän welaýatyňyz')}
label={t("loanOrders.fields.workRegion", "Işleýän welaýatyňyz")}
value={order.workRegion ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.workCity', 'Işleýän etrabyňyz')}
label={t("loanOrders.fields.workCity", "Işleýän etrabyňyz")}
value={order.workProvince ?? undefined}
isLink
/>
<InfoRow
label={t('loanOrders.fields.position', 'Wezipe')}
label={t("loanOrders.fields.position", "Wezipe")}
value={order.position ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.salary', 'Zähmet haky')}
label={t("loanOrders.fields.salary", "Zähmet haky")}
value={order.salary ? String(order.salary) : undefined}
/>
<InfoRow
label={t('loanOrders.fields.employedSince', 'Işe başlan wagtyňyz')}
label={t("loanOrders.fields.employedSince", "Işe başlan wagtyňyz")}
value={order.workStartedAt ?? undefined}
/>
</Section>
{/* ── Passport ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.passport', 'Pasport')}>
<Section title={t("loanOrders.sections.passport", "Pasport")}>
<InfoRow
label={t('loanOrders.fields.passportNumber', 'Pasport')}
label={t("loanOrders.fields.passportNumber", "Pasport")}
value={order.passportNumber ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.passportIssuedBy', 'Kim tarapyndan berildi')}
label={t(
"loanOrders.fields.passportIssuedBy",
"Kim tarapyndan berildi",
)}
value={order.passportGivenBy ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.passportBirthPlace', 'Doglan ýeri (pasport)')}
label={t(
"loanOrders.fields.passportBirthPlace",
"Doglan ýeri (pasport)",
)}
value={order.bornPlace ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage1', 'Pasport (sahypa 1)')}
label={t("loanOrders.fields.passportPage1", "Pasport (sahypa 1)")}
src={order.passportPage1Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage23', 'Pasport (2-3-nji sahypa)')}
label={t(
"loanOrders.fields.passportPage23",
"Pasport (2-3-nji sahypa)",
)}
src={order.passportPage23Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage89', 'Pasport (8-9 sahypa)')}
label={t("loanOrders.fields.passportPage89", "Pasport (8-9 sahypa)")}
src={order.passportPage89Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage32', 'Pasport (32-nji sahypa)')}
label={t(
"loanOrders.fields.passportPage32",
"Pasport (32-nji sahypa)",
)}
src={order.passportPage32Url ?? undefined}
/>
</Section>
{/* ── Guarantor ──────────────────────────────────────────────────────── */}
{(order.guarantor1Name || order.guarantor1CardNumber) && (
<Section title={t('loanOrders.sections.guarantor', '1. Zamun')}>
<Section title={t("loanOrders.sections.guarantor", "1. Zamun")}>
<InfoRow
label={t('loanOrders.fields.guarantorName', 'Zamunyň doly ady')}
value={`${order.guarantor1Name || ''} ${order.guarantor1Surname || ''} ${order.guarantor1Patronic || ''}`.trim()}
label={t("loanOrders.fields.guarantorName", "Zamunyň doly ady")}
value={`${order.guarantor1Name || ""} ${order.guarantor1Surname || ""} ${order.guarantor1Patronic || ""}`.trim()}
/>
<InfoRow
label={t('loanOrders.fields.guarantorPassport', 'Pasport')}
value={`${order.guarantor1PassportSerie || ''} ${order.guarantor1PassportNumber || ''}`.trim()}
label={t("loanOrders.fields.guarantorPassport", "Pasport")}
value={`${order.guarantor1PassportSerie || ""} ${order.guarantor1PassportNumber || ""}`.trim()}
/>
<InfoRow
label={t('loanOrders.fields.guarantorSalary', 'Ortaca zähmet haky')}
value={order.guarantor1Salary ? String(order.guarantor1Salary) : undefined}
label={t("loanOrders.fields.guarantorSalary", "Ortaca zähmet haky")}
value={
order.guarantor1Salary
? String(order.guarantor1Salary)
: undefined
}
/>
{order.guarantor1CardNumber && (
<div className="p-6 bg-slate-50 dark:bg-slate-900/50 border-t border-border flex items-center justify-center">
<CreditCardVisual
<CreditCardVisual
cardNumber={order.guarantor1CardNumber}
cardName={order.guarantor1CardName}
expMonth={order.guarantor1CardExpMonth}
@@ -437,7 +415,7 @@ export default function LoanOrderMobilesViewPage() {
<div className="mb-6">
<details open>
<summary className="text-base font-semibold text-foreground mb-2 cursor-pointer select-none list-none flex items-center gap-1.5 w-fit">
{t('loanOrders.sections.audit', 'Ammallar')}
{t("loanOrders.sections.audit", "Ammallar")}
<ChevronRight size={15} className="text-muted-foreground" />
</summary>
<div className="bg-card border border-border rounded-xl overflow-hidden mt-2">
@@ -446,13 +424,13 @@ export default function LoanOrderMobilesViewPage() {
<thead>
<tr className="border-b border-border bg-muted/30">
{[
'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) => (
<th
key={i}
@@ -471,14 +449,15 @@ export default function LoanOrderMobilesViewPage() {
</table>
</div>
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border text-xs text-muted-foreground">
<span>{t('common.prev', 'Öňki')}</span>
<span>1–{auditLogs.length} / {auditLogs.length}</span>
<span>{t('common.next', 'Soňky')}</span>
<span>{t("common.prev", "Öňki")}</span>
<span>
1–{auditLogs.length} / {auditLogs.length}
</span>
<span>{t("common.next", "Soňky")}</span>
</div>
</div>
</details>
</div>
</div>
)
}
);
}

View File

@@ -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<LoanOrderMobileStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }>
} satisfies Record<
LoanOrderMobileStatus,
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
>;
function LoanOrderMobileStatusBadge({ status }: { status: LoanOrderMobileStatus }) {
const cfg = STATUS_CONFIG[status]
if (!cfg) return <span className="text-xs text-muted-foreground">{String(status)}</span>
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
}
// ─── 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 (
<span className="text-xs text-muted-foreground">{String(status)}</span>
);
return (
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground">{label}</span>
{value ? (
<span className={`text-sm ${isLink ? 'text-primary font-medium' : 'text-foreground'}`}>
{value}
</span>
) : (
<span className="text-muted-foreground/40 text-sm">—</span>
)}
</div>
)
}
// ─── Section ─────────────────────────────────────────────────────────────────
function Section({ title, children }: SectionProps) {
return (
<div className="mb-6">
<h2 className="text-base font-semibold text-foreground mb-2">{title}</h2>
<div className="bg-card border border-border rounded-xl overflow-hidden">{children}</div>
</div>
)
}
// ─── PassportImage ────────────────────────────────────────────────────────────
function PassportImage({ label, src }: PassportImageProps) {
const { t } = useTranslation()
return (
<div className="grid grid-cols-[220px_1fr] items-start py-3 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground pt-1">{label}</span>
<div className="flex flex-col gap-2">
{src ? (
<img
src={src}
alt={label}
className="w-28 h-20 object-cover rounded-md border border-border"
/>
) : (
<div className="w-28 h-20 bg-muted rounded-md border border-border flex items-center justify-center">
<span className="text-xs text-muted-foreground">—</span>
</div>
)}
<button className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit">
<Download size={12} />
{t('common.download', 'Göçürip al')}
</button>
</div>
</div>
)
}
// ─── AuditRow ─────────────────────────────────────────────────────────────────
function AuditRow({ id, action, by, target, status, date }: AuditRowProps) {
return (
<tr className="border-b border-border last:border-0 hover:bg-muted/30 transition-colors">
<td className="px-4 py-2.5 text-xs font-mono text-primary">{id}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{action}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{by}</td>
<td className="px-4 py-2.5 text-sm text-foreground">{target}</td>
<td className="px-4 py-2.5">
<span className="inline-flex items-center gap-1.5 text-xs font-medium text-emerald-400 bg-emerald-400/10 border border-emerald-400/30 px-2 py-0.5 rounded-full">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-400" />
{status}
</span>
</td>
<td className="px-4 py-2.5 text-xs text-muted-foreground whitespace-nowrap">{date}</td>
<td className="px-4 py-2.5">
<button className="p-1 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors">
<Eye size={13} />
</button>
</td>
</tr>
)
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
);
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
@@ -154,7 +68,10 @@ function LoanOrderViewSkeleton() {
<div className="flex flex-col gap-4">
<Skeleton className="h-7 w-64" />
{[...Array(5)].map((_, i) => (
<div key={i} className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3">
<div
key={i}
className="bg-card border border-border rounded-xl p-4 flex flex-col gap-3"
>
<Skeleton className="h-4 w-32 mb-1" />
{[...Array(3)].map((_, j) => (
<Skeleton key={j} className="h-4 w-full" />
@@ -162,74 +79,77 @@ function LoanOrderViewSkeleton() {
</div>
))}
</div>
)
);
}
// ─── 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 <LoanOrderViewSkeleton />
if (isLoading) return <LoanOrderViewSkeleton />;
if (!order) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
{t('common.notFound', 'Tapylmady')}
{t("common.notFound", "Tapylmady")}
</div>
)
);
}
// 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 (
<div className="flex flex-col">
{/* Page Header */}
<div className="flex items-center justify-between mb-5">
<h1 className="text-xl font-semibold text-foreground">
{t('loanOrders.view.title', 'Karz sargyt giriş')}: {order.id}
{t("loanOrders.view.title", "Karz sargyt giriş")}: {order.id}
</h1>
<div className="flex items-center gap-1.5">
<button
onClick={handleDelete}
disabled={deleteMutation.isPending}
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
title={t('common.delete', 'Poz')}
title={t("common.delete", "Poz")}
>
<Trash2 size={16} />
</button>
<button
onClick={() => navigate(`/loan-orders/${order.id}/edit`)}
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Redaktirle')}
title={t("common.edit", "Redaktirle")}
>
<Pencil size={16} />
</button>
@@ -240,156 +160,188 @@ export default function LoanOrderViewPage() {
<div className="bg-card border border-border rounded-xl overflow-hidden mb-6">
<InfoRow label="ID" value={order.id} />
<InfoRow
label={t('loanOrders.columns.createdAt', 'Döredilen wagty')}
label={t("loanOrders.columns.createdAt", "Döredilen wagty")}
value={order.createdAt}
/>
{/* Status row — special render */}
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border">
<span className="text-sm text-muted-foreground">
{t('loanOrders.columns.status', 'Status')}
{t("loanOrders.columns.status", "Status")}
</span>
<LoanOrderMobileStatusBadge status={order.status} />
</div>
<InfoRow
label={t('loanOrders.fields.amount', 'Berlik')}
label={t("loanOrders.fields.amount", "Berlik")}
value={order.amount ? String(order.amount) : undefined}
/>
<InfoRow
label={t('loanOrders.fields.createdBy', 'Sargyt eden')}
label={t("loanOrders.fields.createdBy", "Sargyt eden")}
value={order.createdBy ?? undefined}
isLink
/>
</div>
{/* ── Loan ───────────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.loan', 'Karz')}>
<Section title={t("loanOrders.sections.loan", "Karz")}>
<InfoRow
label={t('loanOrders.columns.loanType', 'Karz görnüşi')}
label={t("loanOrders.columns.loanType", "Karz görnüşi")}
value={order.loanType}
isLink
/>
<InfoRow
label={t('loanOrders.fields.loanAmount', 'Karz mukdary')}
label={t("loanOrders.fields.loanAmount", "Karz mukdary")}
value={order.loanAmount ? String(order.loanAmount) : undefined}
/>
</Section>
{/* ── Location ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.location', 'Lokasiýa')}>
<InfoRow label={t('loanOrders.columns.region', 'Welaýat')} value={order.region} />
<Section title={t("loanOrders.sections.location", "Lokasiýa")}>
<InfoRow
label={t('loanOrders.columns.branch', 'Şahamça')}
label={t("loanOrders.columns.region", "Welaýat")}
value={order.region}
/>
<InfoRow
label={t("loanOrders.columns.branch", "Şahamça")}
value={order.branch}
isLink
/>
</Section>
{/* ── Personal Info ──────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.personal', 'Şahsy maglumatlar')}>
<Section title={t("loanOrders.sections.personal", "Şahsy maglumatlar")}>
<InfoRow
label={t('loanOrders.fields.fullName', 'Doly ady')}
label={t("loanOrders.fields.fullName", "Doly ady")}
value={order.fullName ?? `${order.firstName} ${order.lastName}`}
/>
<InfoRow
label={t('loanOrders.fields.education', 'Bilimi')}
label={t("loanOrders.fields.education", "Bilimi")}
value={order.education ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.maritalStatus', 'Maşgala ýagdaýy')}
label={t("loanOrders.fields.maritalStatus", "Maşgala ýagdaýy")}
value={order.maritalStatus ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.birthDate', 'Doglan güni')}
label={t("loanOrders.fields.birthDate", "Doglan güni")}
value={order.birthDate ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.registeredAddress', 'Ýazgy edilen salgyňyz')}
label={t(
"loanOrders.fields.registeredAddress",
"Ýazgy edilen salgyňyz",
)}
value={order.registeredAddress ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.currentAddress', 'Häzirki ýaşaýyş ýeri')}
label={t("loanOrders.fields.currentAddress", "Häzirki ýaşaýyş ýeri")}
value={order.currentAddress ?? undefined}
/>
</Section>
{/* ── Contacts ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.contacts', 'Habarlaşmak üçin maglumatlar')}>
<Section
title={t(
"loanOrders.sections.contacts",
"Habarlaşmak üçin maglumatlar",
)}
>
<InfoRow
label={t('loanOrders.fields.email', 'E-poçta')}
label={t("loanOrders.fields.email", "E-poçta")}
value={order.email ?? undefined}
/>
<InfoRow label={t('loanOrders.columns.phone', 'Telefon')} value={order.phone} />
<InfoRow
label={t('loanOrders.fields.phoneAlt', 'Telefon goşmaça')}
label={t("loanOrders.columns.phone", "Telefon")}
value={order.phone}
/>
<InfoRow
label={t("loanOrders.fields.phoneAlt", "Telefon goşmaça")}
value={order.phoneAlt ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.homePhone', 'Öý telefony')}
label={t("loanOrders.fields.homePhone", "Öý telefony")}
value={order.homePhone ?? undefined}
/>
</Section>
{/* ── Employment ─────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.employment', 'Iş')}>
<Section title={t("loanOrders.sections.employment", "Iş")}>
<InfoRow
label={t('loanOrders.fields.employer', 'Işleýän edaranyň/kärhananyn ady')}
label={t(
"loanOrders.fields.employer",
"Işleýän edaranyň/kärhananyn ady",
)}
value={order.employer ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.deptPhone', 'Işgärler bölüminiň iş belgisi')}
label={t(
"loanOrders.fields.deptPhone",
"Işgärler bölüminiň iş belgisi",
)}
value={order.deptPhone ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.workRegion', 'Işleýän welaýatyňyz')}
label={t("loanOrders.fields.workRegion", "Işleýän welaýatyňyz")}
value={order.workRegion ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.workCity', 'Işleýän etrabyňyz')}
label={t("loanOrders.fields.workCity", "Işleýän etrabyňyz")}
value={order.workCity ?? undefined}
isLink
/>
<InfoRow
label={t('loanOrders.fields.position', 'Wezipe')}
label={t("loanOrders.fields.position", "Wezipe")}
value={order.position ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.salary', 'Zähmet haky')}
label={t("loanOrders.fields.salary", "Zähmet haky")}
value={order.salary ? String(order.salary) : undefined}
/>
<InfoRow
label={t('loanOrders.fields.employedSince', 'Işe başlan wagtyňyz')}
label={t("loanOrders.fields.employedSince", "Işe başlan wagtyňyz")}
value={order.employedSince ?? undefined}
/>
</Section>
{/* ── Passport ───────────────────────────────────────────────────────── */}
<Section title={t('loanOrders.sections.passport', 'Pasport')}>
<Section title={t("loanOrders.sections.passport", "Pasport")}>
<InfoRow
label={t('loanOrders.fields.passportNumber', 'Pasport')}
label={t("loanOrders.fields.passportNumber", "Pasport")}
value={order.passportNumber ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.passportIssuedBy', 'Kim tarapyndan berildi')}
label={t(
"loanOrders.fields.passportIssuedBy",
"Kim tarapyndan berildi",
)}
value={order.passportIssuedBy ?? undefined}
/>
<InfoRow
label={t('loanOrders.fields.passportBirthPlace', 'Doglan ýeri (pasport)')}
label={t(
"loanOrders.fields.passportBirthPlace",
"Doglan ýeri (pasport)",
)}
value={order.passportBirthPlace ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage1', 'Pasport (sahypa 1)')}
label={t("loanOrders.fields.passportPage1", "Pasport (sahypa 1)")}
src={order.passportPage1Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage23', 'Pasport (2-3-nji sahypa)')}
label={t(
"loanOrders.fields.passportPage23",
"Pasport (2-3-nji sahypa)",
)}
src={order.passportPage23Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage89', 'Pasport (8-9 sahypa)')}
label={t("loanOrders.fields.passportPage89", "Pasport (8-9 sahypa)")}
src={order.passportPage89Url ?? undefined}
/>
<PassportImage
label={t('loanOrders.fields.passportPage32', 'Pasport (32-nji sahypa)')}
label={t(
"loanOrders.fields.passportPage32",
"Pasport (32-nji sahypa)",
)}
src={order.passportPage32Url ?? undefined}
/>
</Section>
@@ -398,7 +350,7 @@ export default function LoanOrderViewPage() {
<div className="mb-6">
<details open>
<summary className="text-base font-semibold text-foreground mb-2 cursor-pointer select-none list-none flex items-center gap-1.5 w-fit">
{t('loanOrders.sections.audit', 'Ammallar')}
{t("loanOrders.sections.audit", "Ammallar")}
<ChevronRight size={15} className="text-muted-foreground" />
</summary>
<div className="bg-card border border-border rounded-xl overflow-hidden mt-2">
@@ -407,13 +359,13 @@ export default function LoanOrderViewPage() {
<thead>
<tr className="border-b border-border bg-muted/30">
{[
'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) => (
<th
key={i}
@@ -432,14 +384,15 @@ export default function LoanOrderViewPage() {
</table>
</div>
<div className="flex items-center justify-between px-4 py-2.5 border-t border-border text-xs text-muted-foreground">
<span>{t('common.prev', 'Öňki')}</span>
<span>1–{auditLogs.length} / {auditLogs.length}</span>
<span>{t('common.next', 'Soňky')}</span>
<span>{t("common.prev", "Öňki")}</span>
<span>
1–{auditLogs.length} / {auditLogs.length}
</span>
<span>{t("common.next", "Soňky")}</span>
</div>
</div>
</details>
</div>
</div>
)
}
);
}

View File

@@ -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 (
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
<span className="text-sm text-muted-foreground">{label}</span>
{value ? (
<span className="text-sm text-foreground">
{value}
</span>
) : (
<span className="text-muted-foreground/40 text-sm">—</span>
)}
</div>
)
}
// ─── Section ─────────────────────────────────────────────────────────────────
function Section({ title, children }: SectionProps) {
return (
<div className="mb-6">
<h2 className="text-base font-semibold text-foreground mb-2">{title}</h2>
<div className="bg-card border border-border rounded-xl overflow-hidden">{children}</div>
</div>
)
}
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() {
))}
</div>
</div>
)
);
}
// ─── 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 <LoanRemainingViewSkeleton />
if (isLoading) return <LoanRemainingViewSkeleton />;
if (!record) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
{t('common.notFound', 'Tapylmady')}
{t("common.notFound", "Tapylmady")}
</div>
)
);
}
return (
@@ -98,21 +72,22 @@ export default function LoanRemainingViewPage() {
{/* Page Header */}
<div className="flex items-center justify-between mb-5">
<h1 className="text-xl font-semibold text-foreground">
{t('loanRemaining.view.title', 'Karz galyndysy maglumaty')}: {record.id}
{t("loanRemaining.view.title", "Karz galyndysy maglumaty")}:{" "}
{record.id}
</h1>
<div className="flex items-center gap-1.5">
<button
onClick={handleDelete}
disabled={deleteMutation.isPending}
className="p-2 rounded-md cursor-pointer hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
title={t('common.delete', 'Poz')}
title={t("common.delete", "Poz")}
>
<Trash2 size={16} />
</button>
<button
onClick={() => navigate(`/loan-remaining/${record.id}/edit`)}
className="p-2 rounded-md cursor-pointer hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
title={t('common.edit', 'Redaktirle')}
title={t("common.edit", "Redaktirle")}
>
<Pencil size={16} />
</button>
@@ -120,21 +95,21 @@ export default function LoanRemainingViewPage() {
</div>
{/* ── Basic Info ─────────────────────────────────────────────────────── */}
<Section title={t('loanRemaining.sections.info', 'Esasy maglumatlar')}>
<Section title={t("loanRemaining.sections.info", "Esasy maglumatlar")}>
<InfoRow label="ID" value={String(record.id)} />
<InfoRow
label={t('loanRemaining.columns.passportSeries', 'Pasport seriýasy')}
label={t("loanRemaining.columns.passportSeries", "Pasport seriýasy")}
value={record.passportSeries}
/>
<InfoRow
label={t('loanRemaining.columns.passportNumber', 'Pasport belgisi')}
label={t("loanRemaining.columns.passportNumber", "Pasport belgisi")}
value={record.passportNumber}
/>
<InfoRow
label={t('loanRemaining.columns.loanAccount', 'Karz hasaby')}
label={t("loanRemaining.columns.loanAccount", "Karz hasaby")}
value={record.loanAccount}
/>
</Section>
</div>
)
);
}