added lang support to view pages
This commit is contained in:
1 parent
a0ed9a702c
commit
a26e788415
25 files changed
+1213
-610
No files matched your search
@@ -1,19 +1,8 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
Loader2,
|
||||
Pencil,
|
||||
Trash2,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
ChevronDown,
|
||||
Plus,
|
||||
Search,
|
||||
SlidersHorizontal,
|
||||
ChevronUp,
|
||||
} from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Loader2, Pencil, Trash2, CheckCircle2, XCircle, ChevronDown, Plus, Search, SlidersHorizontal, ChevronUp } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
@@ -23,31 +12,24 @@ import {
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/components/ui/alert-dialog'
|
||||
import { Section, InfoRow } from '@/components/viewPageComponents'
|
||||
import { useUser, useDeleteUser } from '@/features/allUsers/hooks/useAllUsers'
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Section, InfoRow } from "@/components/viewPageComponents";
|
||||
import { useUser, useDeleteUser } from "@/features/allUsers/hooks/useAllUsers";
|
||||
|
||||
// ─── Collapsible Section ──────────────────────────────────────────────────────
|
||||
|
||||
interface CollapsibleBlockProps {
|
||||
title: string
|
||||
actionLabel: string
|
||||
onAction: () => void
|
||||
emptyMessage: string
|
||||
searchPlaceholder?: string
|
||||
showFilter?: boolean
|
||||
title: string;
|
||||
actionLabel: string;
|
||||
onAction: () => void;
|
||||
emptyMessage: string;
|
||||
searchPlaceholder?: string;
|
||||
showFilter?: boolean;
|
||||
}
|
||||
|
||||
function CollapsibleBlock({
|
||||
title,
|
||||
actionLabel,
|
||||
onAction,
|
||||
emptyMessage,
|
||||
searchPlaceholder = 'Gözlemek',
|
||||
showFilter = false,
|
||||
}: CollapsibleBlockProps) {
|
||||
const [open, setOpen] = useState(true)
|
||||
const [search, setSearch] = useState('')
|
||||
function CollapsibleBlock({ title, actionLabel, onAction, emptyMessage, searchPlaceholder, showFilter = false }: CollapsibleBlockProps) {
|
||||
const [open, setOpen] = useState(true);
|
||||
const [search, setSearch] = useState("");
|
||||
|
||||
return (
|
||||
<div className="mb-6">
|
||||
@@ -64,10 +46,7 @@ function CollapsibleBlock({
|
||||
{/* Sub-toolbar */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b border-border">
|
||||
<div className="relative">
|
||||
<Search
|
||||
size={13}
|
||||
className="absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
||||
/>
|
||||
<Search size={13} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none" />
|
||||
<input
|
||||
type="text"
|
||||
value={search}
|
||||
@@ -92,13 +71,7 @@ function CollapsibleBlock({
|
||||
{/* Empty state */}
|
||||
<div className="flex flex-col items-center justify-center py-16 gap-3">
|
||||
<div className="w-16 h-16 rounded-lg border border-border bg-muted/30 flex items-center justify-center">
|
||||
<svg
|
||||
width="32"
|
||||
height="32"
|
||||
viewBox="0 0 32 32"
|
||||
fill="none"
|
||||
className="text-muted-foreground/40"
|
||||
>
|
||||
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" className="text-muted-foreground/40">
|
||||
<rect x="4" y="8" width="24" height="18" rx="2" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M4 13h24" stroke="currentColor" strokeWidth="1.5" />
|
||||
<path d="M9 8V6" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
|
||||
@@ -115,51 +88,45 @@ function CollapsibleBlock({
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// ─── UserViewPage ─────────────────────────────────────────────────────────────
|
||||
|
||||
export default function UserViewPage() {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
const { id } = useParams<{ id: string }>()
|
||||
const userId = Number(id)
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const userId = Number(id);
|
||||
|
||||
const { data: user, isLoading, isError } = useUser(userId)
|
||||
const deleteUser = useDeleteUser()
|
||||
const { data: user, isLoading, isError } = useUser(userId);
|
||||
const deleteUser = useDeleteUser();
|
||||
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false)
|
||||
const [showDeleteDialog, setShowDeleteDialog] = useState(false);
|
||||
|
||||
const handleDeleteConfirm = async () => {
|
||||
await deleteUser.mutateAsync(userId)
|
||||
navigate('/users')
|
||||
}
|
||||
await deleteUser.mutateAsync(userId);
|
||||
navigate("/users");
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-[400px]">
|
||||
<Loader2 size={24} className="animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (isError || !user) {
|
||||
return (
|
||||
<div className="p-6 text-center text-muted-foreground">
|
||||
{t('common.notFound', 'Maglumat tapylmady')}
|
||||
</div>
|
||||
)
|
||||
return <div className="p-6 text-center text-muted-foreground">{t("common.notFound", "Maglumat tapylmady")}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 max-w-4xl space-y-0">
|
||||
|
||||
|
||||
{/* Title + actions */}
|
||||
<div className="flex items-start justify-between mb-6">
|
||||
<h1 className="text-xl font-bold text-foreground leading-tight">
|
||||
{t('users.viewTitle', 'Ulanyjy giňişleýin')}: {user.name} ({user.username})
|
||||
{t("users.viewTitle", "Ulanyjy giňişleýin")}: {user.name} ({user.username})
|
||||
</h1>
|
||||
<div className="flex items-center gap-2 shrink-0 ml-4">
|
||||
<Button
|
||||
@@ -170,12 +137,7 @@ export default function UserViewPage() {
|
||||
>
|
||||
<Trash2 size={15} />
|
||||
</Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
onClick={() => navigate(`/users/${userId}/edit`)}
|
||||
>
|
||||
<Button variant="ghost" size="icon" className="h-8 w-8" onClick={() => navigate(`/users/${userId}/edit`)}>
|
||||
<Pencil size={15} />
|
||||
</Button>
|
||||
</div>
|
||||
@@ -183,12 +145,12 @@ export default function UserViewPage() {
|
||||
|
||||
{/* Main info */}
|
||||
<Section>
|
||||
<InfoRow label="ID" value={user.id} />
|
||||
<InfoRow label={t('users.fields.username', 'Ulanyjy ady')} value={user.username} />
|
||||
<InfoRow label={t('users.fields.name', 'Ady')} value={user.name} />
|
||||
<InfoRow label={t('users.fields.phone', 'Telefon')} value={user.phone} />
|
||||
<InfoRow label={t('users.fields.email', 'E-poçta')} value={user.email} />
|
||||
<InfoRow label={t('users.fields.isActive', 'Işjeň')}>
|
||||
<InfoRow label={t("common.id", "ID")} value={user.id} />
|
||||
<InfoRow label={t("users.fields.username", "Ulanyjy ady")} value={user.username} />
|
||||
<InfoRow label={t("users.fields.name", "Ady")} value={user.name} />
|
||||
<InfoRow label={t("users.fields.phone", "Telefon")} value={user.phone} />
|
||||
<InfoRow label={t("users.fields.email", "E-poçta")} value={user.email} />
|
||||
<InfoRow label={t("users.fields.isActive", "Işjeň")}>
|
||||
{user.isActive ? (
|
||||
<CheckCircle2 size={18} className="text-emerald-500" />
|
||||
) : (
|
||||
@@ -199,66 +161,61 @@ export default function UserViewPage() {
|
||||
|
||||
{/* Rollar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.roles', 'Rollar')}
|
||||
actionLabel={t('users.actions.addRole', 'Rol birikdiriň')}
|
||||
title={t("users.sections.roles", "Rollar")}
|
||||
actionLabel={t("users.actions.addRole", "Rol birikdiriň")}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.roles', 'Berlen kriteriýalara Rol gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
emptyMessage={t("users.empty.roles", "Berlen kriteriýalara Rol gabat gelmedi.")}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
|
||||
{/* Rugsatlar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.permissions', 'Rugsatlar')}
|
||||
actionLabel={t('users.actions.addPermission', 'Rugsat birikdiriň')}
|
||||
title={t("users.sections.permissions", "Rugsatlar")}
|
||||
actionLabel={t("users.actions.addPermission", "Rugsat birikdiriň")}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.permissions', 'Berlen kriteriýalara Rugsat gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
emptyMessage={t("users.empty.permissions", "Berlen kriteriýalara Rugsat gabat gelmedi.")}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
|
||||
{/* Şahamçalar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.branches', 'Şahamçalar')}
|
||||
actionLabel={t('users.actions.addBranch', 'Şahamça birikdiriň')}
|
||||
title={t("users.sections.branches", "Şahamçalar")}
|
||||
actionLabel={t("users.actions.addBranch", "Şahamça birikdiriň")}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.branches', 'Berlen kriteriýalara Şahamça gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
emptyMessage={t("users.empty.branches", "Berlen kriteriýalara Şahamça gabat gelmedi.")}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
showFilter
|
||||
/>
|
||||
|
||||
{/* Ammallar */}
|
||||
<CollapsibleBlock
|
||||
title={t('users.sections.audit', 'Ammallar')}
|
||||
actionLabel={t('users.actions.addAction', 'Hereket')}
|
||||
title={t("users.sections.audit", "Ammallar")}
|
||||
actionLabel={t("users.actions.addAction", "Hereket")}
|
||||
onAction={() => {}}
|
||||
emptyMessage={t('users.empty.audit', 'Berlen kriteriýalara Hereket gabat gelmedi.')}
|
||||
searchPlaceholder={t('common.search', 'Gözlemek')}
|
||||
emptyMessage={t("users.empty.audit", "Berlen kriteriýalara Hereket gabat gelmedi.")}
|
||||
searchPlaceholder={t("common.search", "Gözlemek")}
|
||||
/>
|
||||
|
||||
{/* Delete dialog */}
|
||||
<AlertDialog open={showDeleteDialog} onOpenChange={setShowDeleteDialog}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{t('users.deleteDialog.title', 'Ulanyjyny öçürmek')}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogTitle>{t("users.deleteDialog.title", "Ulanyjyny öçürmek")}</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
{t(
|
||||
'users.deleteDialog.description',
|
||||
'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.',
|
||||
).replace('{name}', user.username)}
|
||||
{t("users.deleteDialog.description", 'Siz "{name}" ulanyjysyny öçürjekmi? Bu amal yzyna gaýtarylyp bilinmez.').replace(
|
||||
"{name}",
|
||||
user.username,
|
||||
)}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>{t('common.cancel', 'Ýok')}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleDeleteConfirm}
|
||||
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
||||
>
|
||||
{t('common.delete', 'Öçür')}
|
||||
<AlertDialogCancel>{t("common.cancel", "Ýok")}</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={handleDeleteConfirm} className="bg-destructive text-destructive-foreground hover:bg-destructive/90">
|
||||
{t("common.delete", "Öçür")}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user