added locations page
This commit is contained in:
269
src/pages/settings/location/branches/index.tsx
Normal file
269
src/pages/settings/location/branches/index.tsx
Normal file
@@ -0,0 +1,269 @@
|
||||
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 { useBranches, useDeleteBranch } from '@/features/branches/hooks/useBranches'
|
||||
import type { Branch } from '@/features/branches/api/branchesApi'
|
||||
import { getDistrictOptions } from '@/features/branches/api/branchesApi'
|
||||
|
||||
export function BranchesListPage() {
|
||||
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: '' },
|
||||
{ fieldId: 'districtId', value: '' },
|
||||
])
|
||||
const [columnVisibility, setColumnVisibility] = useState<VisibilityState>({})
|
||||
const [columnOrder, setColumnOrder] = useState<string[]>([
|
||||
'id', 'code', 'name', 'districtName', 'phone', 'isActive', 'actions',
|
||||
])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
const deleteMutation = useDeleteBranch()
|
||||
const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? ''
|
||||
const districtIdFilter = activeFilters.find((f) => f.fieldId === 'districtId')?.value ?? ''
|
||||
|
||||
const { data, isLoading } = useBranches({ page, perPage, search, isActive: isActiveFilter, districtId: districtIdFilter })
|
||||
|
||||
const districtOptions = getDistrictOptions().map((d) => ({
|
||||
value: String(d.id),
|
||||
label: d.name.tk,
|
||||
}))
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('branches.fields.isActive', 'Işjeň'),
|
||||
options: [
|
||||
{ value: 'true', label: t('common.active', 'Işjeň') },
|
||||
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'districtId',
|
||||
label: t('branches.fields.district', 'Etrap'),
|
||||
options: districtOptions,
|
||||
},
|
||||
]
|
||||
|
||||
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: '' },
|
||||
{ fieldId: 'districtId', value: '' },
|
||||
])
|
||||
setPage(1)
|
||||
}
|
||||
|
||||
const columns: ColumnDef<Branch>[] = [
|
||||
{
|
||||
accessorKey: 'id',
|
||||
header: 'ID',
|
||||
cell: ({ row }) => (
|
||||
<span className="text-primary font-mono text-sm font-medium">{row.original.id}</span>
|
||||
),
|
||||
size: 70,
|
||||
},
|
||||
{
|
||||
accessorKey: 'code',
|
||||
id: 'code',
|
||||
header: t('branches.fields.code', 'KOD').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm font-mono text-foreground">{row.original.code}</span>
|
||||
),
|
||||
size: 100,
|
||||
},
|
||||
{
|
||||
accessorKey: 'name',
|
||||
id: 'name',
|
||||
header: t('branches.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'districtName',
|
||||
id: 'districtName',
|
||||
header: t('branches.fields.district', 'ETRAP').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">{row.original.districtName[lang]}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone',
|
||||
header: t('branches.fields.phone', 'TELEFON').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.phone}</span>
|
||||
),
|
||||
size: 150,
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
id: 'isActive',
|
||||
header: t('branches.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/location/branches/${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/location/branches/${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">
|
||||
<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.settings', 'Sazlamalar')}</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('branches.title', 'Şahamçalar')}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('branches.title', 'Şahamçalar')}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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('branches.actions.create', 'Şahamça döret')}
|
||||
onAction={() => navigate('/settings/location/branches/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={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('branches.deleteConfirm', 'Bu şahamçany öçü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 BranchesListPage
|
||||
40
src/pages/settings/location/branchesCreate/index.tsx
Normal file
40
src/pages/settings/location/branchesCreate/index.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { BranchForm } from '@/features/branches/components/branchesForm'
|
||||
|
||||
export default function BranchCreatePage() {
|
||||
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/location/branches')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/location/branches')}
|
||||
>
|
||||
{t('branches.title', 'Şahamçalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('branches.create.breadcrumb', 'Şahamça döretmek')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('branches.create.title', 'Şahamça döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<BranchForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
60
src/pages/settings/location/branchesEdit/index.tsx
Normal file
60
src/pages/settings/location/branchesEdit/index.tsx
Normal file
@@ -0,0 +1,60 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { BranchForm } from '@/features/branches/components/branchesForm'
|
||||
import { useBranchById } from '@/features/branches/hooks/useBranches'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
|
||||
export default function BranchEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useBranchById(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/location/branches')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/location/branches')}
|
||||
>
|
||||
{t('branches.title', 'Şahamçalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('branches.edit.breadcrumb', 'Üýtgetmek')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('branches.edit.title', 'Şahamçany üýtgetmek')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 className="animate-spin text-muted-foreground" size={32} />
|
||||
</div>
|
||||
) : isError || !data ? (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<p className="text-sm text-destructive">
|
||||
{t('common.error', 'Maglumat ýüklenilmedi. Sahypany täzeleläň.')}
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<BranchForm mode="edit" initialData={data} branchId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
205
src/pages/settings/location/branchesView/index.tsx
Normal file
205
src/pages/settings/location/branchesView/index.tsx
Normal file
@@ -0,0 +1,205 @@
|
||||
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 { useBranchById, useDeleteBranch } from '@/features/branches/hooks/useBranches'
|
||||
|
||||
export function BranchViewPage() {
|
||||
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 } = useBranchById(numericId)
|
||||
const deleteMutation = useDeleteBranch()
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<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('/settings/location/branches')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/location/branches')}
|
||||
>
|
||||
{t('branches.title', 'Şahamçalar')}
|
||||
</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('branches.view.title', 'Şahamça giňişleýin')}: ${data?.name[lang] ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/settings/location/branches/${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: 6 }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4 border-b border-border last:border-0"
|
||||
>
|
||||
<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 title={t('branches.sections.basic', 'Esasy maglumatlar')}>
|
||||
<InfoRow label="ID" value={data.id} />
|
||||
<InfoRow label={t('branches.fields.code', 'Kod')} value={data.code} />
|
||||
|
||||
<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('branches.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('branches.fields.district', 'Etrap')} value={data.districtName[lang]} />
|
||||
|
||||
<div className="grid grid-cols-[220px_1fr] items-center py-2.5 px-4">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{t('branches.fields.isActive', 'Işjeň')}
|
||||
</span>
|
||||
{data.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
<XCircle size={18} className="text-destructive" />
|
||||
)}
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section title={t('branches.sections.address', 'Salgy we habarlaşmak')}>
|
||||
<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('branches.fields.address', 'Salgy')}
|
||||
</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.address[lang]}</span>
|
||||
</div>
|
||||
</div>
|
||||
<InfoRow label={t('branches.fields.phone', 'Telefon')} value={data.phone} />
|
||||
<InfoRow label={t('branches.fields.email', 'E-poçta')} value={data.email} />
|
||||
</Section>
|
||||
|
||||
<Section title={t('branches.sections.hours', 'Iş wagty')}>
|
||||
<InfoRow label={t('branches.fields.workingHours', 'Iş wagty')} value={data.workingHours} />
|
||||
<InfoRow
|
||||
label={t('branches.fields.description', 'Bellikler')}
|
||||
value={data.description ?? undefined}
|
||||
/>
|
||||
</Section>
|
||||
</>
|
||||
) : (
|
||||
<p className="text-muted-foreground text-sm">{t('common.noData', 'Maglumat ýok')}</p>
|
||||
)}
|
||||
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('branches.deleteConfirm', 'Bu şahamçany öçü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('/settings/location/branches'),
|
||||
})
|
||||
}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default BranchViewPage
|
||||
237
src/pages/settings/location/districts/index.tsx
Normal file
237
src/pages/settings/location/districts/index.tsx
Normal file
@@ -0,0 +1,237 @@
|
||||
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 { useDistricts, useDeleteDistrict } from '@/features/districts/hooks/useDistricts'
|
||||
import type { District } from '@/features/districts/api/districtsApi'
|
||||
|
||||
export function DistrictsListPage() {
|
||||
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', 'description', 'isActive', 'actions',
|
||||
])
|
||||
const [deleteId, setDeleteId] = useState<number | null>(null)
|
||||
|
||||
const deleteMutation = useDeleteDistrict()
|
||||
const isActiveFilter = activeFilters.find((f) => f.fieldId === 'isActive')?.value ?? ''
|
||||
|
||||
const { data, isLoading } = useDistricts({ page, perPage, search, isActive: isActiveFilter })
|
||||
|
||||
const filterFields: FilterField[] = [
|
||||
{
|
||||
id: 'isActive',
|
||||
label: t('districts.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<District>[] = [
|
||||
{
|
||||
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('districts.fields.name', 'ADY').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-foreground">{row.original.name[lang]}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'description',
|
||||
header: t('districts.fields.description', 'BELLIKLER').toUpperCase(),
|
||||
cell: ({ row }) => (
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{row.original.description ?? '—'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
accessorKey: 'isActive',
|
||||
id: 'isActive',
|
||||
header: t('districts.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/location/districts/${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/location/districts/${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">
|
||||
<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.settings', 'Sazlamalar')}</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('districts.title', 'Etraplar')}
|
||||
</span>
|
||||
</nav>
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('districts.title', 'Etraplar')}
|
||||
</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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('districts.actions.create', 'Etrap döret')}
|
||||
onAction={() => navigate('/settings/location/districts/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={totalPages}
|
||||
totalCount={data?.total}
|
||||
onPageChange={setPage}
|
||||
/>
|
||||
|
||||
<AlertDialog open={deleteId !== null} onOpenChange={() => setDeleteId(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('districts.deleteConfirm', 'Bu etrapy öçü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 DistrictsListPage
|
||||
40
src/pages/settings/location/districtsCreate/index.tsx
Normal file
40
src/pages/settings/location/districtsCreate/index.tsx
Normal file
@@ -0,0 +1,40 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { DistrictForm } from '@/features/districts/components/districtsForm'
|
||||
|
||||
export default function DistrictCreatePage() {
|
||||
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/location/districts')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/location/districts')}
|
||||
>
|
||||
{t('districts.title', 'Etraplar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('districts.create.breadcrumb', 'Etrap döretmek')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{t('districts.create.title', 'Etrap döretmek')}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<DistrictForm mode="create" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
65
src/pages/settings/location/districtsEdit/index.tsx
Normal file
65
src/pages/settings/location/districtsEdit/index.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { DistrictForm } from '@/features/districts/components/districtsForm'
|
||||
import { useDistrictById } from '@/features/districts/hooks/useDistricts'
|
||||
|
||||
export default function DistrictEditPage() {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const navigate = useNavigate()
|
||||
const { t } = useTranslation()
|
||||
|
||||
const numericId = Number(id)
|
||||
const { data, isLoading, isError } = useDistrictById(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/location/districts')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/location/districts')}
|
||||
>
|
||||
{t('districts.title', 'Etraplar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span className="text-foreground font-medium">
|
||||
{t('districts.edit.breadcrumb', 'Üýtgetmek')}
|
||||
</span>
|
||||
</nav>
|
||||
|
||||
<h1 className="text-2xl font-bold text-foreground">
|
||||
{isLoading
|
||||
? '...'
|
||||
: `${t('districts.edit.title', 'Etrapy üýtgetmek')}: ${data?.name.tk ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{isLoading ? (
|
||||
<div className="bg-card border border-border rounded-xl overflow-hidden">
|
||||
{Array.from({ length: 3 }).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>
|
||||
) : (
|
||||
<DistrictForm mode="edit" initialData={data} districtId={numericId} />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
170
src/pages/settings/location/districtsView/index.tsx
Normal file
170
src/pages/settings/location/districtsView/index.tsx
Normal file
@@ -0,0 +1,170 @@
|
||||
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 { useDistrictById, useDeleteDistrict } from '@/features/districts/hooks/useDistricts'
|
||||
|
||||
export function DistrictViewPage() {
|
||||
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 } = useDistrictById(numericId)
|
||||
const deleteMutation = useDeleteDistrict()
|
||||
const [deleteOpen, setDeleteOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<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('/settings/location/districts')}
|
||||
>
|
||||
{t('nav.settings', 'Sazlamalar')}
|
||||
</span>
|
||||
<span>›</span>
|
||||
<span
|
||||
className="cursor-pointer hover:text-foreground transition-colors"
|
||||
onClick={() => navigate('/settings/location/districts')}
|
||||
>
|
||||
{t('districts.title', 'Etraplar')}
|
||||
</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('districts.view.title', 'Etrap giňişleýin')}: ${data?.name[lang] ?? ''}`}
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => navigate(`/settings/location/districts/${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: 3 }).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} />
|
||||
|
||||
<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('districts.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('districts.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('districts.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>
|
||||
)}
|
||||
|
||||
<AlertDialog open={deleteOpen} onOpenChange={setDeleteOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{t('common.confirmDelete', 'Öçürmegi tassyklaň')}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t('districts.deleteConfirm', 'Bu etrapy öçü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('/settings/location/districts'),
|
||||
})
|
||||
}
|
||||
>
|
||||
{deleteMutation.isPending
|
||||
? t('common.deleting', 'Öçürilýär...')
|
||||
: t('common.delete', 'Öçürmek')}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default DistrictViewPage
|
||||
Reference in New Issue
Block a user