connected with backups and currency rates
This commit is contained in:
@@ -1,108 +1,91 @@
|
||||
import { useState } from "react";
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download, Database, CheckCircle2, XCircle, Clock } from "lucide-react";
|
||||
import { Download, Database, CheckCircle2, XCircle, Clock, AlertCircle } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ColumnMeta } from "@/components/dataTableToolbar";
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import { useBackups, useCreateBackup, useDeleteBackup, useDownloadBackup } from "@/features/backups/hooks/useBackups";
|
||||
import type { Backup, BackupStatus } from "@/features/backups/api/backupsApi";
|
||||
|
||||
const PER_PAGE = 25;
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
function BackupStatusBadge({ status }: { status: BackupStatus }) {
|
||||
const STATUS_CONFIG: Record<BackupStatus, { labelKey: string; fallback: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
pending: { labelKey: "backups.status.pending", fallback: "Garaşylýar", variant: "warning", icon: AlertCircle },
|
||||
in_progress: { labelKey: "backups.status.inProgress", fallback: "Dowam edýär", variant: "warning", icon: Clock },
|
||||
completed: { labelKey: "backups.status.completed", fallback: "Tamamlandy", variant: "success", icon: CheckCircle2 },
|
||||
failed: { labelKey: "backups.status.failed", fallback: "Şowsuz", variant: "error", icon: XCircle },
|
||||
};
|
||||
|
||||
function BackupStatusBadge({ status }: { status: string }) {
|
||||
const { t } = useTranslation();
|
||||
const cfg: Record<BackupStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
completed: { label: t("backups.status.completed", "Tamamlandy"), variant: "success", icon: CheckCircle2 },
|
||||
failed: { label: t("backups.status.failed", "Şowsuz"), variant: "error", icon: XCircle },
|
||||
in_progress: { label: t("backups.status.inProgress", "Dowam edýär"), variant: "warning", icon: Clock },
|
||||
};
|
||||
const currentCfg = cfg[status];
|
||||
return <StatusBadge label={currentCfg.label} variant={currentCfg.variant} icon={currentCfg.icon} />;
|
||||
const cfg = STATUS_CONFIG[status as BackupStatus];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(cfg.labelKey, cfg.fallback)} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Column meta for toggle dropdown ─────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = ["id", "fileName", "size", "status", "createdBy", "createdAt"] as const;
|
||||
|
||||
export default function BackupsPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage, setPerPage] = useState(PER_PAGE);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([]);
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([{ fieldId: "status", value: "" }]);
|
||||
|
||||
const { data, isLoading } = useBackups({ page, per_page: perPage, search });
|
||||
const createBackup = useCreateBackup();
|
||||
const downloadBackup = useDownloadBackup();
|
||||
const deleteBackup = useDeleteBackup();
|
||||
|
||||
const columns: ColumnDef<Backup>[] = [
|
||||
{
|
||||
id: "fileName",
|
||||
accessorKey: "fileName",
|
||||
header: t("backups.col.fileName", "Faýl ady"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.fileName}</span>,
|
||||
},
|
||||
{
|
||||
id: "fileSize",
|
||||
accessorKey: "fileSize",
|
||||
header: t("backups.col.fileSize", "Ölçegi"),
|
||||
cell: ({ row }) => <span>{row.original.fileSize}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("backups.col.status", "Status"),
|
||||
cell: ({ row }) => <BackupStatusBadge status={row.original.status} />,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("backups.col.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => <span className="text-sm text-muted-foreground">{row.original.createdAt}</span>,
|
||||
size: 160,
|
||||
},
|
||||
{
|
||||
id: "createdBy",
|
||||
accessorKey: "createdBy",
|
||||
header: t("backups.col.createdBy", "Döreden"),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
extraActions={[
|
||||
{
|
||||
icon: Download,
|
||||
title: t("common.download", "Ýükle"),
|
||||
onClick: () => downloadBackup.mutate(row.original.id),
|
||||
disabled: row.original.status === "in_progress",
|
||||
},
|
||||
]}
|
||||
onDelete={() => setDeleteId(row.original.id)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
];
|
||||
// ── Query params & data ─────────────────────────────────────────────────────
|
||||
|
||||
const columnMeta: ColumnMeta[] = columns
|
||||
.filter((c) => c.id !== "actions")
|
||||
.map((c) => ({
|
||||
id: c.id!,
|
||||
label: typeof c.header === "string" ? c.header : c.id!,
|
||||
}));
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]));
|
||||
return {
|
||||
page,
|
||||
limit: perPage,
|
||||
search: search || undefined,
|
||||
status: filterMap.status || undefined,
|
||||
};
|
||||
}, [search, activeFilters, page, perPage]);
|
||||
|
||||
const total = data?.total ?? 0;
|
||||
const totalPages = Math.ceil(total / perPage);
|
||||
const { data, isLoading } = useBackups(queryParams);
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.max(1, Math.ceil(total / perPage));
|
||||
|
||||
const statusOptions = useMemo(
|
||||
() => [
|
||||
{ value: "pending", label: t("backups.status.pending", "Garaşylýar") },
|
||||
{ value: "in_progress", label: t("backups.status.inProgress", "Dowam edýär") },
|
||||
{ value: "completed", label: t("backups.status.completed", "Tamamlandy") },
|
||||
{ value: "failed", label: t("backups.status.failed", "Şowsuz") },
|
||||
],
|
||||
[t],
|
||||
);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" })));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleDelete = async () => {
|
||||
if (deleteId === null) return;
|
||||
@@ -110,14 +93,109 @@ export default function BackupsPage() {
|
||||
setDeleteId(null);
|
||||
};
|
||||
|
||||
// ── Columns ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const columns = useMemo<ColumnDef<Backup>[]>(
|
||||
() => [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("ID", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left cursor-pointer"
|
||||
onClick={() => navigate(`/backups/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
id: "fileName",
|
||||
accessorKey: "fileName",
|
||||
header: t("backups.col.fileName", "Faýl ady"),
|
||||
cell: ({ row }) => <span className="font-mono text-sm">{row.original.fileName}</span>,
|
||||
},
|
||||
{
|
||||
id: "size",
|
||||
accessorKey: "size",
|
||||
header: t("backups.col.fileSize", "Ölçegi"),
|
||||
cell: ({ row }) => <span>{row.original.size}</span>,
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: "status",
|
||||
accessorKey: "status",
|
||||
header: t("backups.col.status", "Status"),
|
||||
cell: ({ row }) => <BackupStatusBadge status={row.original.status} />,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "createdBy",
|
||||
accessorKey: "createdBy",
|
||||
header: t("backups.col.createdBy", "Döreden"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">{row.original.createdBy?.name || row.original.createdBy?.username || "—"}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("backups.col.createdAt", "Döredilen wagty"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">{new Date(row.original.createdAt).toLocaleString()}</span>
|
||||
),
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
extraActions={[
|
||||
{
|
||||
icon: Download,
|
||||
title: t("common.download", "Ýükle"),
|
||||
onClick: () => downloadBackup.mutate({ id: row.original.id, fileName: row.original.fileName }),
|
||||
disabled: row.original.status === "in_progress",
|
||||
},
|
||||
]}
|
||||
onView={() => navigate(`/backups/${row.original.id}`)}
|
||||
onDelete={() => setDeleteId(row.original.id)}
|
||||
isDeleting={deleteBackup.isPending}
|
||||
/>
|
||||
),
|
||||
size: 130,
|
||||
},
|
||||
],
|
||||
[t, navigate, downloadBackup, deleteBackup.isPending],
|
||||
);
|
||||
|
||||
const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`backups.columns.${id}`, id) })), [t]);
|
||||
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: "status",
|
||||
label: t("backups.col.status", "STATUS"),
|
||||
options: statusOptions,
|
||||
},
|
||||
],
|
||||
[t, statusOptions],
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground flex items-center gap-2">
|
||||
<Database className="size-5 text-muted-foreground" />
|
||||
{t("backups.title", "Bekaplar")}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 justify-between">
|
||||
<TableSearchInput
|
||||
value={search}
|
||||
@@ -135,30 +213,34 @@ export default function BackupsPage() {
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
hideSearch
|
||||
hideAction
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => {
|
||||
setSearch(v);
|
||||
setPage(1);
|
||||
}}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columns={toggleableColumns}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
hideSearch
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
data={data?.backups ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
|
||||
142
src/pages/backupsView/index.tsx
Normal file
142
src/pages/backupsView/index.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Download, Trash2, Database, CheckCircle2, XCircle, Clock, AlertCircle } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { useBackup, useDeleteBackup, useDownloadBackup } from "@/features/backups/hooks/useBackups";
|
||||
import { InfoRow } from "@/components/viewPageComponents";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import type { BackupStatus } from "@/features/backups/api/backupsApi";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG: Record<BackupStatus, { labelKey: string; fallback: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
|
||||
pending: { labelKey: "backups.status.pending", fallback: "Garaşylýar", variant: "warning", icon: AlertCircle },
|
||||
in_progress: { labelKey: "backups.status.inProgress", fallback: "Dowam edýär", variant: "warning", icon: Clock },
|
||||
completed: { labelKey: "backups.status.completed", fallback: "Tamamlandy", variant: "success", icon: CheckCircle2 },
|
||||
failed: { labelKey: "backups.status.failed", fallback: "Şowsuz", variant: "error", icon: XCircle },
|
||||
};
|
||||
|
||||
function BackupStatusBadge({ status }: { status: string }) {
|
||||
const { t } = useTranslation();
|
||||
const cfg = STATUS_CONFIG[status as BackupStatus];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(cfg.labelKey, cfg.fallback)} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function BackupViewPage() {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading } = useBackup(numericId);
|
||||
const deleteMutation = useDeleteBackup();
|
||||
const downloadMutation = useDownloadBackup();
|
||||
|
||||
const handleDelete = async () => {
|
||||
await deleteMutation.mutateAsync(numericId);
|
||||
navigate("/backups");
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<Skeleton className="h-7 w-64" />
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-4 w-40" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
return <div className="text-center py-24 text-muted-foreground">{t("Not found", "Tapylmady")}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-xl font-semibold text-foreground flex items-center gap-2">
|
||||
<Database className="size-5 text-muted-foreground" />
|
||||
{t("Backup detail", "Backup giňişleýin")}: #{data.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => downloadMutation.mutate({ id: numericId, fileName: data.fileName })}
|
||||
disabled={downloadMutation.isPending || data.status === "in_progress"}
|
||||
>
|
||||
<Download size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail card */}
|
||||
<div className="rounded-lg border border-border bg-card overflow-hidden">
|
||||
<InfoRow label={t("ID", "ID")} value={data.id} />
|
||||
<InfoRow label={t("backups.col.fileName", "Faýl ady")} value={data.fileName} />
|
||||
<InfoRow label={t("backups.col.fileSize", "Ölçegi")} value={`${data.size} (${data.sizeBytes} bytes)`} />
|
||||
<InfoRow label={t("backups.col.status", "Status")}>
|
||||
<BackupStatusBadge status={data.status} />
|
||||
</InfoRow>
|
||||
<InfoRow
|
||||
label={t("backups.col.createdBy", "Döreden")}
|
||||
value={data.createdBy?.name || data.createdBy?.username || undefined}
|
||||
isLink
|
||||
href={data.createdBy?.id != null ? `/all-users/${data.createdBy.id}` : undefined}
|
||||
/>
|
||||
<InfoRow label={t("backups.col.createdAt", "Döredilen wagty")} value={new Date(data.createdAt).toLocaleString()} />
|
||||
<InfoRow label={t("Updated at", "Täzelenen wagty")} value={new Date(data.updatedAt).toLocaleString()} />
|
||||
</div>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t("Are you sure?", "Eminsiňizmi?")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t("backups.deleteConfirm.description", "Bu backup pozulsynmy? Bu amal yzyna gaýtarylmaz.")}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<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")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
@@ -8,12 +9,30 @@ import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/compone
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { useCardBalances, useDeleteCardBalance } from "@/features/cardBalance/hooks/useCardBalance";
|
||||
import type { CardBalance } from "@/features/cardBalance/api/cardBalanceApi";
|
||||
import { CardBalanceStatusBadge } from "@/features/cardBalance/components/cardBalanceStatusBadge";
|
||||
import type { CardBalance, CardBalanceStatus } from "@/features/cardBalance/api/cardBalanceApi";
|
||||
import { useInfiniteUsers } from "@/features/allUsers/hooks/useAllUsers";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG: Record<
|
||||
CardBalanceStatus,
|
||||
{ labelKey: string; fallback: string; variant: StatusBadgeVariant; icon: React.ElementType }
|
||||
> = {
|
||||
pending: { labelKey: "cardBalance.status.pending", fallback: "Garaşylýar", variant: "warning", icon: AlertCircle },
|
||||
approved: { labelKey: "cardBalance.status.approved", fallback: "Tassyklanan", variant: "success", icon: CheckCircle2 },
|
||||
rejected: { labelKey: "cardBalance.status.rejected", fallback: "Ret edilen", variant: "error", icon: XCircle },
|
||||
};
|
||||
|
||||
function CardBalanceStatusBadge({ status }: { status: string }) {
|
||||
const { t } = useTranslation();
|
||||
const cfg = STATUS_CONFIG[status as CardBalanceStatus];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(cfg.labelKey, cfg.fallback)} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Column meta for toggle dropdown ─────────────────────────────────────────
|
||||
|
||||
const COLUMN_IDS = ["id", "passportNumber", "cardLast4", "expiry", "balance", "status", "createdBy", "createdAt"] as const;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { useParams, useNavigate, Link } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Trash2, Pencil } from "lucide-react";
|
||||
import { Trash2, Pencil, AlertCircle, CheckCircle2, XCircle } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import {
|
||||
@@ -16,7 +16,26 @@ import {
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { useCardBalance, useDeleteCardBalance } from "@/features/cardBalance/hooks/useCardBalance";
|
||||
import { InfoRow } from "@/components/viewPageComponents";
|
||||
import { CardBalanceStatusBadge } from "@/features/cardBalance/components/cardBalanceStatusBadge";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
|
||||
import type { CardBalanceStatus } from "@/features/cardBalance/api/cardBalanceApi";
|
||||
|
||||
// ─── Status Badge ─────────────────────────────────────────────────────────────
|
||||
|
||||
const STATUS_CONFIG: Record<
|
||||
CardBalanceStatus,
|
||||
{ labelKey: string; fallback: string; variant: StatusBadgeVariant; icon: React.ElementType }
|
||||
> = {
|
||||
pending: { labelKey: "cardBalance.status.pending", fallback: "Garaşylýar", variant: "warning", icon: AlertCircle },
|
||||
approved: { labelKey: "cardBalance.status.approved", fallback: "Tassyklanan", variant: "success", icon: CheckCircle2 },
|
||||
rejected: { labelKey: "cardBalance.status.rejected", fallback: "Ret edilen", variant: "error", icon: XCircle },
|
||||
};
|
||||
|
||||
function CardBalanceStatusBadge({ status }: { status: string }) {
|
||||
const { t } = useTranslation();
|
||||
const cfg = STATUS_CONFIG[status as CardBalanceStatus];
|
||||
if (!cfg) return <span className="text-xs text-muted-foreground">{status}</span>;
|
||||
return <StatusBadge label={t(cfg.labelKey, cfg.fallback)} variant={cfg.variant} icon={cfg.icon} />;
|
||||
}
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import type { Card } from "@/features/cardTransactions/api/cardTransactionsApi";
|
||||
const PER_PAGE = 25;
|
||||
|
||||
export default function CardTransactionsPage() {
|
||||
const { t } = useTranslation();
|
||||
const { t, i18n } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
@@ -44,7 +44,7 @@ export default function CardTransactionsPage() {
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 80,
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
id: "name",
|
||||
@@ -62,7 +62,14 @@ export default function CardTransactionsPage() {
|
||||
id: "type",
|
||||
accessorKey: "type",
|
||||
header: t("cardTransaction.col.type", "Görnüşi"),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.type}</span>,
|
||||
cell: ({ row }) => {
|
||||
const ct = row.original.cardType;
|
||||
const val =
|
||||
typeof ct?.name === "object"
|
||||
? ct.name[i18n.language as "tm" | "ru" | "en"] || ct.name.tm || ct.name.en
|
||||
: ct?.name || row.original.type || "—";
|
||||
return <span className="text-sm text-foreground">{val}</span>;
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "expiry",
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { useCardTransaction, useDeleteCardTransaction } from "@/features/cardTransactions/hooks/useCardTransactions";
|
||||
import { BentoGrid, BentoCard, InfoRow } from "@/components/viewPageComponents";
|
||||
import i18n from "@/lib/i18n";
|
||||
|
||||
// ─── Page ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -84,7 +85,14 @@ export default function CardTransactionViewPage() {
|
||||
<BentoCard title={t("cardTransaction.section.card", "Kart")}>
|
||||
<InfoRow label={t("cardTransaction.col.id", "ID")} value={data.id} />
|
||||
<InfoRow label={t("cardTransaction.col.name", "Ady")} value={data.name} />
|
||||
<InfoRow label={t("cardTransaction.col.type", "Görnüşi")} value={data.type} />
|
||||
<InfoRow
|
||||
label={t("cardTransaction.col.type", "Görnüşi")}
|
||||
value={
|
||||
typeof data.cardType?.name === "object"
|
||||
? data.cardType.name[i18n.language as "tm" | "ru" | "en"] || data.cardType.name.tm || data.cardType.name.en || "—"
|
||||
: data.cardType?.name || data.type || "—"
|
||||
}
|
||||
/>
|
||||
<InfoRow label={t("cardTransaction.col.number", "Kart belgisi")} value={data.number} />
|
||||
<InfoRow label={t("cardTransaction.col.expiry", "Möhleti")} value={`${data.month}/${data.year}`} />
|
||||
</BentoCard>
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
// pages/CurrencyRatesPage.tsx
|
||||
|
||||
import { useState } from "react";
|
||||
import { useState, useMemo, useCallback } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import type { ColumnDef, VisibilityState } from "@tanstack/react-table";
|
||||
|
||||
import { DataTable } from "@/components/dataTable";
|
||||
import { DataTableToolbar, type ActiveFilter, type FilterField } from "@/components/dataTableToolbar";
|
||||
import { TableSearchInput } from "@/components/tableSearch";
|
||||
import { CreateButton } from "@/components/createButton";
|
||||
import { TableActions } from "@/components/tableActions";
|
||||
import { useGetCurrencyRates, useDeleteCurrencyRate } from "@/features/currencyRates/hooks/useCurrencyRates";
|
||||
import type { CurrencyRate } from "@/features/currencyRates/api/currencyRatesApi";
|
||||
import { DeleteDialog } from "@/components/deleteDialog";
|
||||
import { useGetCurrencyRates, useDeleteCurrencyRate } from "@/features/currencyRates/hooks/useCurrencyRates";
|
||||
import { CURRENCY_OPTIONS, type CurrencyRate } from "@/features/currencyRates/api/currencyRatesApi";
|
||||
|
||||
// ─── Column visibility defaults ───────────────────────────────────────────────
|
||||
// ─── Column meta for toggle dropdown ─────────────────────────────────────────
|
||||
|
||||
const DEFAULT_VISIBILITY = {
|
||||
id: true,
|
||||
currencyFrom: true,
|
||||
currencyTo: true,
|
||||
value: true,
|
||||
};
|
||||
const DEFAULT_ORDER = ["id", "currencyFrom", "currencyTo", "value", "actions"];
|
||||
const COLUMN_IDS = ["id", "currencyFrom", "currencyTo", "value", "createdBy", "createdAt"] as const;
|
||||
|
||||
// ─── CurrencyRatesPage ────────────────────────────────────────────────────────
|
||||
|
||||
@@ -29,86 +23,154 @@ export default function CurrencyRatesPage() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage] = useState(25);
|
||||
const [perPage, setPerPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>(DEFAULT_VISIBILITY);
|
||||
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER);
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({});
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([...COLUMN_IDS]);
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null);
|
||||
|
||||
const { data, isLoading } = useGetCurrencyRates({ page, perPage, search });
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: "currency_from", value: "" },
|
||||
{ fieldId: "currency_to", value: "" },
|
||||
]);
|
||||
|
||||
const deleteMutation = useDeleteCurrencyRate();
|
||||
|
||||
// ── Query params & data ─────────────────────────────────────────────────────
|
||||
|
||||
const queryParams = useMemo(() => {
|
||||
const filterMap = Object.fromEntries(activeFilters.map((f) => [f.fieldId, f.value]));
|
||||
return {
|
||||
page,
|
||||
limit: perPage,
|
||||
search: search || undefined,
|
||||
currency_from: filterMap.currency_from || undefined,
|
||||
currency_to: filterMap.currency_to || undefined,
|
||||
};
|
||||
}, [search, activeFilters, page, perPage]);
|
||||
|
||||
const { data, isLoading } = useGetCurrencyRates(queryParams);
|
||||
const total = data?.count ?? 0;
|
||||
const totalPages = Math.max(1, Math.ceil(total / perPage));
|
||||
|
||||
const currencyOptions = useMemo(() => CURRENCY_OPTIONS.map((c) => ({ value: c.value, label: c.value })), []);
|
||||
|
||||
const handleFilterChange = useCallback((fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f)));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleFilterReset = useCallback(() => {
|
||||
setActiveFilters((prev) => prev.map((f) => ({ ...f, value: "" })));
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleSearchChange = useCallback((val: string) => {
|
||||
setSearch(val);
|
||||
setPage(1);
|
||||
}, []);
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (deleteId === null) return;
|
||||
await deleteMutation.mutateAsync(deleteId);
|
||||
setDeleteId(null);
|
||||
};
|
||||
|
||||
const handleSearchChange = (val: string) => {
|
||||
setSearch(val);
|
||||
setPage(1);
|
||||
};
|
||||
// ── Columns ─────────────────────────────────────────────────────────────────
|
||||
|
||||
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||
const columns = useMemo<ColumnDef<CurrencyRate>[]>(
|
||||
() => [
|
||||
{
|
||||
id: "id",
|
||||
accessorKey: "id",
|
||||
header: t("ID", "ID"),
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-medium hover:underline text-left cursor-pointer"
|
||||
onClick={() => navigate(`/currency-rates/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
id: "currencyFrom",
|
||||
accessorKey: "currencyFrom",
|
||||
header: t("currencyRates.columns.currencyFrom", "CURRENCY FROM"),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.original.currencyFrom}</span>,
|
||||
},
|
||||
{
|
||||
id: "currencyTo",
|
||||
accessorKey: "currencyTo",
|
||||
header: t("currencyRates.columns.currencyTo", "CURRENCY TO"),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.original.currencyTo}</span>,
|
||||
},
|
||||
{
|
||||
id: "value",
|
||||
accessorKey: "value",
|
||||
header: t("currencyRates.columns.value", "VALUE"),
|
||||
cell: ({ row }) => <span className="text-foreground tabular-nums">{row.original.value}</span>,
|
||||
},
|
||||
{
|
||||
id: "createdBy",
|
||||
accessorKey: "createdBy",
|
||||
header: t("Created by", "DÖREDEN"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">{row.original.createdBy?.name || row.original.createdBy?.username || "—"}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: "createdAt",
|
||||
accessorKey: "createdAt",
|
||||
header: t("Created at", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground whitespace-nowrap">{new Date(row.original.createdAt).toLocaleString()}</span>
|
||||
),
|
||||
size: 180,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
onView={() => navigate(`/currency-rates/${row.original.id}`)}
|
||||
onEdit={() => navigate(`/currency-rates/${row.original.id}/edit`)}
|
||||
onDelete={() => setDeleteId(row.original.id)}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
],
|
||||
[t, navigate, deleteMutation.isPending],
|
||||
);
|
||||
|
||||
const columns: ColumnDef<CurrencyRate>[] = [
|
||||
{
|
||||
accessorKey: "id",
|
||||
header: "ID",
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-semibold hover:underline"
|
||||
onClick={() => navigate(`/resources/currency-rates/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: "currencyFrom",
|
||||
header: t("currencyRates.columns.currencyFrom", "CURRENCY FROM"),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.original.currencyFrom}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "currencyTo",
|
||||
header: t("currencyRates.columns.currencyTo", "CURRENCY TO"),
|
||||
cell: ({ row }) => <span className="font-medium text-foreground">{row.original.currencyTo}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: "value",
|
||||
header: t("currencyRates.columns.value", "VALUE"),
|
||||
cell: ({ row }) => <span className="text-foreground tabular-nums">{row.original.value}</span>,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<TableActions
|
||||
onView={() => navigate(`/currency-rates/${row.original.id}`)}
|
||||
onEdit={() => navigate(`/currency-rates/${row.original.id}/edit`)}
|
||||
onDelete={() => setDeleteId(row.original.id)}
|
||||
isDeleting={deleteMutation.isPending}
|
||||
/>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
];
|
||||
const toggleableColumns = useMemo(() => COLUMN_IDS.map((id) => ({ id, label: t(`currencyRates.columns.${id}`, id) })), [t]);
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => "accessorKey" in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""),
|
||||
label: typeof c.header === "string" ? c.header : String(("accessorKey" in c ? c.accessorKey : "") ?? ""),
|
||||
}));
|
||||
const filterFields = useMemo<FilterField[]>(
|
||||
() => [
|
||||
{
|
||||
id: "currency_from",
|
||||
label: t("currencyRates.fields.currencyFrom", "CURRENCY FROM"),
|
||||
options: currencyOptions,
|
||||
},
|
||||
{
|
||||
id: "currency_to",
|
||||
label: t("currencyRates.fields.currencyTo", "CURRENCY TO"),
|
||||
options: currencyOptions,
|
||||
},
|
||||
],
|
||||
[t, currencyOptions],
|
||||
);
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
// ─── Render ─────────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">{t("currencyRates.title", "Walýuta kursy")}</h1>
|
||||
<h1 className="text-xl font-semibold text-foreground">{t("currencyRates.title", "Walýuta kurslary")}</h1>
|
||||
|
||||
<div className="flex items-center gap-3 justify-between">
|
||||
<TableSearchInput value={search} onChange={handleSearchChange} placeholder={t("common.search", "Gözlemek")} />
|
||||
<CreateButton
|
||||
@@ -116,23 +178,34 @@ export default function CurrencyRatesPage() {
|
||||
onClick={() => navigate("/currency-rates/create")}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl p-4">
|
||||
<DataTableToolbar
|
||||
hideSearch
|
||||
hideAction
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columns={toggleableColumns}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideSearch
|
||||
hideAction
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => {
|
||||
setPerPage(v);
|
||||
setPage(1);
|
||||
}}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
data={data?.currencies ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
@@ -141,8 +214,8 @@ export default function CurrencyRatesPage() {
|
||||
enableRowSelection
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={data?.totalPages ?? 1}
|
||||
totalCount={data?.total ?? 0}
|
||||
totalPages={totalPages}
|
||||
totalCount={total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
// pages/CurrencyRateDetailPage.tsx
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useGetCurrencyRateById, useDeleteCurrencyRate } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||
import { ConfirmDialog } from '@/components/confirmDialog'
|
||||
import { useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Pencil, Trash2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Section, InfoRow } from "@/components/viewPageComponents";
|
||||
import { useGetCurrencyRateById, useDeleteCurrencyRate } from "@/features/currencyRates/hooks/useCurrencyRates";
|
||||
import { ConfirmDialog } from "@/components/confirmDialog";
|
||||
|
||||
// ─── CurrencyRateDetailPage ───────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRateDetailPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const numericId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const numericId = Number(id);
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const { data: rate, isLoading } = useGetCurrencyRateById(numericId)
|
||||
const deleteMutation = useDeleteCurrencyRate()
|
||||
const { data: rate, isLoading } = useGetCurrencyRateById(numericId);
|
||||
const deleteMutation = useDeleteCurrencyRate();
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
await deleteMutation.mutateAsync(numericId)
|
||||
navigate('/resources/currency-rates')
|
||||
}
|
||||
await deleteMutation.mutateAsync(numericId);
|
||||
navigate("/currency-rates");
|
||||
};
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
@@ -36,29 +36,25 @@ export default function CurrencyRateDetailPage() {
|
||||
<Skeleton className="h-6 w-64" />
|
||||
<Skeleton className="h-48 rounded-xl" />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (!rate) {
|
||||
return (
|
||||
<div>
|
||||
<p className="text-muted-foreground">
|
||||
{t('currencyRates.notFound', 'Walýuta kursy tapylmady')}
|
||||
</p>
|
||||
<p className="text-muted-foreground">{t("currencyRates.notFound", "Walýuta kursy tapylmady")}</p>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div >
|
||||
|
||||
|
||||
<div>
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('currencyRates.detail.title', 'Walýuta kursy giňişleýin')}: {rate.id}
|
||||
{t("currencyRates.detail.title", "Walýuta kursy giňişleýin")}: {rate.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
@@ -66,7 +62,7 @@ export default function CurrencyRateDetailPage() {
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
title={t("common.delete", "Pozmak")}
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</Button>
|
||||
@@ -74,8 +70,8 @@ export default function CurrencyRateDetailPage() {
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/resources/currency-rates/${rate.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
onClick={() => navigate(`/currency-rates/${rate.id}/edit`)}
|
||||
title={t("common.edit", "Üýtgetmek")}
|
||||
>
|
||||
<Pencil size={18} />
|
||||
</Button>
|
||||
@@ -84,27 +80,35 @@ export default function CurrencyRateDetailPage() {
|
||||
|
||||
{/* Detail Card */}
|
||||
<Section>
|
||||
<InfoRow label={t('common.id', 'ID')} value={rate.id} />
|
||||
<InfoRow label={t('currencyRates.fields.currencyFrom', 'Currency from')} value={rate.currencyFrom} />
|
||||
<InfoRow label={t('currencyRates.fields.currencyTo', 'Currency to')} value={rate.currencyTo} />
|
||||
<InfoRow label={t('currencyRates.fields.value', 'Value')} value={rate.value} />
|
||||
<InfoRow label={t('common.createdAt', 'Döredilen senesi')}
|
||||
value={new Date(rate.createdAt).toLocaleString()}
|
||||
<InfoRow label={t("common.id", "ID")} value={rate.id} />
|
||||
<InfoRow label={t("currencyRates.fields.currencyFrom", "Currency from")} value={rate.currencyFrom} />
|
||||
<InfoRow label={t("currencyRates.fields.currencyTo", "Currency to")} value={rate.currencyTo} />
|
||||
<InfoRow label={t("currencyRates.fields.value", "Value")} value={rate.value} />
|
||||
<InfoRow
|
||||
label={t("currencyRates.fields.createdBy", "Döreden")}
|
||||
value={rate.createdBy?.name || rate.createdBy?.username || undefined}
|
||||
isLink
|
||||
href={rate.createdBy?.id != null ? `/all-users/${rate.createdBy.id}` : undefined}
|
||||
/>
|
||||
<InfoRow label={t('common.updatedAt', 'Üýtgedilen senesi')}
|
||||
value={new Date(rate.updatedAt).toLocaleString()}
|
||||
<InfoRow
|
||||
label={t("currencyRates.fields.updatedBy", "Üýtgeden")}
|
||||
value={rate.updatedBy?.name || rate.updatedBy?.username || undefined}
|
||||
isLink
|
||||
href={rate.updatedBy?.id != null ? `/all-users/${rate.updatedBy.id}` : undefined}
|
||||
/>
|
||||
<InfoRow label={t("common.createdAt", "Döredilen senesi")} value={new Date(rate.createdAt).toLocaleString()} />
|
||||
<InfoRow label={t("common.updatedAt", "Üýtgedilen senesi")} value={new Date(rate.updatedAt).toLocaleString()} />
|
||||
</Section>
|
||||
|
||||
<ConfirmDialog
|
||||
open={deleteOpen}
|
||||
onOpenChange={setDeleteOpen}
|
||||
title={t('currencyRates.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||
description={t('currencyRates.deleteDialog.description', 'Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.')}
|
||||
confirmLabel={deleteMutation.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Pozmak')}
|
||||
title={t("currencyRates.deleteDialog.title", "Pozmak isleýärsiňizmi?")}
|
||||
description={t("currencyRates.deleteDialog.description", "Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.")}
|
||||
confirmLabel={deleteMutation.isPending ? t("common.deleting", "Pozulýar...") : t("common.delete", "Pozmak")}
|
||||
onConfirm={handleDeleteConfirm}
|
||||
isLoading={deleteMutation.isPending}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user