refactored code, fixed checkbox

This commit is contained in:
@jcarymuhammedow
2026-05-22 18:51:45 +05:00
parent 4adc153503
commit d56620be2e
16 changed files with 640 additions and 267 deletions

View File

@@ -127,6 +127,8 @@ const DistrictsViewPage = lazy(() => import("@/pages/settings/location/districts
const DistrictEditPage = lazy(() => import("@/pages/settings/location/districtsEdit"));
const BranchesPage = lazy(() => import("@/pages/settings/location/branches"));
const BackupsPage = lazy(() => import("@/pages/backups"));
const BranchCreatePage = lazy(() => import("@/pages/settings/location/branchesCreate"));
const BranchesViewPage = lazy(() => import("@/pages/settings/location/branchesView"));
const BranchEditPage = lazy(() => import("@/pages/settings/location/branchesEdit"));
@@ -949,6 +951,15 @@ export const router = createBrowserRouter([
</Suspense>
),
},
{
// Sidebar: /backups
path: "/backups",
element: (
<Suspense fallback={<PageLoader />}>
<BackupsPage />
</Suspense>
),
},
{
// Sidebar: /settings/location/branches
path: "/settings/location/branches",

View File

@@ -32,7 +32,7 @@ export function CreditCardVisual({
return (
<div
className={`${bgGradient} w-full max-w-[340px] h-[210px] rounded-2xl p-6 flex flex-col justify-between text-white shadow-xl relative overflow-hidden`}
className={`${bgGradient} w-full max-w-[360px] h-[210px] rounded-2xl p-6 flex flex-col justify-between text-white shadow-xl relative overflow-hidden`}
>
{/* Glow effects */}
<div className="absolute -top-16 -right-16 w-32 h-32 bg-white/10 rounded-full blur-2xl pointer-events-none"></div>

View File

@@ -124,7 +124,8 @@ interface SelectAllDropdownProps {
isAllTotalSelected: boolean
totalCount: number
pageCount: number
onSelectPage: (checked: boolean) => void
onTogglePage: (checked: boolean) => void
onSelectThisPage: () => void
onSelectAll: () => void
onClearAll: () => void
}
@@ -135,7 +136,8 @@ function SelectAllDropdown({
isAllTotalSelected,
totalCount,
pageCount,
onSelectPage,
onTogglePage,
onSelectThisPage,
onSelectAll,
onClearAll,
}: SelectAllDropdownProps) {
@@ -143,28 +145,42 @@ function SelectAllDropdown({
const ref = useRef<HTMLDivElement>(null)
useOutsideClick(ref, () => setOpen(false))
const checkboxChecked = isAllPageSelected || (isSomePageSelected && 'indeterminate')
const checkboxChecked = isAllTotalSelected || isAllPageSelected
? true
: isSomePageSelected
? 'indeterminate'
: false
return (
<div ref={ref} className="flex items-center gap-0.5">
<div ref={ref} className="flex items-center gap-1">
<Checkbox
checked={checkboxChecked as boolean | 'indeterminate'}
onCheckedChange={(value) => onSelectPage(!!value)}
checked={checkboxChecked}
onCheckedChange={(value) => onTogglePage(!!value)}
aria-label="Select all on page"
onClick={(e) => e.stopPropagation()}
className="after:content-none"
/>
<button
onClick={() => setOpen((v) => !v)}
className="flex items-center text-muted-foreground hover:text-foreground transition-colors p-0.5"
type="button"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
setOpen((v) => !v)
}}
className="relative z-10 flex items-center justify-center w-5 h-5 text-muted-foreground hover:text-foreground hover:bg-muted transition-colors rounded"
aria-label="Selection options"
>
<ChevronDown size={11} />
<ChevronDown size={12} />
</button>
{open && (
<div className="absolute top-10 left-0 z-50 w-52 bg-card border border-border rounded-md shadow-lg py-1">
<div className="absolute top-8 left-0 z-50 w-52 bg-card border border-border rounded-md shadow-lg py-1">
<button
onClick={() => {
onSelectPage(true)
type="button"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
onSelectThisPage()
setOpen(false)
}}
className="w-full text-left px-3 py-2 text-sm hover:bg-muted/50 transition-colors"
@@ -173,7 +189,10 @@ function SelectAllDropdown({
<span className="ml-1 text-muted-foreground text-xs">({pageCount})</span>
</button>
<button
onClick={() => {
type="button"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
onSelectAll()
setOpen(false)
}}
@@ -186,7 +205,10 @@ function SelectAllDropdown({
<>
<div className="border-t border-border my-1" />
<button
onClick={() => {
type="button"
onClick={(e) => {
e.preventDefault()
e.stopPropagation()
onClearAll()
setOpen(false)
}}
@@ -257,9 +279,18 @@ export function DataTable<TData>({
isAllTotalSelected={allTotalSelected}
totalCount={resolvedTotalCount}
pageCount={data.length}
onSelectPage={(checked) => {
table.toggleAllPageRowsSelected(checked)
if (!checked) setAllTotalSelected(false)
onTogglePage={(checked) => {
if (!checked) {
if (allTotalSelected) setAllTotalSelected(false)
table.toggleAllPageRowsSelected(false)
table.setRowSelection({})
} else {
table.toggleAllPageRowsSelected(true)
}
}}
onSelectThisPage={() => {
table.toggleAllPageRowsSelected(true)
setAllTotalSelected(false)
}}
onSelectAll={() => {
table.toggleAllPageRowsSelected(true)
@@ -267,19 +298,36 @@ export function DataTable<TData>({
}}
onClearAll={() => {
table.toggleAllPageRowsSelected(false)
table.setRowSelection({})
setAllTotalSelected(false)
}}
/>
</div>
),
cell: ({ row }) => (
<Checkbox
checked={row.getIsSelected()}
onCheckedChange={(value) => row.toggleSelected(!!value)}
aria-label="Select row"
onClick={(e) => e.stopPropagation()}
/>
),
cell: ({ row, table }) => {
const isSelected = allTotalSelected || row.getIsSelected()
return (
<Checkbox
checked={isSelected}
onCheckedChange={(value) => {
if (allTotalSelected && !value) {
const newSelection: RowSelectionState = {}
table.getRowModel().rows.forEach((r) => {
if (r.id !== row.id) {
newSelection[r.id] = true
}
})
table.setRowSelection(newSelection)
setAllTotalSelected(false)
} else {
row.toggleSelected(!!value)
}
}}
aria-label="Select row"
onClick={(e) => e.stopPropagation()}
/>
)
},
enableSorting: false,
enableHiding: false,
size: 48,
@@ -357,6 +405,7 @@ export function DataTable<TData>({
<button
onClick={() => {
table.toggleAllPageRowsSelected(false)
table.setRowSelection({})
setAllTotalSelected(false)
}}
className="text-xs text-muted-foreground hover:text-foreground transition-colors"

View File

@@ -0,0 +1,78 @@
import apiClient from '@/lib/api/client'
export type BackupStatus = 'completed' | 'failed' | 'in_progress'
export interface Backup {
id: number
fileName: string
fileSize: string
status: BackupStatus
createdAt: string
createdBy: string
}
export interface BackupListResponse {
data: Backup[]
total: number
page: number
per_page: number
}
export interface BackupListParams {
page?: number
per_page?: number
search?: string
}
const MOCK_BACKUPS: Backup[] = [
{ id: 1, fileName: 'backup_2026_05_22_01.sql', fileSize: '256 MB', status: 'completed', createdAt: '2026-05-22 03:00', createdBy: 'Admin' },
{ id: 2, fileName: 'backup_2026_05_21_01.sql', fileSize: '251 MB', status: 'completed', createdAt: '2026-05-21 03:00', createdBy: 'Admin' },
{ id: 3, fileName: 'backup_2026_05_20_01.sql', fileSize: '248 MB', status: 'completed', createdAt: '2026-05-20 03:00', createdBy: 'Admin' },
{ id: 4, fileName: 'backup_2026_05_19_01.sql', fileSize: '245 MB', status: 'failed', createdAt: '2026-05-19 03:05', createdBy: 'Admin' },
{ id: 5, fileName: 'backup_2026_05_18_01.sql', fileSize: '242 MB', status: 'completed', createdAt: '2026-05-18 03:00', createdBy: 'System' },
]
export const backupsApi = {
getAll: async (params?: BackupListParams): Promise<BackupListResponse> => {
const { data } = await apiClient.get('/backups', { params }).catch(() => ({ data: null }))
if (data) return data
const { search = '', page = 1, per_page = 25 } = params ?? {}
let filtered = [...MOCK_BACKUPS]
if (search) {
const s = search.toLowerCase()
filtered = filtered.filter((b) => b.fileName.toLowerCase().includes(s))
}
const total = filtered.length
const start = (page - 1) * per_page
return { data: filtered.slice(start, start + per_page), total, page, per_page }
},
create: async (): Promise<Backup> => {
const { data } = await apiClient.post('/backups').catch(() => ({ data: null }))
if (data) return data
const newBackup: Backup = {
id: Math.floor(Math.random() * 10000),
fileName: `backup_${new Date().toISOString().slice(0, 10).replace(/-/g, '_')}_01.sql`,
fileSize: '0 MB',
status: 'in_progress',
createdAt: new Date().toLocaleString('tr-TR'),
createdBy: 'Admin',
}
MOCK_BACKUPS.unshift(newBackup)
return newBackup
},
download: async (id: number): Promise<Blob> => {
const { data } = await apiClient.get(`/backups/${id}/download`, { responseType: 'blob' }).catch(() => ({ data: null }))
if (data) return data
return new Blob(['mock backup content'], { type: 'application/sql' })
},
delete: async (id: number): Promise<void> => {
await apiClient.delete(`/backups/${id}`).catch(() => {})
const index = MOCK_BACKUPS.findIndex((b) => b.id === id)
if (index !== -1) MOCK_BACKUPS.splice(index, 1)
},
}

View File

@@ -0,0 +1,58 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { useTranslation } from 'react-i18next'
import { backupsApi, type BackupListParams } from '../api/backupsApi'
const QUERY_KEY = 'backups'
export function useBackups(params?: BackupListParams) {
return useQuery({
queryKey: [QUERY_KEY, params],
queryFn: () => backupsApi.getAll(params),
})
}
export function useCreateBackup() {
const queryClient = useQueryClient()
const { t } = useTranslation()
return useMutation({
mutationFn: () => backupsApi.create(),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEY] })
toast.success(t('backups.toast.created', 'Backup üstünlikli döredildi!'))
},
})
}
export function useDownloadBackup() {
const { t } = useTranslation()
return useMutation({
mutationFn: async (id: number) => {
const blob = await backupsApi.download(id)
const url = URL.createObjectURL(blob)
const a = document.createElement('a')
a.href = url
a.download = `backup-${id}.sql`
a.click()
URL.revokeObjectURL(url)
},
onSuccess: () => {
toast.success(t('backups.toast.downloaded', 'Backup üstünlikli ýüklenildi'))
},
})
}
export function useDeleteBackup() {
const queryClient = useQueryClient()
const { t } = useTranslation()
return useMutation({
mutationFn: (id: number) => backupsApi.delete(id),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEY] })
toast.success(t('backups.toast.deleted', 'Backup üstünlikli pozuldy!'))
},
})
}

View File

@@ -121,7 +121,7 @@ export function CurrencyRateForm({ mode, initialData }: CurrencyRateFormProps) {
? t('currencyRates.createTitle', 'Walýuta kursy dörediň')
: t('currencyRates.editTitle', 'Walýuta kursy üýtgetmek')}
</h1>
<div className="space-y-6">
<div className="space-y-6 bg-card border border-border rounded-xl overflow-hidden">
{/* Currency From */}
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
<label className="text-sm text-muted-foreground pt-1.5">

View File

@@ -139,7 +139,7 @@ export function VisaMasterSettingForm({
? t('visaMasterSettings.createTitle', 'Visa/Master, Sber sazlamalar dörediň')
: t('visaMasterSettings.editTitle', 'Visa/Master, Sber sazlamalar üýtgetmek')}
</h1>
<div className="space-y-0">
<div className="space-y-0 bg-card border border-border rounded-xl overflow-hidden">
{/* Kod */}
<div className="grid grid-cols-[220px_1fr] items-start py-4 px-6 border-b border-border">
<label className="text-sm text-muted-foreground pt-1.5">

193
src/pages/backups/index.tsx Normal file
View File

@@ -0,0 +1,193 @@
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { Download, Trash2, Database, CheckCircle2, XCircle, Clock } from 'lucide-react'
import { Button } from '@/components/ui/button'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import { DataTable, type ColumnDef } from '@/components/dataTable'
import { DataTableToolbar, type ColumnMeta } from '@/components/dataTableToolbar'
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
const STATUS_CONFIG: Record<BackupStatus, { label: string; variant: StatusBadgeVariant; icon: React.ElementType }> = {
completed: { label: 'Tamamlandy', variant: 'success', icon: CheckCircle2 },
failed: { label: 'Şowsuz', variant: 'error', icon: XCircle },
in_progress: { label: 'Dowam edýär', variant: 'warning', icon: Clock },
}
function BackupStatusBadge({ status }: { status: BackupStatus }) {
const cfg = STATUS_CONFIG[status]
return <StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
}
export default function BackupsPage() {
const { t } = useTranslation()
const [page, setPage] = useState(1)
const [perPage, setPerPage] = useState(PER_PAGE)
const [search, setSearch] = useState('')
const [deleteId, setDeleteId] = useState<number | null>(null)
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
const [columnOrder, setColumnOrder] = useState<string[]>([])
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 }) => (
<div className="flex items-center gap-1 justify-end">
<Button
variant="ghost" size="icon" className="h-7 w-7"
onClick={() => downloadBackup.mutate(row.original.id)}
disabled={row.original.status === 'in_progress'}
title={t('common.download', 'Ýükle')}
>
<Download size={14} />
</Button>
<Button
variant="ghost" size="icon"
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
onClick={() => setDeleteId(row.original.id)}
title={t('common.delete', 'Poz')}
>
<Trash2 size={14} />
</Button>
</div>
),
},
]
const columnMeta: ColumnMeta[] = columns
.filter((c) => c.id !== 'actions')
.map((c) => ({
id: c.id!,
label: typeof c.header === 'string' ? c.header : c.id!,
}))
const total = data?.total ?? 0
const totalPages = Math.ceil(total / perPage)
const handleDelete = async () => {
if (deleteId === null) return
await deleteBackup.mutateAsync(deleteId)
setDeleteId(null)
}
return (
<div className="space-y-4">
<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="bg-card border border-border rounded-xl p-4">
<DataTableToolbar
searchValue={search}
onSearchChange={(v) => { setSearch(v); setPage(1) }}
searchPlaceholder={t('common.search', 'Gözlemek')}
columns={columnMeta}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
perPageOptions={[10, 25, 50, 100]}
perPage={perPage}
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
actionLabel={createBackup.isPending ? t('common.loading', 'Döredilýär...') : t('backups.create', 'Backup dörediň')}
onAction={() => createBackup.mutate()}
/>
<DataTable
columns={columns}
data={data?.data ?? []}
isLoading={isLoading}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
enableRowSelection
getRowId={(row) => String(row.id)}
currentPage={page}
totalPages={totalPages}
totalCount={total}
onPageChange={setPage}
/>
</div>
<AlertDialog open={deleteId !== null} onOpenChange={(open) => !open && setDeleteId(null)}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>{t('backups.deleteConfirm.title', 'Eminsiňizmi?')}</AlertDialogTitle>
<AlertDialogDescription>
{t('backups.deleteConfirm.description', 'Bu backup pozulsynmy? Bu amal yzyna gaýtarylmaz.')}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{deleteBackup.isPending ? t('common.deleting', 'Pozulýar...') : t('common.delete', 'Poz')}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}

View File

@@ -1,11 +1,14 @@
import { useState } from "react";
import { useParams, useNavigate, Link } from "react-router-dom";
import { useParams, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Download, Trash2, Pencil, DownloadCloud } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
useCardRequisite,
useDeleteCardRequisite,
useDownloadCardRequisite,
} from "@/features/cardRequisites/hooks/useCardRequisites";
import type { CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi";
import { Spinner } from "@/components/ui/spinner";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Pencil, Trash2, Download } from "lucide-react";
import {
AlertDialog,
AlertDialogAction,
@@ -15,268 +18,262 @@ import {
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import {
useCardRequisite,
useDeleteCardRequisite,
useDownloadCardRequisite,
} from "@/features/cardRequisites/hooks/useCardRequisites";
import type { CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequisitesApi";
import { InfoRow } from "@/components/viewPageComponents";
// ─── Status badge ─────────────────────────────────────────────────────────────
StatusBadge,
type StatusBadgeVariant,
} from "@/components/ui/statusBadge";
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import { InfoRow, PassportImage } from "@/components/viewPageComponents";
// ─── Status config ────────────────────────────────────────────────────────────
const STATUS_VARIANT: Record<CardRequisiteStatus, StatusBadgeVariant> = {
pending: "warning",
approved: "success",
rejected: "error",
};
}
const STATUS_ICON: Record<CardRequisiteStatus, React.ElementType> = {
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} />
}
// ─── Section header ───────────────────────────────────────────────────────────
// ─── Bento primitives ─────────────────────────────────────────────────────────
function BentoGrid({ cols = 2, children }: { cols?: 1 | 2 | 3 | 4; children: React.ReactNode }) {
const colClass = {
1: "grid-cols-1",
2: "grid-cols-1 sm:grid-cols-2",
3: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-3",
4: "grid-cols-1 sm:grid-cols-2 lg:grid-cols-4",
}[cols]
return <div className={`grid ${colClass} gap-4`}>{children}</div>
}
function BentoCard({
title,
span,
children,
}: {
title?: string
span?: "full" | 2 | 3
children: React.ReactNode
}) {
const spanClass =
span === "full" ? "sm:col-span-full" :
span === 2 ? "sm:col-span-2" :
span === 3 ? "sm:col-span-3" : ""
function SectionTitle({ children }: { children: React.ReactNode }) {
return (
<h2 className="text-base font-semibold text-foreground mt-6 mb-3">
<div className={`bg-card border border-border rounded-xl overflow-hidden ${spanClass}`}>
{title && (
<div className="px-4 py-2.5 border-b border-border">
<p className="text-xs font-semibold text-muted-foreground uppercase tracking-wide">
{title}
</p>
</div>
)}
{children}
</h2>
);
}
// ─── Passport image row ───────────────────────────────────────────────────────
function PassportImageRow({ label, url }: { label: string; url?: string }) {
const { t } = useTranslation();
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-4 flex flex-col gap-2">
{url ? (
<>
<img
src={url}
alt={label}
className="max-w-[200px] rounded-md border border-border object-cover"
/>
<a
href={url}
download
className="flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground transition-colors w-fit"
>
<DownloadCloud size={13} />
{t("Download", "Göçürip al")}
</a>
</>
) : (
<span className="text-muted-foreground text-sm">—</span>
)}
</div>
</div>
);
)
}
// ─── Page ─────────────────────────────────────────────────────────────────────
export default function CardRequisiteViewPage() {
const { t } = useTranslation();
const { id } = useParams<{ id: string }>();
const navigate = useNavigate();
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const { t } = useTranslation()
const [deleteOpen, setDeleteOpen] = useState(false);
const { data, isLoading } = useCardRequisite(id ?? "");
const deleteMutation = useDeleteCardRequisite();
const downloadMutation = useDownloadCardRequisite();
const handleDelete = async () => {
await deleteMutation.mutateAsync(id ?? "");
navigate("/card-requisites");
};
const { data, isLoading, isError } = useCardRequisite(id ?? "")
const deleteMutation = useDeleteCardRequisite()
const downloadMutation = useDownloadCardRequisite()
if (isLoading) {
return (
<div className="flex items-center justify-center py-24">
<Spinner className="size-7 text-primary" />
<Spinner className="size-8 text-primary" />
</div>
);
)
}
if (!data) {
if (isError || !data) {
return (
<div className="text-center py-24 text-muted-foreground">
{t("Not found", "Tapylmady")}
<div className="flex items-center justify-center py-24 text-muted-foreground">
{t("common.notFound", "Maglumat tapylmady")}
</div>
);
)
}
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}
<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">
{t("cardRequisite.viewTitle", "Kart rekwizit giňişleýin")}: {data.id}
</h1>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="sm"
size="icon" variant="ghost"
className="h-8 w-8"
onClick={() => downloadMutation.mutate(data.id)}
disabled={downloadMutation.isPending}
>
<Download size={14} />
<Download size={15} />
</Button>
<AlertDialog>
<AlertDialogTrigger asChild>
<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("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>
<AlertDialogAction
disabled={deleteMutation.isPending}
className="bg-destructive hover:bg-destructive/90"
onClick={() => deleteMutation.mutate(data.id, { onSuccess: () => navigate("/card-requisites") })}
>
{t("common.delete", "Poz")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<Button
variant="outline"
size="sm"
className="text-destructive border-destructive/30 hover:bg-destructive/10"
onClick={() => setDeleteOpen(true)}
size="icon" variant="ghost" className="h-8 w-8"
onClick={() => navigate(`/card-requisites/${id}/edit`)}
>
<Trash2 size={14} />
</Button>
<Button variant="outline" size="sm" asChild>
<Link to={`/card-requisites/${data.id}/edit`}>
<Pencil size={14} />
</Link>
<Pencil size={15} />
</Button>
</div>
</div>
{/* General info */}
<div className="rounded-lg border border-border bg-card overflow-hidden">
<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")}>
<CardRequisiteStatusBadge status={data.status} />
</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>
) : (
"—"
)}
</InfoRow>
</div>
{/* ── 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("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>
</BentoCard>
{/* Card */}
<SectionTitle>{t("Card", "Kart")}</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<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>
<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>
</BentoCard>
{/* Location */}
<SectionTitle>{t("Location", "Lokasiýa")}</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<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>
<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>
</BentoCard>
</BentoGrid>
{/* Personal */}
<SectionTitle>
{t("Personal information", "Şahsy maglumatlar")}
</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<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>
{/* ── 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>
</BentoCard>
{/* Passport */}
<SectionTitle>{t("Passport", "Pasport")}</SectionTitle>
<div className="rounded-lg border border-border bg-card overflow-hidden">
<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)")}
url={data.passport_page1_url}
/>
<PassportImageRow
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)")}
url={data.passport_page8_9_url}
/>
<PassportImageRow
label={t("Passport (page 32)", "Pasport (32-nji sahypa)")}
url={data.passport_page32_url}
/>
</div>
<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>
</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}
/>
</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}
/>
</BentoCard>
<BentoCard title={t("cardRequisite.passportFile3", "Sahypa 8-9")}>
<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}
/>
</BentoCard>
</BentoGrid>
{/* Delete dialog */}
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<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.",
)}
</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>
);
)
}

View File

@@ -315,6 +315,7 @@ export default function CardOrdersPage() {
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
enableRowSelection
getRowId={(row) => row.id}
currentPage={page}
totalPages={data?.totalPages ?? 1}

View File

@@ -42,7 +42,7 @@ export default function LoanTypeViewPage() {
// ── Skeleton ───────────────────────────────────────────────────────────────
if (isLoading) {
return (
<div className="p-6 max-w-3xl">
<div className="p-6">
<Skeleton className="h-4 w-64 mb-4" />
<Skeleton className="h-7 w-80 mb-6" />
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
@@ -68,7 +68,7 @@ export default function LoanTypeViewPage() {
// ── View ───────────────────────────────────────────────────────────────────
return (
<div className="p-6 max-w-3xl">
<div className="p-6">
{/* Page header */}

View File

@@ -153,6 +153,7 @@ export default function PermissionsPage() {
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
enableRowSelection
getRowId={(row) => String(row.id)}
currentPage={data?.meta?.current_page ?? 1}
totalPages={data?.meta?.last_page ?? 1}

View File

@@ -153,6 +153,7 @@ export default function RolesPage() {
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
enableRowSelection
getRowId={(row) => String(row.id)}
currentPage={data?.meta?.current_page ?? 1}
totalPages={data?.meta?.last_page ?? 1}

View File

@@ -122,7 +122,7 @@ export default function UserViewPage() {
}
return (
<div className="p-6 max-w-4xl space-y-0">
<div className="p-6 space-y-0">
{/* Title + actions */}
<div className="flex items-start justify-between mb-6">
<h1 className="text-xl font-bold text-foreground leading-tight">

View File

@@ -1,7 +1,7 @@
import { useState } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Pencil, Trash2, ChevronDown } from 'lucide-react'
import { Pencil, Trash2, ChevronDown, XCircle, CheckCircle2 } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { ConfirmDialog } from '@/components/confirmDialog'
import { InfoRow, AuditLog } from '@/components/viewPageComponents'
@@ -54,18 +54,10 @@ function BentoCard({
function ActiveIndicator({ active }: { active: boolean }) {
return active ? (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-primary text-primary">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path d="M2 6l3 3 5-5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-destructive text-destructive">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
</svg>
</span>
)
<XCircle size={18} className="text-destructive" />
);
}
// ─── CollapsibleSection ───────────────────────────────────────────────────────

View File

@@ -1,6 +1,6 @@
import { useParams, useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Pencil, Trash2, ChevronDown } from "lucide-react";
import { Pencil, Trash2, ChevronDown, CheckCircle2, XCircle, } from "lucide-react";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { ConfirmDialog } from "@/components/confirmDialog";
@@ -41,17 +41,9 @@ function BentoCard({ title, span, children }: { title?: string; span?: "full" |
function ActiveIndicator({ active }: { active: boolean }) {
return active ? (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-primary text-primary">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path d="M2 6l3 3 5-5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-destructive text-destructive">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
</svg>
</span>
<XCircle size={18} className="text-destructive" />
);
}