added some new pages
This commit is contained in:
208
src/pages/currencies/currencyRates/index.tsx
Normal file
208
src/pages/currencies/currencyRates/index.tsx
Normal file
@@ -0,0 +1,208 @@
|
||||
// pages/CurrencyRatesPage.tsx
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import { DataTable, type ColumnDef } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { useGetCurrencyRates, useDeleteCurrencyRate } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||
import type { CurrencyRate } from '@/features/currencyRates/api/currencyRatesApi'
|
||||
|
||||
// ─── Column visibility defaults ───────────────────────────────────────────────
|
||||
|
||||
const DEFAULT_VISIBILITY = { id: true, currencyFrom: true, currencyTo: true, value: true }
|
||||
const DEFAULT_ORDER = ['id', 'currencyFrom', 'currencyTo', 'value', 'actions']
|
||||
|
||||
// ─── CurrencyRatesPage ────────────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRatesPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>(DEFAULT_VISIBILITY)
|
||||
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER)
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
const { data, isLoading } = useGetCurrencyRates({ page, perPage, search })
|
||||
const deleteMutation = useDeleteCurrencyRate()
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (deleteId === null) return
|
||||
await deleteMutation.mutateAsync(deleteId)
|
||||
setDeleteId(null)
|
||||
}
|
||||
|
||||
const handleSearchChange = (val: string) => {
|
||||
setSearch(val)
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<CurrencyRate>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<button
|
||||
className="text-primary font-semibold hover:underline"
|
||||
onClick={() => navigate(`/resources/currency-rates/${row.original.id}`)}
|
||||
>
|
||||
{row.original.id}
|
||||
</button>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'currencyFrom',
|
||||
header: t('currencyRates.columns.currencyFrom', 'CURRENCY FROM'),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium text-foreground">{row.original.currencyFrom}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'currencyTo',
|
||||
header: t('currencyRates.columns.currencyTo', 'CURRENCY TO'),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium text-foreground">{row.original.currencyTo}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'value',
|
||||
header: t('currencyRates.columns.value', 'VALUE'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground tabular-nums">{row.original.value}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/currency-rates/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/currency-rates/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
]
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: String(('accessorKey' in c ? c.accessorKey : c.id) ?? ''),
|
||||
label: typeof c.header === 'string' ? c.header : String(('accessorKey' in c ? c.accessorKey : '') ?? ''),
|
||||
}))
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||
{t('currencyRates.title', 'Walýuta kursy')}
|
||||
</h1>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('currencyRates.actions.create', 'Walýuta kursy dörediň')}
|
||||
onAction={() => navigate('/currency-rates/create')}
|
||||
/>
|
||||
|
||||
<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 ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete Confirmation Dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={(open) => { if (!open) setDeleteId(null) }}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('currencyRates.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'currencyRates.deleteDialog.description',
|
||||
'Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.'
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Pozmak')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
23
src/pages/currencies/currencyRatesCreate/index.tsx
Normal file
23
src/pages/currencies/currencyRatesCreate/index.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
// pages/CurrencyRateCreatePage.tsx
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CurrencyRateForm } from '@/features/currencyRates/components/currencyRatesForm'
|
||||
|
||||
// ─── CurrencyRateCreatePage ───────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRateCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('currencyRates.actions.create', 'Walýuta kursy dörediň')}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<CurrencyRateForm mode="create" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
57
src/pages/currencies/currencyRatesEdit/index.tsx
Normal file
57
src/pages/currencies/currencyRatesEdit/index.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
// pages/CurrencyRateEditPage.tsx
|
||||
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CurrencyRateForm } from '@/features/currencyRates/components/currencyRatesForm'
|
||||
import { useGetCurrencyRateById } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||
|
||||
// ─── CurrencyRateEditPage ─────────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRateEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const numericId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: rate, isLoading } = useGetCurrencyRateById(numericId)
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="h-6 w-64 bg-muted rounded animate-pulse" />
|
||||
<div className="h-48 bg-muted rounded-xl animate-pulse" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!rate) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">
|
||||
{t('currencyRates.notFound', 'Walýuta kursy tapylmady')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('currencyRates.detail.editTitle', 'Walýuta kursyny üýtgetmek')}: {rate.id}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<CurrencyRateForm
|
||||
mode="edit"
|
||||
initialData={rate}
|
||||
rateId={numericId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
137
src/pages/currencies/currencyRatesView/index.tsx
Normal file
137
src/pages/currencies/currencyRatesView/index.tsx
Normal file
@@ -0,0 +1,137 @@
|
||||
// pages/CurrencyRateDetailPage.tsx
|
||||
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useGetCurrencyRateById, useDeleteCurrencyRate } from '@/features/currencyRates/hooks/useCurrencyRates'
|
||||
|
||||
// ─── CurrencyRateDetailPage ───────────────────────────────────────────────────
|
||||
|
||||
export default function CurrencyRateDetailPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const numericId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
const { data: rate, isLoading } = useGetCurrencyRateById(numericId)
|
||||
const deleteMutation = useDeleteCurrencyRate()
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
await deleteMutation.mutateAsync(numericId)
|
||||
navigate('/resources/currency-rates')
|
||||
}
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="h-6 w-64 bg-muted rounded animate-pulse" />
|
||||
<div className="h-48 bg-muted rounded-xl animate-pulse" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!rate) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">
|
||||
{t('currencyRates.notFound', 'Walýuta kursy tapylmady')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground">
|
||||
{t('currencyRates.detail.title', 'Walýuta kursy giňişleýin')}: {rate.id}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={18} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-foreground"
|
||||
onClick={() => navigate(`/resources/currency-rates/${rate.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={18} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail Card */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={rate.id} />
|
||||
<InfoRow label={t('currencyRates.fields.currencyFrom', 'Currency from')} value={rate.currencyFrom} />
|
||||
<InfoRow label={t('currencyRates.fields.currencyTo', 'Currency to')} value={rate.currencyTo} />
|
||||
<InfoRow label={t('currencyRates.fields.value', 'Value')} value={rate.value} />
|
||||
<InfoRow label={t('common.createdAt', 'Döredilen senesi')}
|
||||
value={new Date(rate.createdAt).toLocaleString()}
|
||||
/>
|
||||
<InfoRow label={t('common.updatedAt', 'Üýtgedilen senesi')}
|
||||
value={new Date(rate.updatedAt).toLocaleString()}
|
||||
/>
|
||||
</Section>
|
||||
|
||||
{/* Delete Dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('currencyRates.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'currencyRates.deleteDialog.description',
|
||||
'Bu amal yzyna gaýtarylyp bilinmez. Walýuta kursy hemişelik pozular.'
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Pozmak')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
204
src/pages/currencies/visaMasterSberSettings/index.tsx
Normal file
204
src/pages/currencies/visaMasterSberSettings/index.tsx
Normal file
@@ -0,0 +1,204 @@
|
||||
// pages/VisaMasterSettingsPage.tsx
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } 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 {
|
||||
useGetVisaMasterSettings,
|
||||
useDeleteVisaMasterSetting,
|
||||
} from '@/features/visaMasterSberSettings/hooks/useVisaMasterSettings'
|
||||
import type { VisaMasterSetting } from '@/features/visaMasterSberSettings/api/visaMasterSberSettingsApi'
|
||||
|
||||
// ─── Column defaults ──────────────────────────────────────────────────────────
|
||||
|
||||
const DEFAULT_VISIBILITY = { id: true, kod: true, ady: true, yazgy: true }
|
||||
const DEFAULT_ORDER = ['id', 'kod', 'ady', 'yazgy', 'actions']
|
||||
|
||||
// ─── VisaMasterSettingsPage ───────────────────────────────────────────────────
|
||||
|
||||
export default function VisaMasterSettingsPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [columnVisibility, setColumnVisibility] = useState<Record<string, boolean>>(DEFAULT_VISIBILITY)
|
||||
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER)
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
const { data, isLoading } = useGetVisaMasterSettings({ page, perPage, search })
|
||||
const deleteMutation = useDeleteVisaMasterSetting()
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
if (deleteId === null) return
|
||||
await deleteMutation.mutateAsync(deleteId)
|
||||
setDeleteId(null)
|
||||
}
|
||||
|
||||
const handleSearchChange = (val: string) => {
|
||||
setSearch(val)
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<VisaMasterSetting>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||
),
|
||||
size: 80,
|
||||
},
|
||||
{
|
||||
accessorKey: 'kod',
|
||||
header: t('visaMasterSettings.columns.kod', 'KOD'),
|
||||
cell: ({ row }) => (
|
||||
<span className="font-medium text-foreground font-mono text-xs">
|
||||
{row.original.kod}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'ady',
|
||||
header: t('visaMasterSettings.columns.ady', 'ADY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground">{row.original.ady}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'yazgy',
|
||||
header: t('visaMasterSettings.columns.yazgy', 'YAZGY'),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground line-clamp-1 max-w-xs">{row.original.yazgy}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() =>
|
||||
navigate(`/visa-master-sber-settings/${row.original.id}/edit`)
|
||||
}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Pozmak')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
]
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => 'accessorKey' in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: String(('accessorKey' in c ? c.accessorKey : c.id) ?? ''),
|
||||
label: typeof c.header === 'string' ? c.header : String(('accessorKey' in c ? c.accessorKey : '') ?? ''),
|
||||
}))
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||
{t('visaMasterSettings.title', 'Visa/Master, Sber sazlamalar')}
|
||||
</h1>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
actionLabel={t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')}
|
||||
onAction={() => navigate('/visa-master-sber-settings/create')}
|
||||
/>
|
||||
|
||||
<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 ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete Confirmation */}
|
||||
<AlertDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('visaMasterSettings.deleteDialog.title', 'Pozmak isleýärsiňizmi?')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'visaMasterSettings.deleteDialog.description',
|
||||
'Bu amal yzyna gaýtarylyp bilinmez. Sazlama hemişelik pozular.'
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
disabled={deleteMutation.isPending}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Pozmak')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
24
src/pages/currencies/visaMasterSberSettingsCreate/index.tsx
Normal file
24
src/pages/currencies/visaMasterSberSettingsCreate/index.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
// pages/VisaMasterSettingCreatePage.tsx
|
||||
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { VisaMasterSettingForm } from '@/features/visaMasterSberSettings/components/visaMasterSberSettingsForm'
|
||||
|
||||
// ─── VisaMasterSettingCreatePage ──────────────────────────────────────────────
|
||||
|
||||
export default function VisaMasterSettingCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('visaMasterSettings.actions.create', 'Visa/Master, Sber sazlamalar dörediň')}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<VisaMasterSettingForm mode="create" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
57
src/pages/currencies/visaMasterSberSettingsEdit/index.tsx
Normal file
57
src/pages/currencies/visaMasterSberSettingsEdit/index.tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
// pages/VisaMasterSettingEditPage.tsx
|
||||
|
||||
import {useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { VisaMasterSettingForm } from '@/features/visaMasterSberSettings/components/visaMasterSberSettingsForm'
|
||||
import { useGetVisaMasterSettingById } from '@/features/visaMasterSberSettings/hooks/useVisaMasterSettings'
|
||||
|
||||
// ─── VisaMasterSettingEditPage ────────────────────────────────────────────────
|
||||
|
||||
export default function VisaMasterSettingEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const numericId = Number(id)
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { data: setting, isLoading } = useGetVisaMasterSettingById(numericId)
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="h-6 w-72 bg-muted rounded animate-pulse" />
|
||||
<div className="h-56 bg-muted rounded-xl animate-pulse" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (!setting) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">
|
||||
{t('visaMasterSettings.notFound', 'Sazlama tapylmady')}
|
||||
</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
|
||||
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-6">
|
||||
{t('visaMasterSettings.detail.editTitle', 'Sazlamany üýtgetmek')}: {setting.id}
|
||||
</h1>
|
||||
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
<VisaMasterSettingForm
|
||||
mode="edit"
|
||||
initialData={setting}
|
||||
settingId={numericId}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
208
src/pages/onlinePaymentsHistory/index.tsx
Normal file
208
src/pages/onlinePaymentsHistory/index.tsx
Normal file
@@ -0,0 +1,208 @@
|
||||
// pages/OnlinePaymentHistoryPage.tsx
|
||||
|
||||
import { useState } from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Eye, Rss } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DataTable, type ColumnDef } from "@/components/dataTable";
|
||||
import { DataTableToolbar } from "@/components/dataTableToolbar";
|
||||
import type { VisibilityState } from "@tanstack/react-table";
|
||||
import {
|
||||
useGetOnlinePayments,
|
||||
useTriggerPaymentCallback,
|
||||
} from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import type { OnlinePayment } from "@/features/onlinePaymentHistory/api/onlinePaymentsHistoryApi";
|
||||
import { PaymentStatusBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
|
||||
// ─── Defaults ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const DEFAULT_VISIBILITY = {
|
||||
amount: true,
|
||||
apiClient: true,
|
||||
description: true,
|
||||
status: true,
|
||||
username: true,
|
||||
createdAt: true,
|
||||
};
|
||||
const DEFAULT_ORDER = [
|
||||
"amount",
|
||||
"apiClient",
|
||||
"description",
|
||||
"status",
|
||||
"username",
|
||||
"createdAt",
|
||||
"actions",
|
||||
];
|
||||
|
||||
// ─── OnlinePaymentHistoryPage ─────────────────────────────────────────────────
|
||||
|
||||
export default function OnlinePaymentHistoryPage() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [perPage] = useState(25);
|
||||
const [search, setSearch] = useState("");
|
||||
const [columnVisibility, setColumnVisibility] =
|
||||
useState<VisibilityState>(DEFAULT_VISIBILITY);
|
||||
const [columnOrder, setColumnOrder] = useState(DEFAULT_ORDER);
|
||||
|
||||
const { data, isLoading } = useGetOnlinePayments({ page, perPage, search });
|
||||
const callbackMutation = useTriggerPaymentCallback();
|
||||
|
||||
const handleSearchChange = (val: string) => {
|
||||
setSearch(val);
|
||||
setPage(1);
|
||||
};
|
||||
|
||||
// ─── Columns ──────────────────────────────────────────────────────────────
|
||||
|
||||
const columns: ColumnDef<OnlinePayment>[] = [
|
||||
{
|
||||
accessorKey: "amount",
|
||||
header: t("onlinePayments.columns.amount", "MÖÇBERI"),
|
||||
cell: ({ row }) => (
|
||||
<span className="tabular-nums text-foreground font-medium">
|
||||
{row.original.amount}
|
||||
</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
accessorKey: "apiClient",
|
||||
header: t("onlinePayments.columns.apiClient", "API CLIENT"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground text-xs font-mono truncate max-w-[180px] block">
|
||||
{row.original.apiClient}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "description",
|
||||
header: t("onlinePayments.columns.description", "DESC"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground text-sm">
|
||||
{row.original.description}
|
||||
</span>
|
||||
),
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
accessorKey: "status",
|
||||
header: t("onlinePayments.columns.status", "STATUS"),
|
||||
cell: ({ row }) => <PaymentStatusBadge status={row.original.status} />,
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
accessorKey: "username",
|
||||
header: t("onlinePayments.columns.username", "USERNAME"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-foreground text-xs font-mono">
|
||||
{row.original.username}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: "createdAt",
|
||||
header: t("onlinePayments.columns.createdAt", "DÖREDILEN WAGTY"),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-muted-foreground text-xs whitespace-nowrap">
|
||||
{formatDateTime(row.original.createdAt)}
|
||||
</span>
|
||||
),
|
||||
size: 140,
|
||||
},
|
||||
{
|
||||
id: "actions",
|
||||
header: "",
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
{/* Callback trigger */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
disabled={callbackMutation.isPending}
|
||||
onClick={() => callbackMutation.mutate(row.original.id)}
|
||||
title={t("onlinePayments.actions.callback", "Callback ugrat")}
|
||||
>
|
||||
<Rss size={15} />
|
||||
</Button>
|
||||
{/* View detail */}
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-foreground"
|
||||
onClick={() =>
|
||||
navigate(`/online-payments-history/${row.original.id}`)
|
||||
}
|
||||
title={t("common.view", "Görmek")}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
size: 90,
|
||||
},
|
||||
];
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => "accessorKey" in c && c.accessorKey)
|
||||
.map((c) => ({
|
||||
id: String(("accessorKey" in c ? c.accessorKey : c.id) ?? ""),
|
||||
label: typeof c.header === "string" ? c.header : "",
|
||||
}));
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-semibold text-foreground mb-5">
|
||||
{t("onlinePayments.title", "Onlaýn töleg taryhy")}
|
||||
</h1>
|
||||
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={handleSearchChange}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
hideAction
|
||||
/>
|
||||
|
||||
<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 ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function formatDateTime(iso: string): string {
|
||||
const d = new Date(iso);
|
||||
const hh = String(d.getHours()).padStart(2, "0");
|
||||
const mm = String(d.getMinutes()).padStart(2, "0");
|
||||
const dd = String(d.getDate()).padStart(2, "0");
|
||||
const mo = String(d.getMonth() + 1).padStart(2, "0");
|
||||
const yy = d.getFullYear();
|
||||
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||
}
|
||||
130
src/pages/onlinePaymentsHistory/onlinePaymenHistoryView.tsx
Normal file
130
src/pages/onlinePaymentsHistory/onlinePaymenHistoryView.tsx
Normal file
@@ -0,0 +1,130 @@
|
||||
// pages/OnlinePaymentDetailPage.tsx
|
||||
|
||||
import { useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Section, InfoRow } from "@/components/viewPageComponents";
|
||||
import { useGetOnlinePaymentById } from "@/features/onlinePaymentHistory/hooks/useOnlinePaymentsHistory";
|
||||
import { PaymentStatusBadge } from "../../features/onlinePaymentHistory/components/PaymentStatusBadge";
|
||||
|
||||
// ─── OnlinePaymentDetailPage ──────────────────────────────────────────────────
|
||||
|
||||
export default function OnlinePaymentDetailPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const numericId = Number(id);
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data: payment, isLoading } = useGetOnlinePaymentById(numericId);
|
||||
|
||||
// ─── Loading skeleton ──────────────────────────────────────────────────────
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="p-6 space-y-4">
|
||||
<div className="h-6 w-96 bg-muted rounded animate-pulse" />
|
||||
<div className="h-[560px] bg-muted rounded-xl animate-pulse" />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!payment) {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<p className="text-muted-foreground">
|
||||
{t("onlinePayments.notFound", "Töleg tapylmady")}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const title = `${t("onlinePayments.detail.title", "Onlaýn töleg taryhy giňişleýin")}: ${payment.orderId}`;
|
||||
|
||||
// ─── Render ───────────────────────────────────────────────────────────────
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-xl font-semibold text-foreground mb-6 break-all">
|
||||
{title}
|
||||
</h1>
|
||||
|
||||
{/* Detail Card */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={payment.id} />
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.amount", "amount")}
|
||||
value={payment.amount}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.orderNumber", "orderNumber")}
|
||||
value={payment.orderNumber}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.apiClient", "Api Client")}
|
||||
value={payment.apiClient}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.description", "description")}
|
||||
value={payment.description}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.orderId", "orderId")}
|
||||
value={payment.orderId}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.formUrl", "formUrl")}
|
||||
isLink
|
||||
value={payment.formUrl}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.successUrl", "successUrl")}
|
||||
isLink
|
||||
value={payment.successUrl}
|
||||
/>
|
||||
<InfoRow label={t("onlinePayments.fields.status", "Status")}>
|
||||
<PaymentStatusBadge status={payment.status} />
|
||||
</InfoRow>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.callbackStatus", "callbackStatus")}
|
||||
value={payment.callbackStatus ?? "—"}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.username", "username")}
|
||||
value={payment.username}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t(
|
||||
"onlinePayments.fields.onlinePaymantableId",
|
||||
"online_paymantable_id",
|
||||
)}
|
||||
value={payment.onlinePaymantableId}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t(
|
||||
"onlinePayments.fields.onlinePaymantableType",
|
||||
"online_paymantable_type",
|
||||
)}
|
||||
value={payment.onlinePaymantableType}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.createdAt", "Döredilen wagty")}
|
||||
value={formatDateTime(payment.createdAt)}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t("onlinePayments.fields.updatedAt", "Updated at")}
|
||||
value={formatDateTime(payment.updatedAt)}
|
||||
/>
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ─── Helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function formatDateTime(iso: string): string {
|
||||
const d = new Date(iso);
|
||||
const hh = String(d.getHours()).padStart(2, "0");
|
||||
const mm = String(d.getMinutes()).padStart(2, "0");
|
||||
const dd = String(d.getDate()).padStart(2, "0");
|
||||
const mo = String(d.getMonth() + 1).padStart(2, "0");
|
||||
const yy = d.getFullYear();
|
||||
return `${hh}:${mm}, ${dd}.${mo}.${yy}`;
|
||||
}
|
||||
15
src/pages/settings/users/createRole/index.tsx
Normal file
15
src/pages/settings/users/createRole/index.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RoleForm } from '@/features/roles/components/roleForm'
|
||||
|
||||
export default function RoleCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('roles.actions.create', 'Rol dörediň')}
|
||||
</h1>
|
||||
<RoleForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
46
src/pages/settings/users/editRole/index.tsx
Normal file
46
src/pages/settings/users/editRole/index.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { RoleForm } from '@/features/roles/components/roleForm'
|
||||
import { useRole } from '@/features/roles/hooks/useRoles'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function RoleEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const roleId = Number(id)
|
||||
|
||||
const { data: role, isLoading, isError } = useRole(roleId)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<Skeleton className="h-8 w-48 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center p-5">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-9 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !role) {
|
||||
return (
|
||||
<p className="text-destructive text-sm">
|
||||
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('roles.editTitle', 'Rol üýtget')}: {role.name?.tk}
|
||||
</h1>
|
||||
<RoleForm mode="edit" initialData={role} roleId={roleId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
194
src/pages/settings/users/permissions/index.tsx
Normal file
194
src/pages/settings/users/permissions/index.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { usePermissions, useDeletePermission } from '@/features/permissions/hooks/usePermissions'
|
||||
import type { Permission } from '@/features/permissions/api/permissionsApi'
|
||||
|
||||
// ─── Column meta for toolbar ──────────────────────────────────────────────────
|
||||
|
||||
const COLUMN_META = [
|
||||
{ id: 'id', label: 'ID' },
|
||||
{ id: 'code', label: 'Kod' },
|
||||
{ id: 'name', label: 'Ady' },
|
||||
{ id: 'guard_name', label: 'Guard name' },
|
||||
]
|
||||
|
||||
// ─── PermissionsPage ──────────────────────────────────────────────────────────
|
||||
|
||||
export default function PermissionsPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
// ── Data ───────────────────────────────────────────────────────────────────
|
||||
const { data, isLoading } = usePermissions({ search, page, per_page: perPage })
|
||||
const deletePermission = useDeletePermission()
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns: ColumnDef<Permission>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
size: 70,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
header: t('permissions.fields.code', 'Kod'),
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('permissions.fields.name', 'Ady'),
|
||||
cell: ({ row }) => <span>{row.original.name?.tk ?? '—'}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'guard_name',
|
||||
header: 'Guard name',
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
size: 120,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-primary"
|
||||
onClick={() => navigate(`/settings/users/permissions/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-blue-500"
|
||||
onClick={() => navigate(`/settings/users/permissions/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleConfirmDelete = () => {
|
||||
if (deleteId === null) return
|
||||
deletePermission.mutate(deleteId, {
|
||||
onSuccess: () => setDeleteId(null),
|
||||
onError: () => setDeleteId(null),
|
||||
})
|
||||
}
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('permissions.title', 'Rugsatlar')}
|
||||
</h1>
|
||||
<Button onClick={() => navigate('/settings/users/permissions/create')}>
|
||||
{t('permissions.actions.create', 'Rugsat dörediň')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('permissions.searchPlaceholder', 'Gözlemek...')}
|
||||
columns={COLUMN_META}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('permissions.deleteDialog.title', 'Rugsaty pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'permissions.deleteDialog.description',
|
||||
'Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deletePermission.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
15
src/pages/settings/users/permissionsCreate/index.tsx
Normal file
15
src/pages/settings/users/permissionsCreate/index.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PermissionForm } from '@/features/permissions/components/permissionsForm'
|
||||
|
||||
export default function PermissionCreatePage() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('permissions.actions.create', 'Rugsat dörediň')}
|
||||
</h1>
|
||||
<PermissionForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
46
src/pages/settings/users/permissionsEdit/index.tsx
Normal file
46
src/pages/settings/users/permissionsEdit/index.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { PermissionForm } from '@/features/permissions/components/permissionsForm'
|
||||
import { usePermission } from '@/features/permissions/hooks/usePermissions'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
|
||||
export default function PermissionEditPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const permissionId = Number(id)
|
||||
|
||||
const { data: permission, isLoading, isError } = usePermission(permissionId)
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<Skeleton className="h-8 w-56 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center p-5">
|
||||
<Skeleton className="h-4 w-24" />
|
||||
<Skeleton className="h-9 w-full" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !permission) {
|
||||
return (
|
||||
<p className="text-destructive text-sm">
|
||||
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground mb-6">
|
||||
{t('permissions.editTitle', 'Rugsaty üýtget')}: {permission.name?.tk}
|
||||
</h1>
|
||||
<PermissionForm mode="edit" initialData={permission} permissionId={permissionId} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
181
src/pages/settings/users/permissionsView/index.tsx
Normal file
181
src/pages/settings/users/permissionsView/index.tsx
Normal file
@@ -0,0 +1,181 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { usePermission, useDeletePermission } from '@/features/permissions/hooks/usePermissions'
|
||||
|
||||
// ─── LangTabs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
function LangTabs({
|
||||
active,
|
||||
onChange,
|
||||
}: {
|
||||
active: LangKey
|
||||
onChange: (l: LangKey) => void
|
||||
}) {
|
||||
return (
|
||||
<div className="flex gap-1 justify-end mb-2">
|
||||
{LANG_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => onChange(tab.key)}
|
||||
className={`px-3 py-0.5 text-xs font-medium rounded-md transition-colors ${
|
||||
active === tab.key
|
||||
? 'text-primary border-b-2 border-primary'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── PermissionViewPage ───────────────────────────────────────────────────────
|
||||
|
||||
export default function PermissionViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const permissionId = Number(id)
|
||||
|
||||
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||
const [showDelete, setShowDelete] = useState(false)
|
||||
|
||||
const { data: permission, isLoading, isError } = usePermission(permissionId)
|
||||
const deletePermission = useDeletePermission()
|
||||
|
||||
const handleConfirmDelete = () => {
|
||||
deletePermission.mutate(permissionId, {
|
||||
onSuccess: () => navigate('/settings/users/permissions'),
|
||||
onError: () => setShowDelete(false),
|
||||
})
|
||||
}
|
||||
|
||||
// ── Loading skeleton ───────────────────────────────────────────────────────
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<Skeleton className="h-8 w-72 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-3 px-4">
|
||||
<Skeleton className="h-4 w-20" />
|
||||
<Skeleton className="h-4 w-40" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !permission) {
|
||||
return (
|
||||
<p className="text-destructive text-sm">
|
||||
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading + actions */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('permissions.viewTitle', 'Rugsat giňişleýin')}: {permission.name?.tk}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-destructive hover:border-destructive"
|
||||
onClick={() => setShowDelete(true)}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-blue-500 hover:border-blue-500"
|
||||
onClick={() => navigate(`/settings/users/permissions/${permissionId}/edit`)}
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail section */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={permission.id} />
|
||||
<InfoRow label={t('permissions.fields.code', 'Kod')} value={permission.code} />
|
||||
|
||||
{/* Name row — with lang switcher */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-1">
|
||||
{t('permissions.fields.name', 'Ady')}
|
||||
</span>
|
||||
<div>
|
||||
<LangTabs active={activeLang} onChange={setActiveLang} />
|
||||
<span className="text-sm text-foreground">
|
||||
{permission.name?.[activeLang] || '—'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InfoRow label={t('permissions.fields.guardName', 'Guard name')} value={permission.guard_name} />
|
||||
</Section>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={showDelete} onOpenChange={setShowDelete}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('permissions.deleteDialog.title', 'Rugsaty pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'permissions.deleteDialog.description',
|
||||
'Bu rugsaty pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deletePermission.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
194
src/pages/settings/users/roles/index.tsx
Normal file
194
src/pages/settings/users/roles/index.tsx
Normal file
@@ -0,0 +1,194 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Eye, Pencil, Trash2 } from 'lucide-react'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { useRoles, useDeleteRole } from '@/features/roles/hooks/useRoles'
|
||||
import type { Role } from '@/features/roles/api/rolesApi'
|
||||
|
||||
// ─── Column meta for toolbar ──────────────────────────────────────────────────
|
||||
|
||||
const COLUMN_META = [
|
||||
{ id: 'id', label: 'ID' },
|
||||
{ id: 'code', label: 'Kod' },
|
||||
{ id: 'name', label: 'Ady' },
|
||||
{ id: 'guard_name', label: 'Guard name' },
|
||||
]
|
||||
|
||||
// ─── RolesPage ────────────────────────────────────────────────────────────────
|
||||
|
||||
export default function RolesPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
// ── State ──────────────────────────────────────────────────────────────────
|
||||
const [search, setSearch] = useState('')
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
// ── Data ───────────────────────────────────────────────────────────────────
|
||||
const { data, isLoading } = useRoles({ search, page, per_page: perPage })
|
||||
const deleteRole = useDeleteRole()
|
||||
|
||||
// ── Columns ────────────────────────────────────────────────────────────────
|
||||
const columns: ColumnDef<Role>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
size: 70,
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-semibold">{row.original.id}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
header: t('roles.fields.code', 'Kod'),
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
header: t('roles.fields.name', 'Ady'),
|
||||
cell: ({ row }) => <span>{row.original.name?.tk ?? '—'}</span>,
|
||||
},
|
||||
{
|
||||
accessorKey: 'guard_name',
|
||||
header: 'Guard name',
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
size: 120,
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center justify-end gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-primary"
|
||||
onClick={() => navigate(`/settings/users/roles/${row.original.id}`)}
|
||||
>
|
||||
<Eye size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-blue-500"
|
||||
onClick={() => navigate(`/settings/users/roles/${row.original.id}/edit`)}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8 text-muted-foreground hover:text-destructive"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
// ── Handlers ───────────────────────────────────────────────────────────────
|
||||
const handleConfirmDelete = () => {
|
||||
if (deleteId === null) return
|
||||
deleteRole.mutate(deleteId, {
|
||||
onSuccess: () => setDeleteId(null),
|
||||
onError: () => setDeleteId(null),
|
||||
})
|
||||
}
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('roles.title', 'Rollar')}
|
||||
</h1>
|
||||
<Button onClick={() => navigate('/settings/users/roles/create')}>
|
||||
{t('roles.actions.create', 'Rol dörediň')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('roles.searchPlaceholder', 'Gözlemek...')}
|
||||
columns={COLUMN_META}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
perPageOptions={[10, 25, 50, 100]}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
/>
|
||||
|
||||
{/* Table */}
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={data?.data ?? []}
|
||||
isLoading={isLoading}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
getRowId={(row) => String(row.id)}
|
||||
currentPage={data?.meta?.current_page ?? 1}
|
||||
totalPages={data?.meta?.last_page ?? 1}
|
||||
totalCount={data?.meta?.total ?? 0}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete confirmation dialog */}
|
||||
<AlertDialog
|
||||
open={deleteId !== null}
|
||||
onOpenChange={(open) => { if (!open) setDeleteId(null) }}
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('roles.deleteDialog.title', 'Roly pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'roles.deleteDialog.description',
|
||||
'Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteRole.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
181
src/pages/settings/users/rolesView/index.tsx
Normal file
181
src/pages/settings/users/rolesView/index.tsx
Normal file
@@ -0,0 +1,181 @@
|
||||
import { useState } from 'react'
|
||||
import { useParams, useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Skeleton } from '@/components/ui/skeleton'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useRole, useDeleteRole } from '@/features/roles/hooks/useRoles'
|
||||
|
||||
// ─── LangTabs ─────────────────────────────────────────────────────────────────
|
||||
|
||||
type LangKey = 'tk' | 'ru' | 'en'
|
||||
|
||||
const LANG_TABS: { key: LangKey; label: string }[] = [
|
||||
{ key: 'tk', label: 'Türkmen' },
|
||||
{ key: 'ru', label: 'Русский' },
|
||||
{ key: 'en', label: 'English' },
|
||||
]
|
||||
|
||||
function LangTabs({
|
||||
active,
|
||||
onChange,
|
||||
}: {
|
||||
active: LangKey
|
||||
onChange: (l: LangKey) => void
|
||||
}) {
|
||||
return (
|
||||
<div className="flex gap-1 justify-end mb-2">
|
||||
{LANG_TABS.map((tab) => (
|
||||
<button
|
||||
key={tab.key}
|
||||
type="button"
|
||||
onClick={() => onChange(tab.key)}
|
||||
className={`px-3 py-0.5 text-xs font-medium rounded-md transition-colors ${
|
||||
active === tab.key
|
||||
? 'text-primary border-b-2 border-primary'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{tab.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── RoleViewPage ─────────────────────────────────────────────────────────────
|
||||
|
||||
export default function RoleViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const roleId = Number(id)
|
||||
|
||||
const [activeLang, setActiveLang] = useState<LangKey>('tk')
|
||||
const [showDelete, setShowDelete] = useState(false)
|
||||
|
||||
const { data: role, isLoading, isError } = useRole(roleId)
|
||||
const deleteRole = useDeleteRole()
|
||||
|
||||
const handleConfirmDelete = () => {
|
||||
deleteRole.mutate(roleId, {
|
||||
onSuccess: () => navigate('/settings/users/roles'),
|
||||
onError: () => setShowDelete(false),
|
||||
})
|
||||
}
|
||||
|
||||
// ── Loading skeleton ───────────────────────────────────────────────────────
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div>
|
||||
<Skeleton className="h-8 w-72 mb-6" />
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden divide-y divide-border">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div key={i} className="grid grid-cols-[220px_1fr] items-center py-3 px-4">
|
||||
<Skeleton className="h-4 w-20" />
|
||||
<Skeleton className="h-4 w-40" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (isError || !role) {
|
||||
return (
|
||||
<p className="text-destructive text-sm">
|
||||
{t('common.fetchError', 'Maglumat ýüklenmedi.')}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
// ── Render ─────────────────────────────────────────────────────────────────
|
||||
return (
|
||||
<div>
|
||||
{/* Page heading + actions */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('roles.viewTitle', 'Rol giňişleýin')}: {role.name?.tk}
|
||||
</h1>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-destructive hover:border-destructive"
|
||||
onClick={() => setShowDelete(true)}
|
||||
>
|
||||
<Trash2 size={16} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-muted-foreground hover:text-blue-500 hover:border-blue-500"
|
||||
onClick={() => navigate(`/settings/users/roles/${roleId}/edit`)}
|
||||
>
|
||||
<Pencil size={16} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Detail section */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={role.id} />
|
||||
<InfoRow label={t('roles.fields.code', 'Kod')} value={role.code} />
|
||||
|
||||
{/* Name row — with lang switcher */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-start py-2.5 px-4 border-b border-border">
|
||||
<span className="text-sm text-muted-foreground pt-1">
|
||||
{t('roles.fields.name', 'Ady')}
|
||||
</span>
|
||||
<div>
|
||||
<LangTabs active={activeLang} onChange={setActiveLang} />
|
||||
<span className="text-sm text-foreground">
|
||||
{role.name?.[activeLang] || '—'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InfoRow label={t('roles.fields.guardName', 'Guard name')} value={role.guard_name} />
|
||||
</Section>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={showDelete} onOpenChange={setShowDelete}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('roles.deleteDialog.title', 'Roly pozmak')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'roles.deleteDialog.description',
|
||||
'Bu roly pozmak isleýärsiňizmi? Bu amal yzyna gaýtarylmaz.',
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirmDelete}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{deleteRole.isPending
|
||||
? t('common.deleting', 'Pozulýar...')
|
||||
: t('common.delete', 'Poz')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,37 +1,14 @@
|
||||
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ň')}
|
||||
|
||||
Reference in New Issue
Block a user