added users pages, stepper
This commit is contained in:
281
src/pages/users/allUsers/index.tsx
Normal file
281
src/pages/users/allUsers/index.tsx
Normal file
@@ -0,0 +1,281 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react'
|
||||
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar, type ActiveFilter } from '@/components/dataTableToolbar'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import type { VisibilityState } from '@tanstack/react-table'
|
||||
|
||||
import { useUsers, useDeleteUser } from '@/features/allUsers/hooks/useAllUsers'
|
||||
import type { UserListItem } from '@/features/allUsers/api/allUsersApi'
|
||||
|
||||
// ─── Constants ────────────────────────────────────────────────────────────────
|
||||
|
||||
const DEFAULT_PER_PAGE = 25
|
||||
|
||||
// ─── UsersListPage ────────────────────────────────────────────────────────────
|
||||
|
||||
export default function UsersListPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteUser = useDeleteUser()
|
||||
|
||||
// Table state
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(DEFAULT_PER_PAGE)
|
||||
const [search, setSearch] = useState('')
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'username', 'name', 'phone', 'email', 'isActive', 'actions',
|
||||
])
|
||||
|
||||
// Delete confirm dialog
|
||||
const [deleteTarget, setDeleteTarget] = useState<UserListItem | null>(null)
|
||||
|
||||
// ── Derived filter values ───────────────────────────────────────────────────
|
||||
const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? ''
|
||||
|
||||
// ── Data fetch ─────────────────────────────────────────────────────────────
|
||||
const { data, isLoading } = useUsers({
|
||||
page,
|
||||
perPage,
|
||||
search,
|
||||
isActive: isActiveFilter || undefined,
|
||||
})
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleSearchChange = (value: string) => {
|
||||
setSearch(value)
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const handleFilterChange = (fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) => {
|
||||
const rest = prev.filter((f) => f.fieldId !== fieldId)
|
||||
return value ? [...rest, { fieldId, value }] : rest
|
||||
})
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const handleFilterReset = () => {
|
||||
setActiveFilters([])
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (!deleteTarget) return
|
||||
await deleteUser.mutateAsync(deleteTarget.id)
|
||||
setDeleteTarget(null)
|
||||
}
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns: ColumnDef<UserListItem>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
size: 80,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-xs font-mono text-primary font-semibold">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'username',
|
||||
header: t('users.fields.username', 'ULANYJY ADY'),
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-medium text-foreground">
|
||||
{row.original.username}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('users.fields.name', 'ADY'),
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
header: t('users.fields.phone', 'TELEFON'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground font-mono">{row.original.phone}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'email',
|
||||
header: t('users.fields.email', 'E-POÇTA'),
|
||||
enableSorting: true,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.email ?? '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
header: t('users.fields.isActive', 'IŞJEŇ'),
|
||||
size: 80,
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-muted-foreground/40" />
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
size: 100,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/all-users/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7"
|
||||
onClick={() => navigate(`/all-users/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-7 w-7 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setDeleteTarget(row.original)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
const columnMetas = columns
|
||||
.filter((c) => 'accessorKey' in c || (c.id && c.id !== 'actions' && c.id !== 'select'))
|
||||
.map((c) => ({
|
||||
id: 'accessorKey' in c ? (c.accessorKey as string) : (c.id as string),
|
||||
label:
|
||||
typeof c.header === 'string'
|
||||
? c.header
|
||||
: 'accessorKey' in c
|
||||
? (c.accessorKey as string)
|
||||
: (c.id as string),
|
||||
}))
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
{/* Page header */}
|
||||
<div>
|
||||
<nav className="flex items-center gap-1.5 text-xs text-muted-foreground mb-3">
|
||||
<span>{t('nav.resources', 'Resurslar')}</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('nav.users', 'Ulanyjylar')}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('users.title', 'Ulanyjylar')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t('users.searchPlaceholder', 'Gözlemek')}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('users.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('users.actions.create', 'Ulanyjy dörediň')}
|
||||
onAction={() => navigate('/all-users/create')}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<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={data?.totalPages ?? 1}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete confirm dialog */}
|
||||
<AlertDialog open={!!deleteTarget} onOpenChange={(o) => !o && setDeleteTarget(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('users.deleteDialog.title', 'Ulanyjyny öçürmek')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'users.deleteDialog.description',
|
||||
'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.',
|
||||
).replace('{name}', deleteTarget?.username ?? '')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýok')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{t('common.delete', 'Öçür')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
44
src/pages/users/allUsersCreate/index.tsx
Normal file
44
src/pages/users/allUsersCreate/index.tsx
Normal file
@@ -0,0 +1,44 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import { UserForm } from '@/features/allUsers/components/allUsersForm'
|
||||
|
||||
// ─── UserCreatePage ───────────────────────────────────────────────────────────
|
||||
|
||||
export default function UserCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4 max-w-4xl">
|
||||
{/* Breadcrumb */}
|
||||
<nav className="flex items-center gap-1.5 text-xs text-muted-foreground">
|
||||
<button
|
||||
onClick={() => navigate('/users')}
|
||||
className="hover:text-foreground transition-colors"
|
||||
>
|
||||
{t('nav.resources', 'Resurslar')}
|
||||
</button>
|
||||
<ChevronRight size={12} />
|
||||
<button
|
||||
onClick={() => navigate('/users')}
|
||||
className="hover:text-foreground transition-colors"
|
||||
>
|
||||
{t('nav.users', 'Ulanyjylar')}
|
||||
</button>
|
||||
<ChevronRight size={12} />
|
||||
<span className="text-foreground font-medium">
|
||||
{t('users.actions.create', 'Ulanyjy dörediň')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
{/* Title */}
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('users.actions.create', 'Ulanyjy dörediň')}
|
||||
</h1>
|
||||
|
||||
{/* Shared form — create mode */}
|
||||
<UserForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
45
src/pages/users/allUsersEdit/index.tsx
Normal file
45
src/pages/users/allUsersEdit/index.tsx
Normal file
@@ -0,0 +1,45 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { UserForm } from '@/features/allUsers/components/allUsersForm'
|
||||
import { useUser } from '@/features/allUsers/hooks/useAllUsers'
|
||||
|
||||
// ─── UserEditPage ─────────────────────────────────────────────────────────────
|
||||
|
||||
export default function UserEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const userId = Number(id)
|
||||
|
||||
const { data: user, isLoading, isError } = useUser(userId)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[300px]">
|
||||
<Loader2 size={24} className="animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !user) {
|
||||
return (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-4 max-w-4xl">
|
||||
|
||||
|
||||
{/* Title */}
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('users.editTitle', 'Ulanyjy giňişleýin')}: {user.name} ({user.username})
|
||||
</h1>
|
||||
|
||||
{/* Shared form — edit mode, passes fetched data */}
|
||||
<UserForm mode="edit" initialData={user} userId={userId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
284
src/pages/users/allUsersView/index.tsx
Normal file
284
src/pages/users/allUsersView/index.tsx
Normal file
@@ -0,0 +1,284 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
ChevronRight,
|
||||
Loader2,
|
||||
Pencil,
|
||||
Trash2,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
ChevronDown,
|
||||
Plus,
|
||||
Search,
|
||||
SlidersHorizontal,
|
||||
ChevronUp,
|
||||
} from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useUser, useDeleteUser } from '@/features/allUsers/hooks/useAllUsers'
|
||||
|
||||
// ─── Collapsible Section ──────────────────────────────────────────────────────
|
||||
|
||||
interface CollapsibleBlockProps {
|
||||
title: string
|
||||
actionLabel: string
|
||||
onAction: () => void
|
||||
emptyMessage: string
|
||||
searchPlaceholder?: string
|
||||
showFilter?: boolean
|
||||
}
|
||||
|
||||
function CollapsibleBlock({
|
||||
title,
|
||||
actionLabel,
|
||||
onAction,
|
||||
emptyMessage,
|
||||
searchPlaceholder = 'Gözlemek',
|
||||
showFilter = false,
|
||||
}: CollapsibleBlockProps) {
|
||||
const [open, setOpen] = useState(true)
|
||||
const [search, setSearch] = useState('')
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<button
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className="flex items-center gap-1.5 text-base font-semibold text-foreground mb-2 hover:opacity-80 transition-opacity select-none"
|
||||
>
|
||||
{title}
|
||||
{open ? <ChevronDown size={15} /> : <ChevronUp size={15} />}
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{/* Sub-toolbar */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-border">
|
||||
<div className="relative">
|
||||
<Search
|
||||
size={13}
|
||||
className="absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
value={search}
|
||||
onChange={(e) => setSearch(e.target.value)}
|
||||
placeholder={searchPlaceholder}
|
||||
className="h-8 pl-8 pr-3 rounded-md border border-border bg-background text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-ring w-48"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{showFilter && (
|
||||
<Button variant="outline" size="icon" className="h-8 w-8">
|
||||
<SlidersHorizontal size={13} />
|
||||
</Button>
|
||||
)}
|
||||
<Button size="sm" className="h-8 gap-1.5" onClick={onAction}>
|
||||
<Plus size={13} />
|
||||
{actionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Empty state */}
|
||||
<div className="flex flex-col items-center justify-center py-16 gap-3">
|
||||
<div className="w-16 h-16 rounded-lg border border-border bg-muted/30 flex items-center justify-center">
|
||||
<svg
|
||||
width="32"
|
||||
height="32"
|
||||
viewBox="0 0 32 32"
|
||||
fill="none"
|
||||
className="text-muted-foreground/40"
|
||||
>
|
||||
<rect x="4" y="8" width="24" height="18" rx="2" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M4 13h24" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M9 8V6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
<path d="M23 8V6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
<circle cx="22" cy="22" r="5" fill="currentColor" fillOpacity="0.1" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M22 20v4M20 22h4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">{emptyMessage}</p>
|
||||
<Button variant="outline" size="sm" onClick={onAction}>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── UserViewPage ─────────────────────────────────────────────────────────────
|
||||
|
||||
export default function UserViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const userId = Number(id)
|
||||
|
||||
const { data: user, isLoading, isError } = useUser(userId)
|
||||
const deleteUser = useDeleteUser()
|
||||
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
await deleteUser.mutateAsync(userId)
|
||||
navigate('/users')
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 size={24} className="animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !user) {
|
||||
return (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-4xl space-y-0">
|
||||
{/* Breadcrumb */}
|
||||
<nav className="flex items-center gap-1.5 text-xs text-muted-foreground mb-3">
|
||||
<button
|
||||
onClick={() => navigate('/users')}
|
||||
className="hover:text-foreground transition-colors"
|
||||
>
|
||||
{t('nav.resources', 'Resurslar')}
|
||||
</button>
|
||||
<ChevronRight size={12} />
|
||||
<button
|
||||
onClick={() => navigate('/users')}
|
||||
className="hover:text-foreground transition-colors"
|
||||
>
|
||||
{t('nav.users', 'Ulanyjylar')}
|
||||
</button>
|
||||
<ChevronRight size={12} />
|
||||
<span className="text-foreground font-medium">
|
||||
{t('users.viewTitle', 'Ulanyjy giňişleýin')}: {user.name} ({user.username})
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
{/* Title + actions */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<h1 className="text-xl font-bold text-foreground leading-tight">
|
||||
{t('users.viewTitle', 'Ulanyjy giňişleýin')}: {user.name} ({user.username})
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 shrink-0 ml-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10"
|
||||
onClick={() => setShowDeleteDialog(true)}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
onClick={() => navigate(`/users/${userId}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Main info */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={user.id} />
|
||||
<InfoRow label={t('users.fields.username', 'Ulanyjy ady')} value={user.username} />
|
||||
<InfoRow label={t('users.fields.name', 'Ady')} value={user.name} />
|
||||
<InfoRow label={t('users.fields.phone', 'Telefon')} value={user.phone} />
|
||||
<InfoRow label={t('users.fields.email', 'E-poçta')} value={user.email} />
|
||||
<InfoRow label={t('users.fields.isActive', 'Işjeň')}>
|
||||
{user.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-muted-foreground/40" />
|
||||
)}
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
{/* Rollar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.roles', 'Rollar')}
|
||||
actionLabel={t('users.actions.addRole', 'Rol birikdiriň')}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.roles', 'Berlen kriteriýalara Rol gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
/>
|
||||
|
||||
{/* Rugsatlar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.permissions', 'Rugsatlar')}
|
||||
actionLabel={t('users.actions.addPermission', 'Rugsat birikdiriň')}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.permissions', 'Berlen kriteriýalara Rugsat gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
/>
|
||||
|
||||
{/* Şahamçalar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.branches', 'Şahamçalar')}
|
||||
actionLabel={t('users.actions.addBranch', 'Şahamça birikdiriň')}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.branches', 'Berlen kriteriýalara Şahamça gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
showFilter
|
||||
/>
|
||||
|
||||
{/* Ammallar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.audit', 'Ammallar')}
|
||||
actionLabel={t('users.actions.addAction', 'Hereket')}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.audit', 'Berlen kriteriýalara Hereket gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
/>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('users.deleteDialog.title', 'Ulanyjyny öçürmek')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'users.deleteDialog.description',
|
||||
'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.',
|
||||
).replace('{name}', user.username)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýok')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{t('common.delete', 'Öçür')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
227
src/pages/users/clients/index.tsx
Normal file
227
src/pages/users/clients/index.tsx
Normal file
@@ -0,0 +1,227 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Trash2, Eye, Pencil } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { useClients, useDeleteClient } from '@/features/clients/hooks/useClients'
|
||||
import type { Client } from '@/features/clients/api/clientsApi'
|
||||
|
||||
export default function ClientsPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteMutation = useDeleteClient()
|
||||
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [isActiveFilter, setIsActiveFilter] = useState('')
|
||||
const [columnVisibility, setColumnVisibility] = useState({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
|
||||
const [deleteTarget, setDeleteTarget] = useState<Client | null>(null)
|
||||
|
||||
const { data, isLoading } = useClients({
|
||||
page,
|
||||
perPage,
|
||||
search: search || undefined,
|
||||
isActive: isActiveFilter || undefined,
|
||||
})
|
||||
|
||||
const clients = data?.data ?? []
|
||||
const totalPages = data?.meta.totalPages ?? 1
|
||||
const totalCount = data?.meta.totalCount ?? 0
|
||||
|
||||
const columns: ColumnDef<Client>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span
|
||||
className="text-primary font-semibold cursor-pointer hover:underline text-sm"
|
||||
onClick={() => navigate(`/clients/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'username',
|
||||
header: t('clients.fields.username', 'ULANYJY ADY'),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.username}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('clients.fields.name', 'ADY'),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
header: t('clients.fields.phone', 'TELEFON'),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.phone ?? '—'}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'email',
|
||||
header: t('clients.fields.email', 'E-POÇTA'),
|
||||
cell: ({ row }) => <span className="text-sm text-foreground">{row.original.email ?? '—'}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
header: t('clients.fields.isActive', 'IŞJEŇ'),
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<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>
|
||||
) : (
|
||||
<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>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/clients/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/clients/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteTarget(row.original)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 120,
|
||||
enableSorting: false,
|
||||
},
|
||||
]
|
||||
|
||||
const columnMetas = columns
|
||||
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: ('accessorKey' in c ? String(c.accessorKey) : c.id) as string,
|
||||
label: typeof c.header === 'string' ? c.header : ('accessorKey' in c ? String(c.accessorKey) : '') ?? '',
|
||||
}))
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('clients.title', 'Müşderiler')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('clients.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={[{ fieldId: 'isActive', value: isActiveFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === 'isActive') setIsActiveFilter(value)
|
||||
setPage(1)
|
||||
}}
|
||||
onFilterReset={() => { setIsActiveFilter(''); setPage(1) }}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('clients.createBtn', 'Müşderi dörediň')}
|
||||
onAction={() => navigate('/clients/create')}
|
||||
/>
|
||||
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={clients}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={totalCount}
|
||||
onPageChange={setPage}
|
||||
enableRowSelection
|
||||
/>
|
||||
|
||||
<AlertDialog open={!!deleteTarget} onOpenChange={(open) => !open && setDeleteTarget(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('clients.deleteTitle', 'Müşderini pozmak')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('clients.deleteConfirm', '{{name}} müşderisini pozmak isleýärsiňizmi? Bu amaly yzyna gaýtaryp bolmaz.', {
|
||||
name: deleteTarget?.name ?? '',
|
||||
})}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive hover:bg-destructive/90 text-destructive-foreground"
|
||||
onClick={() => {
|
||||
if (deleteTarget) {
|
||||
deleteMutation.mutate(deleteTarget.id, {
|
||||
onSuccess: () => setDeleteTarget(null),
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
34
src/pages/users/clientsCreate/index.tsx
Normal file
34
src/pages/users/clientsCreate/index.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import { ClientForm } from '@/features/clients/components/clientForm'
|
||||
|
||||
export default function ClientCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Breadcrumb */}
|
||||
<nav className="flex items-center gap-1.5 text-sm text-muted-foreground mb-4">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/clients')}
|
||||
>
|
||||
{t('clients.title', 'Müşderiler')}
|
||||
</span>
|
||||
<ChevronRight size={14} />
|
||||
<span className="text-foreground font-medium">
|
||||
{t('clients.createTitle', 'Müşderi dörediň')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('clients.createTitle', 'Müşderi dörediň')}
|
||||
</h1>
|
||||
|
||||
<ClientForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
src/pages/users/clientsEdit/index.tsx
Normal file
37
src/pages/users/clientsEdit/index.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { ClientForm } from '@/features/clients/components/clientForm'
|
||||
import { useClient } from '@/features/clients/hooks/useClients'
|
||||
|
||||
export default function ClientEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const clientId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: client, isLoading } = useClient(clientId)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('clients.editTitle', 'Müşderi üýtget')}: {client?.name ?? ''}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="h-14 bg-muted rounded-xl animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<ClientForm
|
||||
mode="edit"
|
||||
initialData={client}
|
||||
clientId={clientId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
294
src/pages/users/clientsView/index.tsx
Normal file
294
src/pages/users/clientsView/index.tsx
Normal file
@@ -0,0 +1,294 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2, ChevronDown, ChevronRight } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Section, InfoRow, AuditLog } from '@/components/viewPageComponents'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { useClient, useDeleteClient } from '@/features/clients/hooks/useClients'
|
||||
import type { ClientRole, ClientBranch, ClientAuditLog } from '@/features/clients/api/clientsApi'
|
||||
|
||||
export default function ClientDetailPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const clientId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteMutation = useDeleteClient()
|
||||
|
||||
const { data: client, isLoading } = useClient(clientId)
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
const [roleSearch, setRoleSearch] = useState('')
|
||||
const [permSearch, setPermSearch] = useState('')
|
||||
const [branchSearch, setBranchSearch] = useState('')
|
||||
const [loanSearch, setLoanSearch] = useState('')
|
||||
const [cardSearch, setCardSearch] = useState('')
|
||||
|
||||
const roleColumns: ColumnDef<ClientRole>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
header: t('roles.fields.code', 'KOD'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.code}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('roles.fields.name', 'ADY'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'guardName',
|
||||
header: t('roles.fields.guardName', 'GUARD NAME'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.guardName}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: () => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-destructive">
|
||||
<Trash2 size={13} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 60,
|
||||
},
|
||||
]
|
||||
|
||||
const branchColumns: ColumnDef<ClientBranch>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => <span className="text-primary font-semibold text-sm">{row.original.id}</span>,
|
||||
size: 60,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('branches.fields.name', 'ADY'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'region',
|
||||
header: t('branches.fields.region', 'WELAÝAT'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.region}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'district',
|
||||
header: t('branches.fields.district', 'ETRAP'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.district}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'uniqueCode',
|
||||
header: t('branches.fields.uniqueCode', 'UNIKAL BELGI'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.uniqueCode}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: () => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-destructive">
|
||||
<Trash2 size={13} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 60,
|
||||
},
|
||||
]
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="h-16 bg-muted rounded-xl animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!client) return null
|
||||
|
||||
const auditLogs = (client.auditLogs ?? []).map((log: ClientAuditLog) => ({
|
||||
id: String(log.id),
|
||||
action: log.actionName,
|
||||
by: log.performedBy,
|
||||
target: log.target,
|
||||
status: log.status,
|
||||
date: log.createdAt,
|
||||
}))
|
||||
|
||||
const filteredRoles = (client.roles ?? []).filter((r) =>
|
||||
r.name.toLowerCase().includes(roleSearch.toLowerCase()) || r.code.toLowerCase().includes(roleSearch.toLowerCase()),
|
||||
)
|
||||
|
||||
const filteredBranches = (client.branches ?? []).filter((b) =>
|
||||
b.name.toLowerCase().includes(branchSearch.toLowerCase()),
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<nav className="flex items-center gap-1.5 text-sm text-muted-foreground mb-4">
|
||||
<span className="cursor-pointer hover:text-foreground transition-colors" onClick={() => navigate('/clients')}>
|
||||
{t('clients.title', 'Müşderiler')}
|
||||
</span>
|
||||
<ChevronRight size={14} />
|
||||
<span className="text-foreground font-medium">
|
||||
{t('clients.detailTitle', 'Müşderi giňişleýin')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('clients.detailTitle', 'Müşderi giňişleýin')}: {client.name}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8 text-muted-foreground hover:text-destructive" onClick={() => setDeleteOpen(true)}>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<Button size="icon" variant="ghost" className="h-8 w-8 text-muted-foreground hover:text-foreground" onClick={() => navigate(`/clients/${clientId}/edit`)}>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Section>
|
||||
<InfoRow label="ID" value={client.id} />
|
||||
<InfoRow label={t('clients.fields.username', 'Ulanyjy ady')} value={client.username} />
|
||||
<InfoRow label={t('clients.fields.name', 'Ady')} value={client.name} />
|
||||
<InfoRow label={t('clients.fields.phone', 'Telefon')} value={client.phone ?? '—'} />
|
||||
<InfoRow label={t('clients.fields.email', 'E-poçta')} value={client.email ?? '—'} />
|
||||
<InfoRow label={t('clients.fields.isActive', 'Işjeň')}>
|
||||
{client.isActive ? (
|
||||
<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>
|
||||
) : (
|
||||
<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>
|
||||
)}
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
<CollapsibleSection title={t('clients.sections.roles', 'Rollar')} actionLabel={t('clients.addRole', 'Rol birikdiriň')} onAction={() => {}}>
|
||||
<DataTableToolbar searchValue={roleSearch} onSearchChange={setRoleSearch} searchPlaceholder={t('common.search', 'Gözlemek')} columns={[]} columnVisibility={{}} onColumnVisibilityChange={() => {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction />
|
||||
{(filteredRoles.length > 0) ? (
|
||||
<DataTable columns={roleColumns} data={filteredRoles} getRowId={(r) => String(r.id)} enableRowSelection />
|
||||
) : (
|
||||
<EmptyState label={t('clients.noRoles', 'Berlen kriterýalara Rol gabat gelmedi.')} actionLabel={t('clients.addRole', 'Rol birikdiriň')} onAction={() => {}} />
|
||||
)}
|
||||
</CollapsibleSection>
|
||||
|
||||
<CollapsibleSection title={t('clients.sections.permissions', 'Rugsatlar')} actionLabel={t('clients.addPermission', 'Rugsat birikdiriň')} onAction={() => {}}>
|
||||
<DataTableToolbar searchValue={permSearch} onSearchChange={setPermSearch} searchPlaceholder={t('common.search', 'Gözlemek')} columns={[]} columnVisibility={{}} onColumnVisibilityChange={() => {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction />
|
||||
{(client.permissions ?? []).length === 0 ? (
|
||||
<EmptyState label={t('clients.noPermissions', 'Berlen kriterýalara Rugsat gabat gelmedi.')} actionLabel={t('clients.addPermission', 'Rugsat birikdiriň')} onAction={() => {}} />
|
||||
) : null}
|
||||
</CollapsibleSection>
|
||||
|
||||
<CollapsibleSection title={t('clients.sections.branches', 'Şahamçalar')} actionLabel={t('clients.addBranch', 'Şahamça birikdiriň')} onAction={() => {}}>
|
||||
<DataTableToolbar searchValue={branchSearch} onSearchChange={setBranchSearch} searchPlaceholder={t('common.search', 'Gözlemek')} columns={[]} columnVisibility={{}} onColumnVisibilityChange={() => {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction />
|
||||
{(filteredBranches.length > 0) ? (
|
||||
<DataTable columns={branchColumns} data={filteredBranches} getRowId={(r) => String(r.id)} enableRowSelection />
|
||||
) : (
|
||||
<EmptyState label={t('clients.noBranches', 'Berlen kriterýalara Şahamça gabat gelmedi.')} actionLabel={t('clients.addBranch', 'Şahamça birikdiriň')} onAction={() => {}} />
|
||||
)}
|
||||
</CollapsibleSection>
|
||||
|
||||
<CollapsibleSection title={t('clients.sections.loanOrders', 'Karz sargyt')} actionLabel={t('clients.addLoanOrder', 'Karz sargyt dörediň')} onAction={() => {}}>
|
||||
<DataTableToolbar searchValue={loanSearch} onSearchChange={setLoanSearch} searchPlaceholder={t('common.search', 'Gözlemek')} columns={[]} columnVisibility={{}} onColumnVisibilityChange={() => {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction />
|
||||
{(client.loanOrders ?? []).length === 0 ? (
|
||||
<EmptyState label={t('clients.noLoanOrders', 'Berlen kriterýalara Karz sargyt gabat gelmedi.')} actionLabel={t('clients.addLoanOrder', 'Karz sargyt dörediň')} onAction={() => {}} />
|
||||
) : null}
|
||||
</CollapsibleSection>
|
||||
|
||||
<CollapsibleSection title={t('clients.sections.cardOrders', 'Kart sargyt')} actionLabel={t('clients.addCardOrder', 'Kart sargyt dörediň')} onAction={() => {}}>
|
||||
<DataTableToolbar searchValue={cardSearch} onSearchChange={setCardSearch} searchPlaceholder={t('common.search', 'Gözlemek')} columns={[]} columnVisibility={{}} onColumnVisibilityChange={() => {}} columnOrder={[]} onColumnOrderChange={() => {}} hideAction />
|
||||
{(client.cardOrders ?? []).length === 0 ? (
|
||||
<EmptyState label={t('clients.noCardOrders', 'Berlen kriterýalara Kart sargyt gabat gelmedi.')} actionLabel={t('clients.addCardOrder', 'Kart sargyt dörediň')} onAction={() => {}} />
|
||||
) : null}
|
||||
</CollapsibleSection>
|
||||
|
||||
<AuditLog logs={auditLogs} />
|
||||
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('clients.deleteTitle', 'Müşderini pozmak')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('clients.deleteConfirm', '{{name}} müşderisini pozmak isleýärsiňizmi?', { name: client.name })}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction className="bg-destructive hover:bg-destructive/90 text-destructive-foreground" onClick={() => deleteMutation.mutate(clientId, { onSuccess: () => navigate('/clients') })}>
|
||||
{t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface CollapsibleSectionProps { title: string; actionLabel: string; onAction: () => void; children: React.ReactNode }
|
||||
function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) {
|
||||
const [open, setOpen] = useState(true)
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<div className="flex items-center justify-between mb-2 cursor-pointer select-none w-fit gap-2" onClick={() => setOpen((v) => !v)}>
|
||||
<h2 className="text-base font-semibold text-foreground">{title}</h2>
|
||||
<ChevronDown size={15} className={`text-muted-foreground transition-transform duration-200 ${open ? '' : '-rotate-90'}`} />
|
||||
</div>
|
||||
{open && (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden p-4 space-y-3">
|
||||
<div className="flex justify-end">
|
||||
<Button size="sm" className="bg-primary hover:bg-primary/90 text-primary-foreground h-8 text-xs" onClick={onAction}>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
interface EmptyStateProps { label: string; actionLabel: string; onAction: () => void }
|
||||
function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-12 gap-4">
|
||||
<div className="w-16 h-16 rounded-full bg-muted flex items-center justify-center">
|
||||
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" className="text-muted-foreground">
|
||||
<rect x="4" y="8" width="24" height="18" rx="2" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M4 13h24" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M10 8V6M22 8V6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
<circle cx="16" cy="20" r="3" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M19 23l2 2" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground text-center">{label}</p>
|
||||
<Button size="sm" variant="outline" className="h-8 text-xs" onClick={onAction}>{actionLabel}</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
271
src/pages/users/operators/index.tsx
Normal file
271
src/pages/users/operators/index.tsx
Normal file
@@ -0,0 +1,271 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Trash2, Eye, Pencil } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { useOperators, useDeleteOperator } from '@/features/operators/hooks/useOperators'
|
||||
import type { Operator } from '@/features/operators/api/operatorsApi'
|
||||
|
||||
// ─── OperatorsPage ────────────────────────────────────────────────────────────
|
||||
|
||||
export default function OperatorsPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteMutation = useDeleteOperator()
|
||||
|
||||
// ── Table state ─────────────────────────────────────────────────────────────
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [isActiveFilter, setIsActiveFilter] = useState('')
|
||||
const [columnVisibility, setColumnVisibility] = useState({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
|
||||
// ── Delete dialog ────────────────────────────────────────────────────────────
|
||||
const [deleteTarget, setDeleteTarget] = useState<Operator | null>(null)
|
||||
|
||||
// ── Query ────────────────────────────────────────────────────────────────────
|
||||
const { data, isLoading } = useOperators({
|
||||
page,
|
||||
perPage,
|
||||
search: search || undefined,
|
||||
isActive: isActiveFilter || undefined,
|
||||
})
|
||||
|
||||
const operators = data?.data ?? []
|
||||
const totalPages = data?.meta.totalPages ?? 1
|
||||
const totalCount = data?.meta.totalCount ?? 0
|
||||
|
||||
// ── Columns ──────────────────────────────────────────────────────────────────
|
||||
const columns: ColumnDef<Operator>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span
|
||||
className="text-primary font-semibold cursor-pointer hover:underline text-sm"
|
||||
onClick={() => navigate(`/operators/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'username',
|
||||
header: t('operators.fields.username', 'ULANYJY ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.username}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('operators.fields.name', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
header: t('operators.fields.phone', 'TELEFON'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.phone ?? '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'email',
|
||||
header: t('operators.fields.email', 'E-POÇTA'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">
|
||||
{row.original.email ?? '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
header: t('operators.fields.isActive', 'IŞJEŇ'),
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<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>
|
||||
) : (
|
||||
<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>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/operators/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/operators/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteTarget(row.original)}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 120,
|
||||
enableSorting: false,
|
||||
},
|
||||
]
|
||||
|
||||
const columnMetas = columns
|
||||
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: ('accessorKey' in c ? String(c.accessorKey) : c.id) as string,
|
||||
label:
|
||||
typeof c.header === 'string'
|
||||
? c.header
|
||||
: ('accessorKey' in c ? String(c.accessorKey) : '') ?? '',
|
||||
}))
|
||||
|
||||
// ── Render ───────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Page header */}
|
||||
<div className="mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('operators.title', 'Operatorlar')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMetas}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={[
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('operators.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
]}
|
||||
activeFilters={[{ fieldId: 'isActive', value: isActiveFilter }]}
|
||||
onFilterChange={(fieldId, value) => {
|
||||
if (fieldId === 'isActive') setIsActiveFilter(value)
|
||||
setPage(1)
|
||||
}}
|
||||
onFilterReset={() => { setIsActiveFilter(''); setPage(1) }}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('operators.createBtn', 'Operator döredin')}
|
||||
onAction={() => navigate('/operators/create')}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={operators}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={page}
|
||||
totalPages={totalPages}
|
||||
totalCount={totalCount}
|
||||
onPageChange={setPage}
|
||||
enableRowSelection
|
||||
/>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog
|
||||
open={!!deleteTarget}
|
||||
onOpenChange={(open) => !open && setDeleteTarget(null)}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('operators.deleteTitle', 'Operatory pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'operators.deleteConfirm',
|
||||
'{{name}} operatoryny pozmak isleýärsiňizmi? Bu amaly yzyna gaýtaryp bolmaz.',
|
||||
{ name: deleteTarget?.name ?? '' },
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive hover:bg-destructive/90 text-destructive-foreground"
|
||||
onClick={() => {
|
||||
if (deleteTarget) {
|
||||
deleteMutation.mutate(deleteTarget.id, {
|
||||
onSuccess: () => setDeleteTarget(null),
|
||||
})
|
||||
}
|
||||
}}
|
||||
>
|
||||
{t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
36
src/pages/users/operatorsCreate/index.tsx
Normal file
36
src/pages/users/operatorsCreate/index.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
// ─── OperatorCreatePage.tsx ───────────────────────────────────────────────────
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { ChevronRight } from 'lucide-react'
|
||||
import { OperatorForm } from '@/features/operators/components/operatorForms'
|
||||
|
||||
export default function OperatorCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Breadcrumb */}
|
||||
<nav className="flex items-center gap-1.5 text-sm text-muted-foreground mb-4">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/operators')}
|
||||
>
|
||||
{t('operators.title', 'Operatorlar')}
|
||||
</span>
|
||||
<ChevronRight size={14} />
|
||||
<span className="text-foreground font-medium">
|
||||
{t('operators.createTitle', 'Operator döredin')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('operators.createTitle', 'Operator döredin')}
|
||||
</h1>
|
||||
|
||||
<OperatorForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
37
src/pages/users/operatorsEdit/index.tsx
Normal file
37
src/pages/users/operatorsEdit/index.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
// ─── OperatorEditPage.tsx ─────────────────────────────────────────────────────
|
||||
|
||||
import { useParams, } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { OperatorForm } from '@/features/operators/components/operatorForms'
|
||||
import { useOperator } from '@/features/operators/hooks/useOperators'
|
||||
|
||||
export default function OperatorEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const operatorId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: operator, isLoading } = useOperator(operatorId)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Page heading */}
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('operators.editTitle', 'Operator üýtget')}: {operator?.name ?? ''}
|
||||
</h1>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="space-y-3">
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className="h-14 bg-muted rounded-xl animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<OperatorForm
|
||||
mode="edit"
|
||||
initialData={operator}
|
||||
operatorId={operatorId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
457
src/pages/users/operatorsView/index.tsx
Normal file
457
src/pages/users/operatorsView/index.tsx
Normal file
@@ -0,0 +1,457 @@
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2, ChevronDown } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Section, InfoRow, AuditLog } from '@/components/viewPageComponents'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { useOperator, useDeleteOperator } from '@/features/operators/hooks/useOperators'
|
||||
import type { OperatorRole, OperatorBranch, OperatorAuditLog } from '@/features/operators/api/operatorsApi'
|
||||
|
||||
// ─── OperatorDetailPage ───────────────────────────────────────────────────────
|
||||
|
||||
export default function OperatorDetailPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const operatorId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const deleteMutation = useDeleteOperator()
|
||||
|
||||
const { data: operator, isLoading } = useOperator(operatorId)
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
const [roleSearch, setRoleSearch] = useState('')
|
||||
const [permSearch, setPermSearch] = useState('')
|
||||
const [branchSearch, setBranchSearch] = useState('')
|
||||
|
||||
// ── Role columns ──────────────────────────────────────────────────────────
|
||||
const roleColumns: ColumnDef<OperatorRole>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold text-sm">{row.original.id}</span>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
header: t('roles.fields.code', 'KOD'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.code}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('roles.fields.name', 'ADY'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'guardName',
|
||||
header: t('roles.fields.guardName', 'GUARD NAME'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.guardName}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/roles/${row.original.id}`)}
|
||||
>
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<Pencil size={13} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-7 w-7 text-muted-foreground hover:text-destructive"
|
||||
>
|
||||
<Trash2 size={13} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
]
|
||||
|
||||
// ── Branch columns ────────────────────────────────────────────────────────
|
||||
const branchColumns: ColumnDef<OperatorBranch>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold text-sm">{row.original.id}</span>
|
||||
),
|
||||
size: 60,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('branches.fields.name', 'ADY'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.name}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'region',
|
||||
header: t('branches.fields.region', 'WELAÝAT'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.region}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'district',
|
||||
header: t('branches.fields.district', 'ETRAP'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.district}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'uniqueCode',
|
||||
header: t('branches.fields.uniqueCode', 'UNIKAL BELGI'),
|
||||
cell: ({ row }) => <span className="text-sm">{row.original.uniqueCode}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
header: t('branches.fields.isActive', 'IŞJEŇ'),
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<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>
|
||||
) : (
|
||||
<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>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'billingUsernameIbr',
|
||||
header: t('branches.fields.billingIbr', 'BILLING ULANYJY ADY'),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-xs">{row.original.billingUsernameIbr}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'billingUsernameSber',
|
||||
header: t('branches.fields.billingSber', 'BILLING USERNAME (SBER)'),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-xs">{row.original.billingUsernameSber}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'billingUsernameVisa',
|
||||
header: t('branches.fields.billingVisa', 'BILLING USERNAME (VISA)'),
|
||||
cell: ({ row }) => <span className="text-sm font-mono text-xs">{row.original.billingUsernameVisa}</span>,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: () => (
|
||||
<div className="flex items-center gap-1 justify-end">
|
||||
<Button size="icon" variant="ghost" className="h-7 w-7 text-muted-foreground hover:text-foreground">
|
||||
<Trash2 size={13} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 60,
|
||||
},
|
||||
]
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="h-16 bg-muted rounded-xl animate-pulse" />
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!operator) return null
|
||||
|
||||
// Map audit logs to AuditLog component format
|
||||
const auditLogs = (operator.auditLogs ?? []).map((log: OperatorAuditLog) => ({
|
||||
id: String(log.id),
|
||||
action: log.actionName,
|
||||
by: log.performedBy,
|
||||
target: log.target,
|
||||
status: log.status,
|
||||
date: log.createdAt,
|
||||
}))
|
||||
|
||||
const filteredRoles = (operator.roles ?? []).filter(
|
||||
(r) =>
|
||||
r.name.toLowerCase().includes(roleSearch.toLowerCase()) ||
|
||||
r.code.toLowerCase().includes(roleSearch.toLowerCase()),
|
||||
)
|
||||
|
||||
const filteredBranches = (operator.branches ?? []).filter((b) =>
|
||||
b.name.toLowerCase().includes(branchSearch.toLowerCase()),
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Page header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('operators.detailTitle', 'Operator giňişleýin')}: {operator.name}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
size="icon"
|
||||
variant="ghost"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/operators/${operatorId}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Basic info */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={operator.id} />
|
||||
<InfoRow label={t('operators.fields.username', 'Ulanyjy ady')} value={operator.username} />
|
||||
<InfoRow label={t('operators.fields.name', 'Ady')} value={operator.name} />
|
||||
<InfoRow label={t('operators.fields.phone', 'Telefon')} value={operator.phone ?? '—'} />
|
||||
<InfoRow label={t('operators.fields.email', 'E-poçta')} value={operator.email ?? '—'} />
|
||||
<InfoRow label={t('operators.fields.isActive', 'Işjeň')}>
|
||||
{operator.isActive ? (
|
||||
<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>
|
||||
) : (
|
||||
<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>
|
||||
)}
|
||||
</InfoRow>
|
||||
</Section>
|
||||
|
||||
{/* Roles */}
|
||||
<CollapsibleSection
|
||||
title={t('operators.sections.roles', 'Rollar')}
|
||||
actionLabel={t('operators.addRole', 'Rol birikdiriň')}
|
||||
onAction={() => {/* open role assign modal */}}
|
||||
>
|
||||
<DataTableToolbar
|
||||
searchValue={roleSearch}
|
||||
onSearchChange={setRoleSearch}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
hideAction
|
||||
/>
|
||||
<DataTable
|
||||
columns={roleColumns}
|
||||
data={filteredRoles}
|
||||
getRowId={(r) => String(r.id)}
|
||||
enableRowSelection
|
||||
/>
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Permissions */}
|
||||
<CollapsibleSection
|
||||
title={t('operators.sections.permissions', 'Rugsatlar')}
|
||||
actionLabel={t('operators.addPermission', 'Rugsat birikdiriň')}
|
||||
onAction={() => {/* open permission modal */}}
|
||||
>
|
||||
<DataTableToolbar
|
||||
searchValue={permSearch}
|
||||
onSearchChange={setPermSearch}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
hideAction
|
||||
/>
|
||||
{(operator.permissions ?? []).length === 0 ? (
|
||||
<EmptyState label={t('operators.noPermissions', 'Berlen kriterýalara Rugsat gabat gelmedi.')} actionLabel={t('operators.addPermission', 'Rugsat birikdiriň')} onAction={() => {}} />
|
||||
) : null}
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Branches */}
|
||||
<CollapsibleSection
|
||||
title={t('operators.sections.branches', 'Şahamçalar')}
|
||||
actionLabel={t('operators.addBranch', 'Şahamça birikdiriň')}
|
||||
onAction={() => {}}
|
||||
>
|
||||
<DataTableToolbar
|
||||
searchValue={branchSearch}
|
||||
onSearchChange={setBranchSearch}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={[]}
|
||||
columnVisibility={{}}
|
||||
onColumnVisibilityChange={() => {}}
|
||||
columnOrder={[]}
|
||||
onColumnOrderChange={() => {}}
|
||||
hideAction
|
||||
/>
|
||||
<DataTable
|
||||
columns={branchColumns}
|
||||
data={filteredBranches}
|
||||
getRowId={(r) => String(r.id)}
|
||||
enableRowSelection
|
||||
/>
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Karz sargyt */}
|
||||
<CollapsibleSection
|
||||
title={t('operators.sections.loanLimits', 'Karz sargyt')}
|
||||
actionLabel={t('operators.addLoanLimit', 'Karz sargyt döredin')}
|
||||
onAction={() => {}}
|
||||
>
|
||||
{(operator.loanLimits ?? []).length === 0 ? (
|
||||
<EmptyState label={t('operators.noLoanLimits', 'Berlen kriterýalara Karz sargyt gabat gelmedi.')} actionLabel={t('operators.addLoanLimit', 'Karz sargyt döredin')} onAction={() => {}} />
|
||||
) : null}
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Kart sargyt */}
|
||||
<CollapsibleSection
|
||||
title={t('operators.sections.cardLimits', 'Kart sargyt')}
|
||||
actionLabel={t('operators.addCardLimit', 'Kart sargyt döredin')}
|
||||
onAction={() => {}}
|
||||
>
|
||||
{(operator.cardLimits ?? []).length === 0 ? (
|
||||
<EmptyState label={t('operators.noCardLimits', 'Berlen kriterýalara Kart sargyt gabat gelmedi.')} actionLabel={t('operators.addCardLimit', 'Kart sargyt döredin')} onAction={() => {}} />
|
||||
) : null}
|
||||
</CollapsibleSection>
|
||||
|
||||
{/* Audit log */}
|
||||
<AuditLog logs={auditLogs} />
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('operators.deleteTitle', 'Operatory pozmak')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('operators.deleteConfirm', '{{name}} operatoryny pozmak isleýärsiňizmi?', {
|
||||
name: operator.name,
|
||||
})}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive hover:bg-destructive/90 text-destructive-foreground"
|
||||
onClick={() =>
|
||||
deleteMutation.mutate(operatorId, {
|
||||
onSuccess: () => navigate('/operators'),
|
||||
})
|
||||
}
|
||||
>
|
||||
{t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── CollapsibleSection ───────────────────────────────────────────────────────
|
||||
|
||||
interface CollapsibleSectionProps {
|
||||
title: string
|
||||
actionLabel: string
|
||||
onAction: () => void
|
||||
children: React.ReactNode
|
||||
}
|
||||
|
||||
function CollapsibleSection({ title, actionLabel, onAction, children }: CollapsibleSectionProps) {
|
||||
const [open, setOpen] = useState(true)
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
<div
|
||||
className="flex items-center justify-between mb-2 cursor-pointer select-none w-fit gap-2"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
>
|
||||
<h2 className="text-base font-semibold text-foreground">{title}</h2>
|
||||
<ChevronDown
|
||||
size={15}
|
||||
className={`text-muted-foreground transition-transform duration-200 ${open ? '' : '-rotate-90'}`}
|
||||
/>
|
||||
</div>
|
||||
{open && (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden p-4 space-y-3">
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
size="sm"
|
||||
className="bg-primary hover:bg-primary/90 text-primary-foreground h-8 text-xs"
|
||||
onClick={onAction}
|
||||
>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── EmptyState ───────────────────────────────────────────────────────────────
|
||||
|
||||
interface EmptyStateProps {
|
||||
label: string
|
||||
actionLabel: string
|
||||
onAction: () => void
|
||||
}
|
||||
|
||||
function EmptyState({ label, actionLabel, onAction }: EmptyStateProps) {
|
||||
return (
|
||||
<div className="flex flex-col items-center justify-center py-12 gap-4">
|
||||
<div className="w-16 h-16 rounded-full bg-muted flex items-center justify-center">
|
||||
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" className="text-muted-foreground">
|
||||
<rect x="4" y="8" width="24" height="18" rx="2" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M4 13h24" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M10 8V6M22 8V6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
<circle cx="16" cy="20" r="3" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M19 23l2 2" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
</svg>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground text-center">{label}</p>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="h-8 text-xs"
|
||||
onClick={onAction}
|
||||
>
|
||||
{actionLabel}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user