refactored some view pages

This commit is contained in:
@jcarymuhammedow
2026-06-04 17:36:57 +05:00
parent ef9d6201eb
commit 84c5ff4153
4 changed files with 234 additions and 350 deletions

View File

@@ -1,9 +1,6 @@
import { useParams, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import {
useCardPin,
useDeleteCardPin,
} from "@/features/cardPins/hooks/useCardPins";
import { useCardPin, useDeleteCardPin } from "@/features/cardPins/hooks/useCardPins";
import type { CardPinStatus } from "@/features/cardPins/api/cardPinApi";
import { Skeleton } from "@/components/ui/skeleton";
import { Button } from "@/components/ui/button";
@@ -18,33 +15,30 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import {
StatusBadge,
type StatusBadgeVariant,
} from "@/components/ui/statusBadge";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { BentoGrid, BentoCard, InfoRow, PassportImage } from "@/components/viewPageComponents";
// ─── Status config ────────────────────────────────────────────────────────────
const STATUS_VARIANT: Record<CardPinStatus, StatusBadgeVariant> = {
pending: "warning",
pending: "warning",
approved: "success",
rejected: "error",
}
};
const STATUS_ICON: Record<CardPinStatus, React.ElementType> = {
pending: AlertCircle,
pending: AlertCircle,
approved: CheckCircle2,
rejected: XCircle,
}
};
function CardPinStatusBadge({ status }: { status: CardPinStatus }) {
const { t } = useTranslation()
const variant = STATUS_VARIANT[status]
const Icon = STATUS_ICON[status]
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>
return <StatusBadge label={t(`cardPin.status.${status}`)} variant={variant} icon={Icon} />
const { t } = useTranslation();
const variant = STATUS_VARIANT[status];
const Icon = STATUS_ICON[status];
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>;
return <StatusBadge label={t(`cardPin.status.${status}`)} variant={variant} icon={Icon} />;
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
@@ -64,34 +58,29 @@ function CardPinViewSkeleton() {
))}
</div>
</div>
)
);
}
// ─── 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 <CardPinViewSkeleton />
return <CardPinViewSkeleton />;
}
if (isError || !data) {
return (
<div className="flex items-center justify-center py-24 text-muted-foreground">
{t("common.notFound", "Maglumat tapylmady")}
</div>
)
return <div className="flex items-center justify-center py-24 text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
}
return (
<div className="mx-auto flex flex-col gap-6">
{/* ── Page header ──────────────────────────────────────────────────── */}
<div className="flex items-start justify-between">
<h1 className="text-xl font-bold text-foreground">
@@ -100,28 +89,19 @@ export default function CardPinViewPage() {
<div className="flex items-center gap-2">
<AlertDialog>
<AlertDialogTitle 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>
</AlertDialogTitle>
<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")}
</AlertDialogCancel>
<AlertDialogCancel disabled={isDeleting}>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
disabled={isDeleting}
className="bg-destructive hover:bg-destructive/90"
@@ -133,12 +113,7 @@ export default function CardPinViewPage() {
</AlertDialogContent>
</AlertDialog>
<Button
size="icon"
variant="ghost"
className="h-8 w-8"
onClick={() => navigate(`/card-pins/${id}/edit`)}
>
<Button size="icon" variant="ghost" className="h-8 w-8" onClick={() => navigate(`/card-pins/${id}/edit`)}>
<Pencil size={15} />
</Button>
</div>
@@ -147,97 +122,56 @@ export default function CardPinViewPage() {
{/* ── Row 1: Meta + Kart + Lokasiýa ───────────────────────────────── */}
<BentoGrid cols={3}>
<BentoCard title={t("cardPin.metaSection", "Esasy maglumatlar")}>
<InfoRow label={t("common.id", "ID")}>
<span className="font-mono">{data.id}</span>
</InfoRow>
<InfoRow label={t("cardPin.createdAt", "Döredilen wagty")}>
{data.created_at}
</InfoRow>
<InfoRow label={t("common.id", "ID")} value={data.id} />
<InfoRow label={t("cardPin.createdAt", "Döredilen wagty")} value={data.created_at} />
<InfoRow label={t("cardPin.status", "Status")}>
<CardPinStatusBadge status={data.status} />
</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>
<InfoRow label={t("cardPin.note", "Bellik")} value={data.note || undefined} />
<InfoRow label={t("cardPin.createdBy", "Sargyt eden")} value={data.created_by_label} isLink />
</BentoCard>
<BentoCard title={t("cardPin.cardSection", "Kart")}>
<InfoRow label={t("cardPin.cardNumber", "Kart belgisi")}>
<span className="font-mono tracking-wider">{data.card_number}</span>
</InfoRow>
<InfoRow label={t("cardPin.cardExpireMonth", "Kart Möhleti (aý)")}>
—
</InfoRow>
<InfoRow label={t("cardPin.cardExpireYear", "Kart Möhleti (ýyl)")}>
—
</InfoRow>
<InfoRow label={t("cardPin.cardNumber", "Kart belgisi")} value={data.card_number} />
<InfoRow label={t("cardPin.cardExpireMonth", "Kart Möhleti (aý)")} value={null} />
<InfoRow label={t("cardPin.cardExpireYear", "Kart Möhleti (ýyl)")} value={null} />
</BentoCard>
<BentoCard title={t("cardPin.locationSection", "Lokasiýa")}>
<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>
<InfoRow label={t("cardPin.province", "Welaýat")} value={data.province_label} />
<InfoRow label={t("cardPin.branch", "Şahamça")} value={data.branch_label} isLink />
</BentoCard>
</BentoGrid>
{/* ── Row 2: Şahsy + Pasport maglumatlary ─────────────────────────── */}
<BentoGrid cols={2}>
<BentoCard title={t("cardPin.personalSection", "Şahsy maglumatlar")}>
<InfoRow label={t("cardPin.fullName", "Doly ady")}>
{`${data.last_name} ${data.first_name} ${data.father_name}`}
</InfoRow>
<InfoRow label={t("cardPin.birthDate", "Doglan güni")}>
{data.birth_date}
</InfoRow>
<InfoRow label={t("cardPin.phone", "Telefon")}>
+{data.phone}
</InfoRow>
<InfoRow label={t("cardPin.fullName", "Doly ady")} value={`${data.last_name} ${data.first_name} ${data.father_name}`} />
<InfoRow label={t("cardPin.birthDate", "Doglan güni")} value={data.birth_date} />
<InfoRow label={t("cardPin.phone", "Telefon")} value={`+${data.phone}`} />
</BentoCard>
<BentoCard title={t("cardPin.passportSection", "Pasport")}>
<InfoRow label={t("cardPin.passportSeries", "Pasport seriýasy")}>
{data.passport_series}
</InfoRow>
<InfoRow label={t("cardPin.passportNumber", "Pasport belgisi")}>
{data.passport_number}
</InfoRow>
<InfoRow label={t("cardPin.passportSeries", "Pasport seriýasy")} value={data.passport_series} />
<InfoRow label={t("cardPin.passportNumber", "Pasport belgisi")} value={data.passport_number} />
</BentoCard>
</BentoGrid>
{/* ── Row 3: Passport images ───────────────────────────────────────── */}
<BentoGrid cols={4}>
<BentoCard title={t("cardPin.passportFile1", "Sahypa 1")}>
<PassportImage
label={t("cardPin.passportFile1", "Pasport (sahypa 1)")}
url={data.passport_file_1}
/>
<PassportImage label={t("cardPin.passportFile1", "Pasport (sahypa 1)")} url={data.passport_file_1} />
</BentoCard>
<BentoCard title={t("cardPin.passportFile2", "Sahypa 2-3")}>
<PassportImage
label={t("cardPin.passportFile2", "Pasport (2-3-nji sahypa)")}
url={data.passport_file_2}
/>
<PassportImage label={t("cardPin.passportFile2", "Pasport (2-3-nji sahypa)")} url={data.passport_file_2} />
</BentoCard>
<BentoCard title={t("cardPin.passportFile3", "Sahypa 8-9")}>
<PassportImage
label={t("cardPin.passportFile3", "Pasport (8-9 sahypa)")}
url={data.passport_file_3}
/>
<PassportImage label={t("cardPin.passportFile3", "Pasport (8-9 sahypa)")} url={data.passport_file_3} />
</BentoCard>
<BentoCard title={t("cardPin.passportFile4", "Sahypa 32")}>
<PassportImage
label={t("cardPin.passportFile4", "Pasport (32-nji sahypa)")}
url={data.passport_file_4}
/>
<PassportImage label={t("cardPin.passportFile4", "Pasport (32-nji sahypa)")} url={data.passport_file_4} />
</BentoCard>
</BentoGrid>
</div>
)
}
);
}

View File

@@ -1,10 +1,6 @@
import { useParams, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import {
useCardRequisite,
useDeleteCardRequisite,
useDownloadCardRequisite,
} from "@/features/cardRequisites/hooks/useCardRequisites";
import { useCardRequisite, useDeleteCardRequisite, useDownloadCardRequisite } from "@/features/cardRequisites/hooks/useCardRequisites";
import type { CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi";
import { Skeleton } from "@/components/ui/skeleton";
import { Button } from "@/components/ui/button";
@@ -19,33 +15,30 @@ import {
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import {
StatusBadge,
type StatusBadgeVariant,
} from "@/components/ui/statusBadge";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { BentoGrid, BentoCard, InfoRow, PassportImage } from "@/components/viewPageComponents";
// ─── Status config ────────────────────────────────────────────────────────────
const STATUS_VARIANT: Record<CardRequisiteStatus, StatusBadgeVariant> = {
pending: "warning",
pending: "warning",
approved: "success",
rejected: "error",
}
};
const STATUS_ICON: Record<CardRequisiteStatus, React.ElementType> = {
pending: AlertCircle,
pending: AlertCircle,
approved: CheckCircle2,
rejected: XCircle,
}
};
function CardRequisiteStatusBadge({ status }: { status: CardRequisiteStatus }) {
const { t } = useTranslation()
const variant = STATUS_VARIANT[status]
const Icon = STATUS_ICON[status]
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>
return <StatusBadge label={t(`cardRequisite.status.${status}`)} variant={variant} icon={Icon} />
const { t } = useTranslation();
const variant = STATUS_VARIANT[status];
const Icon = STATUS_ICON[status];
if (!variant) return <span className="text-xs text-muted-foreground">{status}</span>;
return <StatusBadge label={t(`cardRequisite.status.${status}`)} variant={variant} icon={Icon} />;
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
@@ -65,35 +58,30 @@ function CardRequisiteViewSkeleton() {
))}
</div>
</div>
)
);
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function CardRequisiteViewPage() {
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 } = useCardRequisite(id ?? "")
const deleteMutation = useDeleteCardRequisite()
const downloadMutation = useDownloadCardRequisite()
const { data, isLoading, isError } = useCardRequisite(id ?? "");
const deleteMutation = useDeleteCardRequisite();
const downloadMutation = useDownloadCardRequisite();
if (isLoading) {
return <CardRequisiteViewSkeleton />
return <CardRequisiteViewSkeleton />;
}
if (isError || !data) {
return (
<div className="flex items-center justify-center py-24 text-muted-foreground">
{t("common.notFound", "Maglumat tapylmady")}
</div>
)
return <div className="flex items-center justify-center py-24 text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
}
return (
<div className="mx-auto flex flex-col gap-6">
{/* ── Page header ──────────────────────────────────────────────────── */}
<div className="flex items-start justify-between">
<h1 className="text-xl font-bold text-foreground">
@@ -101,7 +89,8 @@ export default function CardRequisiteViewPage() {
</h1>
<div className="flex items-center gap-2">
<Button
size="icon" variant="ghost"
size="icon"
variant="ghost"
className="h-8 w-8"
onClick={() => downloadMutation.mutate(data.id)}
disabled={downloadMutation.isPending}
@@ -110,27 +99,19 @@ export default function CardRequisiteViewPage() {
</Button>
<AlertDialog>
<AlertDialogTitle 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>
</AlertDialogTitle>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
{t("cardRequisite.deleteTitle", "Pozmak isleýärsiňizmi?")}
</AlertDialogTitle>
<AlertDialogTitle>{t("cardRequisite.deleteTitle", "Pozmak isleýärsiňizmi?")}</AlertDialogTitle>
<AlertDialogDescription>
{t("cardRequisite.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} {data.id}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={deleteMutation.isPending}>
{t("common.cancel", "Ýatyr")}
</AlertDialogCancel>
<AlertDialogCancel disabled={deleteMutation.isPending}>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
disabled={deleteMutation.isPending}
className="bg-destructive hover:bg-destructive/90"
@@ -142,10 +123,7 @@ export default function CardRequisiteViewPage() {
</AlertDialogContent>
</AlertDialog>
<Button
size="icon" variant="ghost" className="h-8 w-8"
onClick={() => navigate(`/card-requisites/${id}/edit`)}
>
<Button size="icon" variant="ghost" className="h-8 w-8" onClick={() => navigate(`/card-requisites/${id}/edit`)}>
<Pencil size={15} />
</Button>
</div>
@@ -154,101 +132,63 @@ export default function CardRequisiteViewPage() {
{/* ── Row 1: Meta + Kart + Lokasiýa ────────────────────────────────── */}
<BentoGrid cols={3}>
<BentoCard title={t("cardRequisite.metaSection", "Esasy maglumatlar")}>
<InfoRow label={t("common.id", "ID")}>
<span className="font-mono">{data.id}</span>
</InfoRow>
<InfoRow label={t("cardRequisite.createdAt", "Döredilen wagty")}>
{data.created_at}
</InfoRow>
<InfoRow label={t("common.id", "ID")} value={data.id} />
<InfoRow label={t("cardRequisite.createdAt", "Döredilen wagty")} value={data.created_at} />
<InfoRow label={t("cardRequisite.status", "Status")}>
<CardRequisiteStatusBadge status={data.status} />
</InfoRow>
<InfoRow label={t("cardRequisite.note", "Bellik")}>
{data.note || "—"}
</InfoRow>
<InfoRow label={t("cardRequisite.createdBy", "Sargyt eden")}>
{data.first_name && data.last_name ? (
<span className="text-primary font-medium">
{data.last_name}_{data.first_name}
</span>
) : "—"}
</InfoRow>
<InfoRow label={t("cardRequisite.note", "Bellik")} value={data.note || undefined} />
<InfoRow
label={t("cardRequisite.createdBy", "Sargyt eden")}
value={data.first_name && data.last_name ? `${data.last_name}_${data.first_name}` : undefined}
isLink
/>
</BentoCard>
<BentoCard title={t("cardRequisite.cardSection", "Kart")}>
<InfoRow label={t("cardRequisite.cardNumber", "Kart belgisi")}>
<span className="font-mono tracking-wider">{data.card_number}</span>
</InfoRow>
<InfoRow label={t("cardRequisite.cardExpireMonth", "Kart Möhleti (aý)")}>
{data.card_expiry_month}
</InfoRow>
<InfoRow label={t("cardRequisite.cardExpireYear", "Kart Möhleti (ýyl)")}>
{data.card_expiry_year}
</InfoRow>
<InfoRow label={t("cardRequisite.cardNumber", "Kart belgisi")} value={data.card_number} />
<InfoRow label={t("cardRequisite.cardExpireMonth", "Kart Möhleti (aý)")} value={data.card_expiry_month} />
<InfoRow label={t("cardRequisite.cardExpireYear", "Kart Möhleti (ýyl)")} value={data.card_expiry_year} />
</BentoCard>
<BentoCard title={t("cardRequisite.locationSection", "Lokasiýa")}>
<InfoRow label={t("cardRequisite.province", "Welaýat")}>
{data.province_name ?? "—"}
</InfoRow>
<InfoRow label={t("cardRequisite.branch", "Şahamça")}>
<span className="text-primary font-medium">{data.branch_name ?? "—"}</span>
</InfoRow>
<InfoRow label={t("cardRequisite.province", "Welaýat")} value={data.province_name ?? undefined} />
<InfoRow label={t("cardRequisite.branch", "Şahamça")} value={data.branch_name ?? undefined} isLink />
</BentoCard>
</BentoGrid>
{/* ── Row 2: Şahsy + Pasport maglumatlary ──────────────────────────── */}
<BentoGrid cols={2}>
<BentoCard title={t("cardRequisite.personalSection", "Şahsy maglumatlar")}>
<InfoRow label={t("cardRequisite.fullName", "Doly ady")}>
{[data.first_name, data.last_name, data.middle_name].filter(Boolean).join(" ")}
</InfoRow>
<InfoRow label={t("cardRequisite.birthDate", "Doglan güni")}>
{data.birth_date}
</InfoRow>
<InfoRow label={t("cardRequisite.phone", "Telefon")}>
{data.phone}
</InfoRow>
<InfoRow
label={t("cardRequisite.fullName", "Doly ady")}
value={[data.first_name, data.last_name, data.middle_name].filter(Boolean).join(" ")}
/>
<InfoRow label={t("cardRequisite.birthDate", "Doglan güni")} value={data.birth_date} />
<InfoRow label={t("cardRequisite.phone", "Telefon")} value={data.phone} />
</BentoCard>
<BentoCard title={t("cardRequisite.passportSection", "Pasport")}>
<InfoRow label={t("cardRequisite.passportSeries", "Pasport seriýasy")}>
{data.passport_series}
</InfoRow>
<InfoRow label={t("cardRequisite.passportNumber", "Pasport belgisi")}>
{data.passport_number}
</InfoRow>
<InfoRow label={t("cardRequisite.passportSeries", "Pasport seriýasy")} value={data.passport_series} />
<InfoRow label={t("cardRequisite.passportNumber", "Pasport belgisi")} value={data.passport_number} />
</BentoCard>
</BentoGrid>
{/* ── Row 3: Passport images ────────────────────────────────────────── */}
<BentoGrid cols={4}>
<BentoCard title={t("cardRequisite.passportFile1", "Sahypa 1")}>
<PassportImage
label={t("cardRequisite.passportFile1", "Pasport (sahypa 1)")}
src={data.passport_page1_url}
/>
<PassportImage label={t("cardRequisite.passportFile1", "Pasport (sahypa 1)")} src={data.passport_page1_url} />
</BentoCard>
<BentoCard title={t("cardRequisite.passportFile2", "Sahypa 2-3")}>
<PassportImage
label={t("cardRequisite.passportFile2", "Pasport (2-3-nji sahypa)")}
src={data.passport_page2_3_url}
/>
<PassportImage label={t("cardRequisite.passportFile2", "Pasport (2-3-nji sahypa)")} src={data.passport_page2_3_url} />
</BentoCard>
<BentoCard title={t("cardRequisite.passportFile3", "Sahypa 8-9")}>
<PassportImage
label={t("cardRequisite.passportFile3", "Pasport (8-9 sahypa)")}
src={data.passport_page8_9_url}
/>
<PassportImage label={t("cardRequisite.passportFile3", "Pasport (8-9 sahypa)")} src={data.passport_page8_9_url} />
</BentoCard>
<BentoCard title={t("cardRequisite.passportFile4", "Sahypa 32")}>
<PassportImage
label={t("cardRequisite.passportFile4", "Pasport (32-nji sahypa)")}
src={data.passport_page32_url}
/>
<PassportImage label={t("cardRequisite.passportFile4", "Pasport (32-nji sahypa)")} src={data.passport_page32_url} />
</BentoCard>
</BentoGrid>
</div>
)
);
}

View File

@@ -111,8 +111,8 @@ export default function CardOrderDetailPage() {
{/* ── Row 1: Meta + Kart + Lokasiýa ───────────────────────────────── */}
<BentoGrid cols={3}>
<BentoCard title={t("cardOrder.section.meta", "Esasy maglumatlar")}>
<InfoRow label={t("common.id", "ID")}>{order.id}</InfoRow>
<InfoRow label={t("cardOrder.field.createdAt", "Döredilen wagty")}>{order.createdAt}</InfoRow>
<InfoRow label={t("common.id", "ID")} value={order.id} />
<InfoRow label={t("cardOrder.field.createdAt", "Döredilen wagty")} value={order.createdAt} />
<InfoRow label={t("cardOrder.field.status", "Status")}>
<CardOrderStatusBadge status={order.status} />
</InfoRow>
@@ -123,45 +123,38 @@ export default function CardOrderDetailPage() {
{order.isPaid ? "✓" : "✕"}
</span>
</InfoRow>
<InfoRow label={t("cardOrder.field.note", "Bellik")}>{order.note ?? "—"}</InfoRow>
<InfoRow label={t("cardOrder.field.createdBy", "Sargyt eden")}>
<span className="text-primary font-medium">{order.createdBy}</span>
</InfoRow>
<InfoRow label={t("cardOrder.field.note", "Bellik")} value={order.note ?? undefined} />
<InfoRow label={t("cardOrder.field.createdBy", "Sargyt eden")} value={order.createdBy} isLink />
</BentoCard>
<BentoCard 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>
<InfoRow label={t("cardOrder.field.issuanceReason", "Kartyň çykarylmagynyň sebäbi")} value={order.issuanceReasonName} isLink />
<InfoRow label={t("cardOrder.field.cardType", "Kart görnüşi")} value={order.cardTypeName} />
</BentoCard>
<BentoCard 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")}>
<span className="text-cyan-400 font-medium">{order.branchName}</span>
</InfoRow>
<InfoRow label={t("cardOrder.field.province", "Welaýat")} value={order.provinceName} />
<InfoRow label={t("cardOrder.field.branch", "Şahamça")} value={order.branchName} />
</BentoCard>
</BentoGrid>
{/* ── Row 2: Şahsy maglumatlar (full width — many fields) ─────────── */}
<BentoGrid cols={2}>
<BentoCard 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")}>{order.birthDate}</InfoRow>
<InfoRow label={t("cardOrder.field.citizenship", "Raýatlyk")}>{order.citizenship}</InfoRow>
<InfoRow label={t("cardOrder.field.registeredAddress", "Ýazgy edilen salgy")}>{order.registeredAddress}</InfoRow>
<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 we wezipesi")}>{order.workplace}</InfoRow>
<InfoRow
label={t("cardOrder.field.fullName", "Doly ady")}
value={[order.lastName, order.firstName, order.middleName].filter(Boolean).join(" ")}
/>
<InfoRow label={t("cardOrder.field.birthDate", "Doglan güni")} value={order.birthDate} />
<InfoRow label={t("cardOrder.field.citizenship", "Raýatlyk")} value={order.citizenship} />
<InfoRow label={t("cardOrder.field.registeredAddress", "Ýazgy edilen salgy")} value={order.registeredAddress} />
<InfoRow label={t("cardOrder.field.currentAddress", "Häzirki ýaşaýyş ýeri")} value={order.currentAddress} />
<InfoRow label={t("cardOrder.field.workplace", "Işleýän ýeri we wezipesi")} value={order.workplace} />
</BentoCard>
<BentoCard title={t("cardOrder.section.contacts", "Kontakt")}>
<InfoRow label={t("cardOrder.field.phone", "Telefon")}>{order.phone}</InfoRow>
<InfoRow label={t("cardOrder.field.phoneExtra", "Telefon goşmaça")}>{order.phoneExtra ?? "—"}</InfoRow>
<InfoRow label={t("cardOrder.field.phone", "Telefon")} value={order.phone} />
<InfoRow label={t("cardOrder.field.phoneExtra", "Telefon goşmaça")} value={order.phoneExtra ?? undefined} />
</BentoCard>
</BentoGrid>

View File

@@ -1,46 +1,47 @@
import { useState } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Pencil, Trash2, Download, Search, AlertCircle, CheckCircle2, XCircle } from 'lucide-react'
import { ConfirmDialog } from '@/components/confirmDialog'
import { Skeleton } from '@/components/ui/skeleton'
import { StatusBadge, type StatusBadgeVariant } from '@/components/ui/statusBadge'
import { BentoGrid, BentoCard, InfoRow } from '@/components/viewPageComponents'
import { useIntlPayment, useDeleteIntlPayment } from '@/features/visaMasterPayments/hooks/useVisaMasterPayments'
import type { IntlPaymentStatus } from '@/features/visaMasterPayments/api/visaMasterPaymentsApi'
import { useState } from "react";
import { useParams, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Pencil, Trash2, Download, Search, AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { ConfirmDialog } from "@/components/confirmDialog";
import { Skeleton } from "@/components/ui/skeleton";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
import { useIntlPayment, useDeleteIntlPayment } from "@/features/visaMasterPayments/hooks/useVisaMasterPayments";
import type { IntlPaymentStatus } from "@/features/visaMasterPayments/api/visaMasterPaymentsApi";
// ─── Status config ────────────────────────────────────────────────────────────
const STATUS_VARIANT: Record<IntlPaymentStatus, StatusBadgeVariant> = {
pending: 'warning',
approved: 'success',
rejected: 'error',
}
pending: "warning",
approved: "success",
rejected: "error",
};
const STATUS_ICON: Record<IntlPaymentStatus, React.ElementType> = {
pending: AlertCircle,
pending: AlertCircle,
approved: CheckCircle2,
rejected: XCircle,
}
};
function PaymentStatusBadge({ status }: { status: IntlPaymentStatus }) {
const { t } = useTranslation()
const variant = STATUS_VARIANT[status] ?? STATUS_VARIANT.pending
const Icon = STATUS_ICON[status] ?? STATUS_ICON.pending
return <StatusBadge label={t(`intlPayment.status.${status}`)} variant={variant} icon={Icon} />
const { t } = useTranslation();
const variant = STATUS_VARIANT[status] ?? STATUS_VARIANT.pending;
const Icon = STATUS_ICON[status] ?? STATUS_ICON.pending;
return <StatusBadge label={t(`intlPayment.status.${status}`)} variant={variant} icon={Icon} />;
}
// ─── DocFile row ──────────────────────────────────────────────────────────────
function DocFileRow({ label, url }: { label: string; url: string | null }) {
if (!url) return (
<InfoRow label={label}>
<span className="text-muted-foreground/50">—</span>
</InfoRow>
)
if (!url)
return (
<InfoRow label={label}>
<span className="text-muted-foreground/50">—</span>
</InfoRow>
);
const filename = url.split('/').pop() ?? 'faýl'
const isImage = /\.(jpg|jpeg|png|gif|webp)$/i.test(url)
const filename = url.split("/").pop() ?? "faýl";
const isImage = /\.(jpg|jpeg|png|gif|webp)$/i.test(url);
return (
<InfoRow label={label}>
@@ -66,7 +67,7 @@ function DocFileRow({ label, url }: { label: string; url: string | null }) {
</a>
</div>
</InfoRow>
)
);
}
// ─── Skeleton ─────────────────────────────────────────────────────────────────
@@ -86,68 +87,92 @@ function IntlPaymentViewSkeleton() {
))}
</div>
</div>
)
);
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function IntlPaymentViewPage() {
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { t } = useTranslation()
const [historySearch, setHistorySearch] = useState('')
const [deleteOpen, setDeleteOpen] = useState(false)
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const { t } = useTranslation();
const [historySearch, setHistorySearch] = useState("");
const [deleteOpen, setDeleteOpen] = useState(false);
const { data, isLoading, isError } = useIntlPayment(id!)
const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment()
const { data, isLoading, isError } = useIntlPayment(id!);
const { mutate: deletePayment, isPending: isDeleting } = useDeleteIntlPayment();
const confirmDelete = () => {
deletePayment(data!.id, { onSuccess: () => navigate('/intl-payments/visa-master') })
}
deletePayment(data!.id, { onSuccess: () => navigate("/intl-payments/visa-master") });
};
if (isLoading) return <IntlPaymentViewSkeleton />
if (isLoading) return <IntlPaymentViewSkeleton />;
if (isError || !data) {
return (
<div className="flex items-center justify-center h-64 text-muted-foreground text-sm">
{t('common.notFound', 'Maglumat tapylmady')}
{t("common.notFound", "Maglumat tapylmady")}
</div>
)
);
}
const KABUL_DOCS = [
{ label: 'Talypyň degişli welaýata "SBERBANK" kartyň rekwizitleri', url: data.doc_sberbank_account },
{ label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy', url: data.doc_school_enrollment },
{ label: 'Talypyň bilendiriň göçürmesi', url: data.doc_summons },
{ label: 'Talypyň degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', url: data.doc_passport_tm },
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi', url: data.doc_foreign_passport },
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurtda galan döwründe bakýan döwleti baradaky bellenen sahypasynyň göçürmesi', url: data.doc_foreign_passport_copy },
{ label: 'Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň dowletiniň girmesiz baradaky bellenen sahypasynyň göçürmesi', url: data.doc_exit_permission },
{ label: 'Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy barada maglumatlary daşary ýurt döwletiniň ýokary okuw mekdebinden haty', url: data.doc_school_foreign_info },
{ label: 'Talypyň daşary ýurt döwletinde okaýandygy baradaky güwänamany daşary ýurt döwletiniň ýokary okuw mekdebinden haty', url: data.doc_school_departure_info },
]
{ label: 'Talypyň degişli welaýata "SBERBANK" kartyň rekwizitleri', url: data.doc_sberbank_account },
{ label: "Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy baradaky güwänamasy", url: data.doc_school_enrollment },
{ label: "Talypyň bilendiriň göçürmesi", url: data.doc_summons },
{ label: "Talypyň degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi", url: data.doc_passport_tm },
{ label: "Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi", url: data.doc_foreign_passport },
{
label:
"Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurtda galan döwründe bakýan döwleti baradaky bellenen sahypasynyň göçürmesi",
url: data.doc_foreign_passport_copy,
},
{
label:
"Talypyň Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň dowletiniň girmesiz baradaky bellenen sahypasynyň göçürmesi",
url: data.doc_exit_permission,
},
{
label:
"Talypyň daşary ýurt döwletiniň ýokary okuw mekdebinde okaýandygy barada maglumatlary daşary ýurt döwletiniň ýokary okuw mekdebinden haty",
url: data.doc_school_foreign_info,
},
{
label: "Talypyň daşary ýurt döwletinde okaýandygy baradaky güwänamany daşary ýurt döwletiniň ýokary okuw mekdebinden haty",
url: data.doc_school_departure_info,
},
];
const UPGRAD_DOCS = [
{ label: 'Upgradyý degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi', url: data.upd_doc_passport_tm },
{ label: 'Upgradyý degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi', url: data.upd_doc_foreign_passport },
{ label: 'Upgradyý Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurt döwletinde galýandygy baradaky şaýmynyň bellenen sahypasynyň göçürmesi', url: data.upd_doc_visa },
{ label: 'Upgradyýyň we kabul edijiniň resminamalarynyň göçürmesi', url: data.upd_doc_acceptance_letter },
{ label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky maglumatlary', url: data.upd_doc_passport_biometric },
{ label: 'Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky göwnamasy', url: data.upd_doc_passport_old },
]
{ label: "Upgradyý degişli Türkmenistanyň raýatynyň içki milli pasportynyň asyl görnüşi we göçürmesi", url: data.upd_doc_passport_tm },
{
label: "Upgradyý degişli Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň göçürmesi",
url: data.upd_doc_foreign_passport,
},
{
label:
"Upgradyý Türkmenistandan çykmak we Türkmenistana girmek üçin pasportynyň daşary ýurt döwletinde galýandygy baradaky şaýmynyň bellenen sahypasynyň göçürmesi",
url: data.upd_doc_visa,
},
{ label: "Upgradyýyň we kabul edijiniň resminamalarynyň göçürmesi", url: data.upd_doc_acceptance_letter },
{
label: "Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky maglumatlary",
url: data.upd_doc_passport_biometric,
},
{ label: "Upgradyý we kabul ediji täze 2015-nji ýyldan soňra pasportynyň seriýasy baradaky göwnamasy", url: data.upd_doc_passport_old },
];
return (
<div className="flex flex-col gap-6">
{/* ── Page header ──────────────────────────────────────────────────── */}
<div className="flex items-center justify-between">
<h1 className="text-xl font-semibold text-foreground">
{t('intlPayment.viewTitle', 'Halkara töleg')}: {data.id}
{t("intlPayment.viewTitle", "Halkara töleg")}: {data.id}
</h1>
<div className="flex items-center gap-1.5">
<button
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")}
onClick={() => setDeleteOpen(true)}
>
<Trash2 size={16} />
@@ -156,7 +181,7 @@ export default function IntlPaymentViewPage() {
<button
onClick={() => navigate(`/intl-payments/visa-master/${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>
@@ -165,55 +190,47 @@ export default function IntlPaymentViewPage() {
{/* ── Row 1: Meta + Ýüztuman + Lokasiýa ───────────────────────────── */}
<BentoGrid cols={3}>
<BentoCard title={t('intlPayment.statusSection', 'Esasy maglumatlar')}>
<InfoRow label={t('intlPayment.client', 'Ulanyjy')}>
<span className="text-primary font-medium">{data.client_label}</span>
</InfoRow>
<InfoRow label={t("common.id", "ID")}>
<span className="font-mono">{data.id}</span>
</InfoRow>
<InfoRow label={t('intlPayment.status', 'Status')}>
<BentoCard title={t("intlPayment.statusSection", "Esasy maglumatlar")}>
<InfoRow label={t("intlPayment.client", "Ulanyjy")} value={data.client_label} isLink />
<InfoRow label={t("common.id", "ID")} value={data.id} />
<InfoRow label={t("intlPayment.status", "Status")}>
<PaymentStatusBadge status={data.status} />
</InfoRow>
<InfoRow label={t('intlPayment.tilowanMonth', 'Tölewan (Aý/aý)')} value={data.created_at} />
<InfoRow label={t('intlPayment.note', 'Bellik')} value={data.note} />
<InfoRow label={t("intlPayment.tilowanMonth", "Tölewan (Aý/aý)")} value={data.created_at} />
<InfoRow label={t("intlPayment.note", "Bellik")} value={data.note} />
</BentoCard>
<BentoCard title={t('intlPayment.currencySection', 'Ýüztumanyň görnüşi')}>
<InfoRow label={t('intlPayment.currencyType', 'Görnüşi')} value={data.currency_type_label} />
<BentoCard title={t("intlPayment.currencySection", "Ýüztumanyň görnüşi")}>
<InfoRow label={t("intlPayment.currencyType", "Görnüşi")} value={data.currency_type_label} />
</BentoCard>
<BentoCard title={t('intlPayment.locationSection', 'Lokasiýa')}>
<InfoRow label={t('intlPayment.province', 'Welaýat')} value={data.province_label} />
<InfoRow label={t('intlPayment.branch', 'Şahamça')}>
<span className="text-primary font-medium">{data.branch_label}</span>
</InfoRow>
<BentoCard title={t("intlPayment.locationSection", "Lokasiýa")}>
<InfoRow label={t("intlPayment.province", "Welaýat")} value={data.province_label} />
<InfoRow label={t("intlPayment.branch", "Şahamça")} value={data.branch_label} isLink />
</BentoCard>
</BentoGrid>
{/* ── Row 2: Şahsy maglumatlar + Töleg ─────────────────────────────── */}
<BentoGrid cols={2}>
<BentoCard title={t('intlPayment.personalSection', 'Şahsy maglumatlar')}>
<InfoRow label={t('intlPayment.passportFirstName', 'Pasportdaky ady')} value={data.passport_first_name} />
<InfoRow label={t('intlPayment.passportLastName', 'Pasportdaky familiýa')} value={data.passport_last_name} />
<InfoRow label={t('intlPayment.phone', 'Telefon')}>
<span>+{data.phone}</span>
</InfoRow>
<InfoRow label={t('intlPayment.email', 'E-poçta')} value={data.email} />
<InfoRow label={t('intlPayment.homeAddress', 'Häzirki ýaşyş ýeri')} value={data.home_address} />
<BentoCard title={t("intlPayment.personalSection", "Şahsy maglumatlar")}>
<InfoRow label={t("intlPayment.passportFirstName", "Pasportdaky ady")} value={data.passport_first_name} />
<InfoRow label={t("intlPayment.passportLastName", "Pasportdaky familiýa")} value={data.passport_last_name} />
<InfoRow label={t("intlPayment.phone", "Telefon")} value={`+${data.phone}`} />
<InfoRow label={t("intlPayment.email", "E-poçta")} value={data.email} />
<InfoRow label={t("intlPayment.homeAddress", "Häzirki ýaşyş ýeri")} value={data.home_address} />
</BentoCard>
<BentoCard title={t('intlPayment.paymentSection', 'Töleg')}>
<InfoRow label={t('intlPayment.payerFullName', 'Töleg upgradyjynyň maglumatlary')} value={data.payer_full_name} />
<InfoRow label={t('intlPayment.payerAccount', 'Töleg upgradyjynyň goşun hasaby')} value={data.payer_account_number} />
<InfoRow label={t('intlPayment.passportSeries', 'Pasport seriýasy')} value={data.passport_series} />
<InfoRow label={t('intlPayment.passportNumber', 'Pasport nomeri')} value={data.passport_number} />
<BentoCard title={t("intlPayment.paymentSection", "Töleg")}>
<InfoRow label={t("intlPayment.payerFullName", "Töleg upgradyjynyň maglumatlary")} value={data.payer_full_name} />
<InfoRow label={t("intlPayment.payerAccount", "Töleg upgradyjynyň goşun hasaby")} value={data.payer_account_number} />
<InfoRow label={t("intlPayment.passportSeries", "Pasport seriýasy")} value={data.passport_series} />
<InfoRow label={t("intlPayment.passportNumber", "Pasport nomeri")} value={data.passport_number} />
</BentoCard>
</BentoGrid>
{/* ── Row 3: Kabul ediji resminamalar ──────────────────────────────── */}
<BentoGrid cols={1}>
<BentoCard title={t('intlPayment.kabulDocsSection', 'Kabul ediji talyp boyunca resminamalar')}>
<BentoCard title={t("intlPayment.kabulDocsSection", "Kabul ediji talyp boyunca resminamalar")}>
{KABUL_DOCS.map((doc, i) => (
<DocFileRow key={i} label={doc.label} url={doc.url} />
))}
@@ -222,7 +239,7 @@ export default function IntlPaymentViewPage() {
{/* ── Row 4: Upgradyý resminamalar ─────────────────────────────────── */}
<BentoGrid cols={1}>
<BentoCard title={t('intlPayment.upgradDocsSection', 'Upgradyý boyunca resminamalar')}>
<BentoCard title={t("intlPayment.upgradDocsSection", "Upgradyý boyunca resminamalar")}>
{UPGRAD_DOCS.map((doc, i) => (
<DocFileRow key={i} label={doc.label} url={doc.url} />
))}
@@ -231,7 +248,7 @@ export default function IntlPaymentViewPage() {
{/* ── Row 5: Töleg taryhy ───────────────────────────────────────────── */}
<BentoGrid cols={1}>
<BentoCard title={t('intlPayment.paymentHistory', 'Töleg taryhy')}>
<BentoCard title={t("intlPayment.paymentHistory", "Töleg taryhy")}>
<div className="p-4">
<div className="relative max-w-xs mb-4">
<Search size={13} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
@@ -239,7 +256,7 @@ export default function IntlPaymentViewPage() {
type="text"
value={historySearch}
onChange={(e) => setHistorySearch(e.target.value)}
placeholder={t('intlPayment.search', 'Gözlemek')}
placeholder={t("intlPayment.search", "Gözlemek")}
className="h-9 w-full pl-9 pr-3 rounded-md border border-border bg-background text-sm focus:outline-none focus:ring-2 focus:ring-ring"
/>
</div>
@@ -252,7 +269,7 @@ export default function IntlPaymentViewPage() {
<line x1="9" y1="9" x2="9" y2="21" />
</svg>
</div>
<p className="text-sm">{t('intlPayment.noHistory', 'Beriilen kriteriýalara Töleg gabat gelmedi')}</p>
<p className="text-sm">{t("intlPayment.noHistory", "Beriilen kriteriýalara Töleg gabat gelmedi")}</p>
</div>
</div>
</BentoCard>
@@ -261,12 +278,12 @@ export default function IntlPaymentViewPage() {
<ConfirmDialog
open={deleteOpen}
onOpenChange={setDeleteOpen}
title={t('intlPayment.deleteTitle', 'Pozmak isleýärsiňizmi?')}
description={`${t('intlPayment.deleteDesc', 'Bu amal yzyna dolanyp bolmaz.')} ${data?.id}`}
confirmLabel={t('common.delete', 'Poz')}
title={t("intlPayment.deleteTitle", "Pozmak isleýärsiňizmi?")}
description={`${t("intlPayment.deleteDesc", "Bu amal yzyna dolanyp bolmaz.")} ${data?.id}`}
confirmLabel={t("common.delete", "Poz")}
onConfirm={confirmDelete}
isLoading={isDeleting}
/>
</div>
)
}
);
}