added setting card pages
This commit is contained in:
1 parent
a1d059a838
commit
d8821a0199
17 files changed
+2042
-28
No files matched your search
@@ -0,0 +1,249 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import type { FilterField, ActiveFilter } from '@/components/dataTableToolbar'
|
||||
import { useCardTypes, useDeleteCardType } from '@/features/cardTypes/hooks/useCardTypes'
|
||||
import type { CardType } from '@/features/cardTypes/api/cardTypesApi'
|
||||
|
||||
export function CardTypesListPage() {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en'
|
||||
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: 'isActive', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'name', 'value', 'description', 'isActive', 'actions',
|
||||
])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
const deleteMutation = useDeleteCardType()
|
||||
const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? ''
|
||||
|
||||
const { data, isLoading } = useCardTypes({ page, perPage, search, isActive: isActiveFilter })
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('cardTypes.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const handleFilterChange = (fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) =>
|
||||
prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))
|
||||
)
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const handleFilterReset = () => {
|
||||
setActiveFilters([{ fieldId: 'isActive', value: '' }])
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const columns: ColumnDef<CardType>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>
|
||||
),
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('cardTypes.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'value',
|
||||
header: t('cardTypes.fields.value', 'BAHA').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.value}</span>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('cardTypes.fields.description', 'BELLIKLER').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.description ?? '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
id: 'isActive',
|
||||
header: t('cardTypes.fields.isActive', 'IŞJEŇ').toUpperCase(),
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-types/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-types/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
size: 120,
|
||||
},
|
||||
]
|
||||
|
||||
const columnMeta = columns
|
||||
.filter(
|
||||
(c) =>
|
||||
c.id !== 'actions' &&
|
||||
(c as { accessorKey?: string }).accessorKey !== undefined
|
||||
)
|
||||
.map((c) => ({
|
||||
id: (c.id ?? (c as { accessorKey?: string }).accessorKey) as string,
|
||||
label:
|
||||
typeof c.header === 'string'
|
||||
? c.header
|
||||
: (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ''),
|
||||
}))
|
||||
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span>{t('nav.resources', 'Resurslar')}</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('cardTypes.title', 'Kart görnüşleri')}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('cardTypes.title', 'Kart görnüşleri')}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('cardTypes.actions.create', 'Kart görnüşi döretdiň')}
|
||||
onAction={() => navigate('/settings/card/card-types/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={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('cardTypes.deleteConfirm', 'Bu kart görnüşini öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteId !== null) {
|
||||
deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) })
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CardTypesListPage
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardTypeForm } from '@/features/cardTypes/components/cardTypesForm'
|
||||
|
||||
export default function CardTypeCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/card/card-types')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/card/card-types')}
|
||||
>
|
||||
{t('cardTypes.title', 'Kart görnüşleri')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('cardTypes.create.breadcrumb', 'Kart görnüşi döretmek')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('cardTypes.create.title', 'Kart görnüşi döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardTypeForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardTypeForm } from '@/features/cardTypes/components/cardTypesForm'
|
||||
import { useCardTypeById } from '@/features/cardTypes/hooks/useCardTypes'
|
||||
|
||||
export default function CardTypeEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useCardTypeById(numericId)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/card/card-types')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/card/card-types')}
|
||||
>
|
||||
{t('cardTypes.title', 'Kart görnüşleri')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('cardTypes.edit.breadcrumb', 'Üýtgetmek')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('cardTypes.edit.title', 'Kart görnüşini üýtgetmek')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-8 w-full bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center py-20 text-destructive text-sm">
|
||||
{t('common.error', 'Ýalňyşlyk ýüze çykdy')}
|
||||
</div>
|
||||
) : (
|
||||
<CardTypeForm mode="edit" initialData={data} cardTypeId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2, CheckCircle2, XCircle } 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 { useCardTypeById, useDeleteCardType } from '@/features/cardTypes/hooks/useCardTypes'
|
||||
|
||||
export function CardTypeViewPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t, i18n } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en'
|
||||
|
||||
const { data, isLoading } = useCardTypeById(numericId)
|
||||
const deleteMutation = useDeleteCardType()
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Breadcrumb + actions */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<div>
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/resources/card-types')}
|
||||
>
|
||||
{t('nav.resources', 'Resurslar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/resources/card-types')}
|
||||
>
|
||||
{t('cardTypes.title', 'Kart görnüşleri')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{isLoading ? '...' : data?.name[lang] ?? ''}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('cardTypes.view.title', 'Kart görnüşi giňişleýin')}: ${data?.name[lang] ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/resources/card-types/${numericId}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-4 w-40 bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : data ? (
|
||||
<Section>
|
||||
<InfoRow label="ID" value={data.id} />
|
||||
|
||||
{/* Multilang name with tabs */}
|
||||
<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('cardTypes.fields.name', 'Ady')}
|
||||
</span>
|
||||
<div>
|
||||
<div className="flex gap-3 mb-2 justify-end">
|
||||
{(['tk', 'ru', 'en'] as const).map((l) => (
|
||||
<span
|
||||
key={l}
|
||||
className={`text-sm cursor-default ${
|
||||
l === lang
|
||||
? 'text-primary font-semibold underline underline-offset-4'
|
||||
: 'text-muted-foreground'
|
||||
}`}
|
||||
>
|
||||
{l === 'tk' ? 'Türkmen' : l === 'ru' ? 'Русский' : 'English'}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<span className="text-sm text-foreground">{data.name[lang]}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InfoRow label={t('cardTypes.fields.value', 'Baha')} value={data.value} />
|
||||
<InfoRow
|
||||
label={t('cardTypes.fields.description', 'Bellikler')}
|
||||
value={data.description ?? undefined}
|
||||
/>
|
||||
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('cardTypes.fields.isActive', 'Işjeň')}
|
||||
</span>
|
||||
{data.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
)}
|
||||
</div>
|
||||
</Section>
|
||||
) : (
|
||||
<p className="text-muted-foreground text-sm">{t('common.noData', 'Maglumat ýok')}</p>
|
||||
)}
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('cardTypes.deleteConfirm', 'Bu kart görnüşini öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() =>
|
||||
deleteMutation.mutate(numericId, {
|
||||
onSuccess: () => navigate('/resources/card-types'),
|
||||
})
|
||||
}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CardTypeViewPage
|
||||
@@ -0,0 +1,253 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { ColumnDef, VisibilityState } from '@tanstack/react-table'
|
||||
import { Eye, Pencil, Trash2, CheckCircle2, XCircle } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { DataTable } from '@/components/dataTable'
|
||||
import { DataTableToolbar } from '@/components/dataTableToolbar'
|
||||
import type { FilterField, ActiveFilter } from '@/components/dataTableToolbar'
|
||||
import { useCardReasons, useDeleteCardReason } from '@/features/cardReasons/hooks/useCardReasons'
|
||||
import type { CardReason } from '@/features/cardReasons/api/cardReasonsApi'
|
||||
|
||||
// ─── CardReasonsListPage ───────────────────────────────────────────────────────
|
||||
|
||||
export function CardReasonsListPage() {
|
||||
const { t, i18n } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en'
|
||||
|
||||
// ── Table state ─────────────────────────────────────────────────────────────
|
||||
const [page, setPage] = useState(1)
|
||||
const [perPage, setPerPage] = useState(25)
|
||||
const [search, setSearch] = useState('')
|
||||
const [activeFilters, setActiveFilters] = useState<ActiveFilter[]>([
|
||||
{ fieldId: 'isActive', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'name', 'value', 'description', 'isActive', 'actions',
|
||||
])
|
||||
|
||||
// ── Delete dialog ────────────────────────────────────────────────────────────
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
const deleteMutation = useDeleteCardReason()
|
||||
|
||||
const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? ''
|
||||
|
||||
const { data, isLoading } = useCardReasons({
|
||||
page,
|
||||
perPage,
|
||||
search,
|
||||
isActive: isActiveFilter,
|
||||
})
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('CardReasons.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const handleFilterChange = (fieldId: string, value: string) => {
|
||||
setActiveFilters((prev) =>
|
||||
prev.map((f) => (f.fieldId === fieldId ? { ...f, value } : f))
|
||||
)
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const handleFilterReset = () => {
|
||||
setActiveFilters([{ fieldId: 'isActive', value: '' }])
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
// ── Columns ──────────────────────────────────────────────────────────────────
|
||||
const columns: ColumnDef<CardReason>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">
|
||||
{row.original.id}
|
||||
</span>
|
||||
),
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('CardReasons.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'value',
|
||||
header: t('CardReasons.fields.value', 'BAHA').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.value}</span>
|
||||
),
|
||||
size: 120,
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('CardReasons.fields.description', 'BELLIKLER').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.description ?? '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
id: 'isActive',
|
||||
header: t('CardReasons.fields.isActive', 'IŞJEŇ').toUpperCase(),
|
||||
cell: ({ row }) =>
|
||||
row.original.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
id: 'actions',
|
||||
header: '',
|
||||
cell: ({ row }) => (
|
||||
<div className="flex items-center gap-2 justify-end">
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-reasons/${row.original.id}`)}
|
||||
title={t('common.view', 'Görmek')}
|
||||
>
|
||||
<Eye size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-muted/60 text-muted-foreground hover:text-foreground transition-colors"
|
||||
onClick={() => navigate(`/settings/card/card-reasons/${row.original.id}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={14} />
|
||||
</button>
|
||||
<button
|
||||
className="p-1.5 rounded hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
|
||||
onClick={() => setDeleteId(row.original.id)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
>
|
||||
<Trash2 size={14} />
|
||||
</button>
|
||||
</div>
|
||||
),
|
||||
enableSorting: false,
|
||||
enableHiding: false,
|
||||
size: 120,
|
||||
},
|
||||
]
|
||||
|
||||
const columnMeta = columns
|
||||
.filter((c) => c.id !== 'actions' && (c as { accessorKey?: string }).accessorKey !== undefined)
|
||||
.map((c) => ({
|
||||
id: (c.id ?? (c as { accessorKey?: string }).accessorKey) as string,
|
||||
label:
|
||||
typeof c.header === 'string'
|
||||
? c.header
|
||||
: (c.id ?? (c as { accessorKey?: string }).accessorKey ?? ''),
|
||||
}))
|
||||
|
||||
const totalPages = data ? Math.ceil(data.total / perPage) : 1
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('CardReasons.title', 'Kartyň çykarylmagynyň sebäpleri')}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Toolbar */}
|
||||
<DataTableToolbar
|
||||
searchValue={search}
|
||||
onSearchChange={(v) => { setSearch(v); setPage(1) }}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
columns={columnMeta}
|
||||
columnVisibility={columnVisibility}
|
||||
onColumnVisibilityChange={setColumnVisibility}
|
||||
columnOrder={columnOrder}
|
||||
onColumnOrderChange={setColumnOrder}
|
||||
filterFields={filterFields}
|
||||
activeFilters={activeFilters}
|
||||
onFilterChange={handleFilterChange}
|
||||
onFilterReset={handleFilterReset}
|
||||
perPage={perPage}
|
||||
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
|
||||
actionLabel={t('CardReasons.actions.create', 'Kartyň çykarylmagynyň sebäbini döretdiň')}
|
||||
onAction={() => navigate('/settings/card/card-reasons/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={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('common.confirmDelete', 'Öçürmegi tassyklaň')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('CardReasons.deleteConfirm', 'Bu kartyň çykarylmagynyň sebäbini öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() => {
|
||||
if (deleteId !== null) {
|
||||
deleteMutation.mutate(deleteId, { onSuccess: () => setDeleteId(null) })
|
||||
}
|
||||
}}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CardReasonsListPage
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useNavigate, } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { CardReasonForm } from '@/features/cardReasons/components/reasonForm'
|
||||
|
||||
export function CardReasonCreatePage() {
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/resources/card-states')}
|
||||
>
|
||||
{t('nav.resources', 'Resurslar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/resources/card-states')}
|
||||
>
|
||||
{t('CardReasons.title', 'Kartyň çykarylmagynyň sebäpleri')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('CardReasons.create.breadcrumb', 'Kartyň çykarylmagynyň sebäbi dörediň')}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('CardReasons.create.title', 'Kartyň çykarylmagynyň sebäbi dörediň')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<CardReasonForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CardReasonCreatePage
|
||||
@@ -0,0 +1,68 @@
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CardReasonForm } from "@/features/cardReasons/components/reasonForm";
|
||||
import { useCardReasonById } from "@/features/cardReasons/hooks/useCardReasons";
|
||||
|
||||
// ─── CardReasonEditPage ────────────────────────────────────────────────────────
|
||||
|
||||
export function CardReasonEditPage() {
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const navigate = useNavigate();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const numericId = Number(id);
|
||||
const { data, isLoading } = useCardReasonById(numericId);
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<div className="mb-6">
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate("/resources/card-states")}
|
||||
>
|
||||
{t("nav.resources", "Resurslar")}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate("/resources/card-states")}
|
||||
>
|
||||
{t("CardReasons.title", "Kartyň çykarylmagynyň sebäpleri")}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t("CardReasons.edit.breadcrumb", "Üýtgetmek")}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? "..."
|
||||
: `${t("CardReasons.edit.title", "Kartyň çykarylmagynyň sebäbini üýtgetmek")}: ${data?.name.tk ?? ""}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-3 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-8 w-full bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<CardReasonForm
|
||||
mode="edit"
|
||||
initialData={data}
|
||||
CardReasonId={numericId}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default CardReasonEditPage
|
||||
@@ -0,0 +1,180 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Pencil, Trash2 } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { CheckCircle2, XCircle } from 'lucide-react'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useCardReasonById, useDeleteCardReason } from '@/features/cardReasons/hooks/useCardReasons'
|
||||
|
||||
// ─── CardReasonViewPage ────────────────────────────────────────────────────────
|
||||
|
||||
export function CardReasonViewPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t, i18n } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const lang = (i18n.language?.slice(0, 2) ?? 'tk') as 'tk' | 'ru' | 'en'
|
||||
|
||||
const { data, isLoading } = useCardReasonById(numericId)
|
||||
const deleteMutation = useDeleteCardReason()
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
{/* Breadcrumb + actions */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<div>
|
||||
<nav className="flex items-center gap-2 text-sm text-muted-foreground mb-1">
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/resources/card-states')}
|
||||
>
|
||||
{t('nav.resources', 'Resurslar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/resources/card-states')}
|
||||
>
|
||||
{t('CardReasons.title', 'Kartyň çykarylmagynyň sebäpleri')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('CardReasons.view.breadcrumb', 'Kartyň çykarylmagynyň sebäbi giňişleýin: Rekwizit')}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('CardReasons.view.title', 'Kartyň çykarylmagynyň sebäbi giňişleýin')}: ${data?.name[lang] ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/resources/card-states/${numericId}/edit`)}
|
||||
title={t('common.edit', 'Üýtgetmek')}
|
||||
>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="text-destructive border-destructive/30 hover:bg-destructive/10"
|
||||
onClick={() => setDeleteOpen(true)}
|
||||
title={t('common.delete', 'Öçürmek')}
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 4 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<div className="h-4 w-24 bg-muted rounded animate-pulse" />
|
||||
<div className="h-4 w-40 bg-muted rounded animate-pulse" />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : data ? (
|
||||
<Section>
|
||||
<InfoRow label="ID" value={data.id} />
|
||||
|
||||
{/* Multilang name tabs */}
|
||||
<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('CardReasons.fields.name', 'Ady')}
|
||||
</span>
|
||||
<div>
|
||||
{/* Lang switcher is displayed in top-right corner of this cell */}
|
||||
<div className="flex gap-3 mb-2 justify-end">
|
||||
{(['tk', 'ru', 'en'] as const).map((l) => (
|
||||
<span
|
||||
key={l}
|
||||
className={`text-sm cursor-default ${
|
||||
l === lang ? 'text-primary font-semibold underline underline-offset-4' : 'text-muted-foreground'
|
||||
}`}
|
||||
>
|
||||
{l === 'tk' ? 'Türkmen' : l === 'ru' ? 'Русский' : 'English'}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
<span className="text-sm text-foreground">{data.name[lang]}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<InfoRow
|
||||
label={t('CardReasons.fields.value', 'Baha')}
|
||||
value={data.value}
|
||||
/>
|
||||
<InfoRow
|
||||
label={t('CardReasons.fields.description', 'Bellikler')}
|
||||
value={data.description ?? undefined}
|
||||
/>
|
||||
|
||||
{/* isActive custom row */}
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('CardReasons.fields.isActive', 'Işjeň')}
|
||||
</span>
|
||||
{data.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
)}
|
||||
</div>
|
||||
</Section>
|
||||
) : (
|
||||
<p className="text-muted-foreground text-sm">{t('common.noData', 'Maglumat ýok')}</p>
|
||||
)}
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('CardReasons.deleteConfirm', 'Bu kartyň çykarylmagynyň sebäbini öçürmek isleýärsiňizmi?')}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
onClick={() =>
|
||||
deleteMutation.mutate(numericId, {
|
||||
onSuccess: () => navigate('/resources/card-states'),
|
||||
})
|
||||
}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default CardReasonViewPage
|
||||
Reference in new issue
Block a user