added read me file

This commit is contained in:
Jelaletdin12
2026-05-15 19:56:27 +05:00
parent 1f79766192
commit b4085e5340
11 changed files with 882 additions and 254 deletions

View File

@@ -1,7 +1,35 @@
import { useEffect } from 'react'
import { RouterProvider } from 'react-router-dom'
import { toast } from 'sonner'
import i18next from 'i18next'
import { router } from '@/app/router'
function App() {
useEffect(() => {
// Fired by the Axios response interceptor (client.ts) when a 401 is received
// and the refresh token attempt also fails — the user must re-authenticate.
const handleUnauthorized = () => {
router.navigate('/login', { replace: true })
}
// Fired by the Axios response interceptor (client.ts) on 403 Forbidden.
// The user stays on the current page but receives a toast notification.
const handleForbidden = () => {
toast.error(
i18next.t('errors.forbidden', 'You do not have permission to perform this action.'),
{ id: 'auth-forbidden' },
)
}
window.addEventListener('auth:unauthorized', handleUnauthorized)
window.addEventListener('auth:forbidden', handleForbidden)
return () => {
window.removeEventListener('auth:unauthorized', handleUnauthorized)
window.removeEventListener('auth:forbidden', handleForbidden)
}
}, [])
return <RouterProvider router={router} />
}

View File

@@ -1,4 +1,3 @@
import { ThemeProvider as NextThemesProvider } from 'next-themes'
import type { ReactNode } from 'react'
interface ThemeProviderProps {
@@ -6,9 +5,7 @@ interface ThemeProviderProps {
}
export function ThemeProvider({ children }: ThemeProviderProps) {
return (
<NextThemesProvider attribute="class" defaultTheme="light" enableSystem={false}>
{children}
</NextThemesProvider>
)
// Theme is managed by useThemeStore in src/app/store/themeStore.ts
// next-themes was removed to avoid conflicts and double persistence issues.
return <>{children}</>
}

View File

@@ -3,6 +3,7 @@ import { createBrowserRouter, Navigate, Outlet } from "react-router-dom";
import { useAuthStore } from "../store/authStore";
import { Spinner } from "@/components/ui/spinner";
import { DashboardLayout } from "@/layouts/DashboardLayout";
import { AuthLayout } from "@/layouts/AuthLayout";
import { PageErrorFallback } from "@/app/providers/ErrorBoundary";
import NotFoundPage from "@/pages/notFoundPage";
@@ -150,12 +151,19 @@ export const router = createBrowserRouter([
errorElement: <PageErrorFallback />,
children: [
{
path: "/login",
element: (
<Suspense fallback={<PageLoader />}>
<LoginPage />
</Suspense>
),
// AuthLayout: semantic wrapper for all public/unauthenticated pages.
// Login manages its own full-screen layout internally.
element: <AuthLayout />,
children: [
{
path: "/login",
element: (
<Suspense fallback={<PageLoader />}>
<LoginPage />
</Suspense>
),
},
],
},
],
},

View File

@@ -1,9 +1,9 @@
import { useTheme } from "next-themes"
import { useThemeStore } from "@/app/store/themeStore"
import { Toaster as Sonner, type ToasterProps } from "sonner"
import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react"
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
const { theme } = useThemeStore()
return (
<Sonner

View File

@@ -0,0 +1,16 @@
import { Outlet } from 'react-router-dom'
/**
* AuthLayout — a thin semantic wrapper for all unauthenticated pages
* (login, register, reset-password, 2FA, etc.).
*
* The login page manages its own full-screen layout internally,
* so this component simply renders <Outlet /> without adding any
* visual chrome. The value of this layout is architectural:
* - Clear separation between public and private route trees.
* - Any future auth page added here inherits the same guard and error boundary.
* - Consistent with the DashboardLayout pattern used for auth'd routes.
*/
export function AuthLayout() {
return <Outlet />
}

View File

@@ -4,6 +4,8 @@ import { useTranslation } from "react-i18next";
import { Download, Trash2, Pencil, DownloadCloud } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Spinner } from "@/components/ui/spinner";
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/statusBadge";
import { AlertCircle, CheckCircle2, XCircle } from "lucide-react";
import {
AlertDialog,
AlertDialogAction,
@@ -23,24 +25,35 @@ import type { CardRequisiteStatus } from "@/features/cardRequisites/api/cardRequ
import { InfoRow } from "@/components/viewPageComponents";
// ─── Status badge ─────────────────────────────────────────────────────────────
const STATUS_BADGE: Record<
CardRequisiteStatus,
{ label: string; className: string }
> = {
const STATUS_CONFIG = {
pending: {
label: "GARAŞYLÝAR",
className: "bg-yellow-500/20 text-yellow-400 border border-yellow-500/30",
label: "Garaşylýar",
variant: "warning" as StatusBadgeVariant,
icon: AlertCircle,
},
approved: {
label: "TASSYKLANAN",
className:
"bg-emerald-500/20 text-emerald-400 border border-emerald-500/30",
label: "Tassyklanan",
variant: "success" as StatusBadgeVariant,
icon: CheckCircle2,
},
rejected: {
label: "RET EDILEN",
className: "bg-red-500/20 text-red-400 border border-red-500/30",
label: "Ret edilen",
variant: "error" as StatusBadgeVariant,
icon: XCircle,
},
};
} satisfies Record<
CardRequisiteStatus,
{ label: string; variant: StatusBadgeVariant; icon: React.ElementType }
>;
function CardRequisiteStatusBadge({ status }: { status: CardRequisiteStatus }) {
const cfg = STATUS_CONFIG[status];
if (!cfg)
return <span className="text-xs text-muted-foreground">{String(status)}</span>;
return (
<StatusBadge label={cfg.label} variant={cfg.variant} icon={cfg.icon} />
);
}
// ─── Section header ───────────────────────────────────────────────────────────
@@ -119,7 +132,6 @@ export default function CardRequisiteViewPage() {
);
}
const statusCfg = STATUS_BADGE[data.status] ?? STATUS_BADGE.pending;
return (
<div className="space-y-0">
@@ -160,11 +172,7 @@ export default function CardRequisiteViewPage() {
{data.created_at}
</InfoRow>
<InfoRow label={t("Status", "Status")}>
<span
className={`inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-semibold ${statusCfg.className}`}
>
{statusCfg.label}
</span>
<CardRequisiteStatusBadge status={data.status} />
</InfoRow>
<InfoRow label={t("Note", "Bellik")}>{data.note || "—"}</InfoRow>
<InfoRow label={t("Requested by", "Sargyt eden:")}>

View File

@@ -136,7 +136,7 @@ export default function UsersListPage() {
row.original.isActive ? (
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<XCircle size={18} className="text-muted-foreground/40" />
<XCircle size={18} className="text-destructive" />
),
},
{

View File

@@ -1,7 +1,7 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Trash2, Eye, Pencil } from 'lucide-react'
import { Trash2, Eye, Pencil, CheckCircle2, XCircle } from 'lucide-react'
import {
AlertDialog,
AlertDialogAction,
@@ -82,17 +82,9 @@ export default function ClientsPage() {
header: t('clients.fields.isActive', 'IŞJEŇ'),
cell: ({ row }) =>
row.original.isActive ? (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-primary text-primary">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path d="M2 6l3 3 5-5" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-destructive text-destructive">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path d="M3 3l6 6M9 3l-6 6" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" />
</svg>
</span>
<XCircle size={18} className="text-destructive" />
),
size: 80,
},

View File

@@ -1,7 +1,7 @@
import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { Trash2, Eye, Pencil } from 'lucide-react'
import { useState } from "react";
import { useNavigate } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Trash2, Eye, Pencil, CheckCircle2, XCircle } from "lucide-react";
import {
AlertDialog,
AlertDialogAction,
@@ -11,30 +11,33 @@ import {
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import { Button } from '@/components/ui/button'
import { DataTable, type ColumnDef } from '@/components/dataTable'
import { DataTableToolbar } from '@/components/dataTableToolbar'
import { useOperators, useDeleteOperator } from '@/features/operators/hooks/useOperators'
import type { Operator } from '@/features/operators/api/operatorsApi'
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { DataTable, type ColumnDef } from "@/components/dataTable";
import { DataTableToolbar } from "@/components/dataTableToolbar";
import {
useOperators,
useDeleteOperator,
} from "@/features/operators/hooks/useOperators";
import type { Operator } from "@/features/operators/api/operatorsApi";
// ─── OperatorsPage ────────────────────────────────────────────────────────────
export default function OperatorsPage() {
const { t } = useTranslation()
const navigate = useNavigate()
const deleteMutation = useDeleteOperator()
const { t } = useTranslation();
const navigate = useNavigate();
const deleteMutation = useDeleteOperator();
// ── Table state ─────────────────────────────────────────────────────────────
const [page, setPage] = useState(1)
const [perPage, setPerPage] = useState(25)
const [search, setSearch] = useState('')
const [isActiveFilter, setIsActiveFilter] = useState('')
const [columnVisibility, setColumnVisibility] = useState({})
const [columnOrder, setColumnOrder] = useState<string[]>([])
const [page, setPage] = useState(1);
const [perPage, setPerPage] = useState(25);
const [search, setSearch] = useState("");
const [isActiveFilter, setIsActiveFilter] = useState("");
const [columnVisibility, setColumnVisibility] = useState({});
const [columnOrder, setColumnOrder] = useState<string[]>([]);
// ── Delete dialog ────────────────────────────────────────────────────────────
const [deleteTarget, setDeleteTarget] = useState<Operator | null>(null)
const [deleteTarget, setDeleteTarget] = useState<Operator | null>(null);
// ── Query ────────────────────────────────────────────────────────────────────
const { data, isLoading } = useOperators({
@@ -42,17 +45,17 @@ export default function OperatorsPage() {
perPage,
search: search || undefined,
isActive: isActiveFilter || undefined,
})
});
const operators = data?.data ?? []
const totalPages = data?.meta.totalPages ?? 1
const totalCount = data?.meta.totalCount ?? 0
const operators = data?.data ?? [];
const totalPages = data?.meta.totalPages ?? 1;
const totalCount = data?.meta.totalCount ?? 0;
// ── Columns ──────────────────────────────────────────────────────────────────
const columns: ColumnDef<Operator>[] = [
{
accessorKey: 'id',
header: 'ID',
accessorKey: "id",
header: "ID",
cell: ({ row }) => (
<span
className="text-primary font-semibold cursor-pointer hover:underline text-sm"
@@ -64,70 +67,51 @@ export default function OperatorsPage() {
size: 80,
},
{
accessorKey: 'username',
header: t('operators.fields.username', 'ULANYJY ADY'),
accessorKey: "username",
header: t("operators.fields.username", "ULANYJY ADY"),
cell: ({ row }) => (
<span className="text-sm text-foreground">{row.original.username}</span>
),
},
{
accessorKey: 'name',
header: t('operators.fields.name', 'ADY'),
accessorKey: "name",
header: t("operators.fields.name", "ADY"),
cell: ({ row }) => (
<span className="text-sm text-foreground">{row.original.name}</span>
),
},
{
accessorKey: 'phone',
header: t('operators.fields.phone', 'TELEFON'),
accessorKey: "phone",
header: t("operators.fields.phone", "TELEFON"),
cell: ({ row }) => (
<span className="text-sm text-foreground">
{row.original.phone ?? '—'}
{row.original.phone ?? "—"}
</span>
),
},
{
accessorKey: 'email',
header: t('operators.fields.email', 'E-POÇTA'),
accessorKey: "email",
header: t("operators.fields.email", "E-POÇTA"),
cell: ({ row }) => (
<span className="text-sm text-foreground">
{row.original.email ?? '—'}
{row.original.email ?? "—"}
</span>
),
},
{
accessorKey: 'isActive',
header: t('operators.fields.isActive', 'IŞJEŇ'),
accessorKey: "isActive",
header: t("operators.fields.isActive", "IŞJEŇ"),
cell: ({ row }) =>
row.original.isActive ? (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-primary text-primary">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path
d="M2 6l3 3 5-5"
stroke="currentColor"
strokeWidth="1.8"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</span>
<CheckCircle2 size={18} className="text-emerald-500" />
) : (
<span className="inline-flex items-center justify-center w-6 h-6 rounded-full border-2 border-destructive text-destructive">
<svg width="12" height="12" viewBox="0 0 12 12" fill="none">
<path
d="M3 3l6 6M9 3l-6 6"
stroke="currentColor"
strokeWidth="1.8"
strokeLinecap="round"
/>
</svg>
</span>
<XCircle size={18} className="text-destructive" />
),
size: 80,
},
{
id: 'actions',
header: '',
id: "actions",
header: "",
cell: ({ row }) => (
<div className="flex items-center gap-1 justify-end">
<Button
@@ -159,17 +143,17 @@ export default function OperatorsPage() {
size: 120,
enableSorting: false,
},
]
];
const columnMetas = columns
.filter((c) => 'accessorKey' in c && c.accessorKey)
.filter((c) => "accessorKey" in c && c.accessorKey)
.map((c) => ({
id: ('accessorKey' in c ? String(c.accessorKey) : c.id) as string,
id: ("accessorKey" in c ? String(c.accessorKey) : c.id) as string,
label:
typeof c.header === 'string'
typeof c.header === "string"
? c.header
: ('accessorKey' in c ? String(c.accessorKey) : '') ?? '',
}))
: (("accessorKey" in c ? String(c.accessorKey) : "") ?? ""),
}));
// ── Render ───────────────────────────────────────────────────────────────────
return (
@@ -177,61 +161,69 @@ export default function OperatorsPage() {
{/* Page header */}
<div className="mb-6">
<h1 className="text-2xl font-semibold text-foreground">
{t('operators.title', 'Operatorlar')}
{t("operators.title", "Operatorlar")}
</h1>
</div>
<div className="bg-card border border-border rounded-xl p-4">
<div className="bg-card border border-border rounded-xl p-4">
{/* Toolbar */}
<DataTableToolbar
searchValue={search}
onSearchChange={(v) => {
setSearch(v);
setPage(1);
}}
searchPlaceholder={t("common.search", "Gözlemek")}
columns={columnMetas}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
filterFields={[
{
id: "isActive",
label: t("operators.fields.isActive", "Işjeň"),
options: [
{ value: "true", label: t("common.active", "Işjeň") },
{ value: "false", label: t("common.inactive", "Işjeň däl") },
],
},
]}
activeFilters={[{ fieldId: "isActive", value: isActiveFilter }]}
onFilterChange={(fieldId, value) => {
if (fieldId === "isActive") setIsActiveFilter(value);
setPage(1);
}}
onFilterReset={() => {
setIsActiveFilter("");
setPage(1);
}}
perPageOptions={[10, 25, 50, 100]}
perPage={perPage}
onPerPageChange={(v) => {
setPerPage(v);
setPage(1);
}}
actionLabel={t("operators.createBtn", "Operator döredin")}
onAction={() => navigate("/operators/create")}
/>
{/* Toolbar */}
<DataTableToolbar
searchValue={search}
onSearchChange={(v) => { setSearch(v); setPage(1) }}
searchPlaceholder={t('common.search', 'Gözlemek')}
columns={columnMetas}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
filterFields={[
{
id: 'isActive',
label: t('operators.fields.isActive', 'Işjeň'),
options: [
{ value: 'true', label: t('common.active', 'Işjeň') },
{ value: 'false', label: t('common.inactive', 'Işjeň däl') },
],
},
]}
activeFilters={[{ fieldId: 'isActive', value: isActiveFilter }]}
onFilterChange={(fieldId, value) => {
if (fieldId === 'isActive') setIsActiveFilter(value)
setPage(1)
}}
onFilterReset={() => { setIsActiveFilter(''); setPage(1) }}
perPageOptions={[10, 25, 50, 100]}
perPage={perPage}
onPerPageChange={(v) => { setPerPage(v); setPage(1) }}
actionLabel={t('operators.createBtn', 'Operator döredin')}
onAction={() => navigate('/operators/create')}
/>
{/* Table */}
<DataTable
columns={columns}
data={operators}
isLoading={isLoading}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
getRowId={(row) => String(row.id)}
currentPage={page}
totalPages={totalPages}
totalCount={totalCount}
onPageChange={setPage}
enableRowSelection
/>
</div>
{/* Table */}
<DataTable
columns={columns}
data={operators}
isLoading={isLoading}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
columnOrder={columnOrder}
onColumnOrderChange={setColumnOrder}
getRowId={(row) => String(row.id)}
currentPage={page}
totalPages={totalPages}
totalCount={totalCount}
onPageChange={setPage}
enableRowSelection
/>
</div>
{/* Delete dialog */}
<AlertDialog
@@ -241,33 +233,33 @@ export default function OperatorsPage() {
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>
{t('operators.deleteTitle', 'Operatory pozmak')}
{t("operators.deleteTitle", "Operatory pozmak")}
</AlertDialogTitle>
<AlertDialogDescription>
{t(
'operators.deleteConfirm',
'{{name}} operatoryny pozmak isleýärsiňizmi? Bu amaly yzyna gaýtaryp bolmaz.',
{ name: deleteTarget?.name ?? '' },
"operators.deleteConfirm",
"{{name}} operatoryny pozmak isleýärsiňizmi? Bu amaly yzyna gaýtaryp bolmaz.",
{ name: deleteTarget?.name ?? "" },
)}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('common.cancel', 'Ýatyr')}</AlertDialogCancel>
<AlertDialogCancel>{t("common.cancel", "Ýatyr")}</AlertDialogCancel>
<AlertDialogAction
className="bg-destructive hover:bg-destructive/90 text-destructive-foreground"
onClick={() => {
if (deleteTarget) {
deleteMutation.mutate(deleteTarget.id, {
onSuccess: () => setDeleteTarget(null),
})
});
}
}}
>
{t('common.delete', 'Poz')}
{t("common.delete", "Poz")}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</div>
)
}
);
}