added users pages, stepper
This commit is contained in:
198
src/features/allUsers/api/allUsersApi.ts
Normal file
198
src/features/allUsers/api/allUsersApi.ts
Normal file
@@ -0,0 +1,198 @@
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface User {
|
||||
id: number
|
||||
username: string
|
||||
name: string
|
||||
phone: string
|
||||
email: string | null
|
||||
isActive: boolean
|
||||
phoneVerified: boolean
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}
|
||||
|
||||
export interface UserListItem {
|
||||
id: number
|
||||
username: string
|
||||
name: string
|
||||
phone: string
|
||||
email: string | null
|
||||
isActive: boolean
|
||||
}
|
||||
|
||||
export interface UsersListResponse {
|
||||
data: UserListItem[]
|
||||
total: number
|
||||
page: number
|
||||
perPage: number
|
||||
totalPages: number
|
||||
}
|
||||
|
||||
export interface UsersListParams {
|
||||
page?: number
|
||||
perPage?: number
|
||||
search?: string
|
||||
isActive?: string
|
||||
}
|
||||
|
||||
export interface CreateUserPayload {
|
||||
username: string
|
||||
name: string
|
||||
phone: string
|
||||
email?: string
|
||||
password: string
|
||||
phoneVerified: boolean
|
||||
isActive: boolean
|
||||
}
|
||||
|
||||
export interface UpdateUserPayload {
|
||||
username?: string
|
||||
name?: string
|
||||
phone?: string
|
||||
email?: string
|
||||
phoneVerified?: boolean
|
||||
isActive?: boolean
|
||||
}
|
||||
|
||||
// ─── Mock Data ────────────────────────────────────────────────────────────────
|
||||
|
||||
const MOCK_USERS: User[] = Array.from({ length: 50 }, (_, i) => {
|
||||
const id = 5970 - i
|
||||
const names = [
|
||||
'Orazowa Nurtuwak Täşliyewna',
|
||||
'Hallyýewa Aýna Gurbanmyradowna',
|
||||
'Sopýýewa Maral Agamyradowna',
|
||||
'Babamurat Baýnazarow Şanazarowič',
|
||||
'Narmet Narmet',
|
||||
'Sheker Durdyyewa',
|
||||
'kamalowyusup',
|
||||
'Mahmudowberdimet',
|
||||
'allanazarowasayyara',
|
||||
'dadayewjepbar',
|
||||
]
|
||||
const usernames = [
|
||||
'Nurtuwak_1970', 'Ayna_1989', 'Maral_1974', 'Babamurat_0002', 'Narmet',
|
||||
'8319_ShekerDurdyyewa', 'kamalowyusup', 'Mahmudowberdimet',
|
||||
'allanazarowasayyara', 'dadayewjepbar',
|
||||
]
|
||||
const idx = i % names.length
|
||||
return {
|
||||
id,
|
||||
username: i < usernames.length ? usernames[idx] : `user_${id}`,
|
||||
name: names[idx],
|
||||
phone: `+(993)-6${Math.floor(Math.random() * 9 + 1)}-${String(Math.floor(Math.random() * 90 + 10))}-${String(Math.floor(Math.random() * 90 + 10))}-${String(Math.floor(Math.random() * 90 + 10))}`,
|
||||
email: i % 4 === 0 ? `user${id}@tbbank.gov.tm` : null,
|
||||
isActive: Math.random() > 0.1,
|
||||
phoneVerified: Math.random() > 0.3,
|
||||
createdAt: new Date(Date.now() - Math.random() * 1e10).toISOString(),
|
||||
updatedAt: new Date(Date.now() - Math.random() * 1e9).toISOString(),
|
||||
}
|
||||
})
|
||||
|
||||
// ─── Mock delay helper ────────────────────────────────────────────────────────
|
||||
|
||||
const delay = (ms = 500) => new Promise((res) => setTimeout(res, ms))
|
||||
|
||||
// ─── API Functions ────────────────────────────────────────────────────────────
|
||||
|
||||
export const usersApi = {
|
||||
/**
|
||||
* GET /users
|
||||
*/
|
||||
getUsers: async (params: UsersListParams = {}): Promise<UsersListResponse> => {
|
||||
await delay()
|
||||
// Uncomment for real API:
|
||||
// const res = await apiClient.get<UsersListResponse>('/users', { params })
|
||||
// return res.data
|
||||
|
||||
const { page = 1, perPage = 25, search = '', isActive } = params
|
||||
|
||||
let filtered = [...MOCK_USERS]
|
||||
|
||||
if (search.trim()) {
|
||||
const q = search.toLowerCase()
|
||||
filtered = filtered.filter(
|
||||
(u) =>
|
||||
u.username.toLowerCase().includes(q) ||
|
||||
u.name.toLowerCase().includes(q) ||
|
||||
u.phone.includes(q),
|
||||
)
|
||||
}
|
||||
|
||||
if (isActive !== undefined && isActive !== '') {
|
||||
const active = isActive === 'true'
|
||||
filtered = filtered.filter((u) => u.isActive === active)
|
||||
}
|
||||
|
||||
const total = filtered.length
|
||||
const totalPages = Math.ceil(total / perPage)
|
||||
const start = (page - 1) * perPage
|
||||
const data = filtered.slice(start, start + perPage).map(({ id, username, name, phone, email, isActive }) => ({
|
||||
id, username, name, phone, email, isActive,
|
||||
}))
|
||||
|
||||
return { data, total, page, perPage, totalPages }
|
||||
},
|
||||
|
||||
/**
|
||||
* GET /users/:id
|
||||
*/
|
||||
getUserById: async (id: number): Promise<User> => {
|
||||
await delay()
|
||||
// const res = await apiClient.get<User>(`/users/${id}`)
|
||||
// return res.data
|
||||
|
||||
const user = MOCK_USERS.find((u) => u.id === id)
|
||||
if (!user) throw new Error(`User ${id} not found`)
|
||||
return user
|
||||
},
|
||||
|
||||
/**
|
||||
* POST /users
|
||||
*/
|
||||
createUser: async (payload: CreateUserPayload): Promise<User> => {
|
||||
await delay(800)
|
||||
// const res = await apiClient.post<User>('/users', payload)
|
||||
// return res.data
|
||||
|
||||
const newUser: User = {
|
||||
id: Math.max(...MOCK_USERS.map((u) => u.id)) + 1,
|
||||
username: payload.username,
|
||||
name: payload.name,
|
||||
phone: payload.phone,
|
||||
email: payload.email ?? null,
|
||||
isActive: payload.isActive,
|
||||
phoneVerified: payload.phoneVerified,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
MOCK_USERS.unshift(newUser)
|
||||
return newUser
|
||||
},
|
||||
|
||||
/**
|
||||
* PUT /users/:id
|
||||
*/
|
||||
updateUser: async (id: number, payload: UpdateUserPayload): Promise<User> => {
|
||||
await delay(800)
|
||||
// const res = await apiClient.put<User>(`/users/${id}`, payload)
|
||||
// return res.data
|
||||
|
||||
const idx = MOCK_USERS.findIndex((u) => u.id === id)
|
||||
if (idx === -1) throw new Error(`User ${id} not found`)
|
||||
MOCK_USERS[idx] = { ...MOCK_USERS[idx], ...payload, updatedAt: new Date().toISOString() }
|
||||
return MOCK_USERS[idx]
|
||||
},
|
||||
|
||||
/**
|
||||
* DELETE /users/:id
|
||||
*/
|
||||
deleteUser: async (id: number): Promise<void> => {
|
||||
await delay(600)
|
||||
// await apiClient.delete(`/users/${id}`)
|
||||
|
||||
const idx = MOCK_USERS.findIndex((u) => u.id === id)
|
||||
if (idx !== -1) MOCK_USERS.splice(idx, 1)
|
||||
},
|
||||
}
|
||||
326
src/features/allUsers/components/allUsersForm.tsx
Normal file
326
src/features/allUsers/components/allUsersForm.tsx
Normal file
@@ -0,0 +1,326 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { FormInput } from '@/components/formInput'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useCreateUser, useUpdateUser } from '../hooks/useAllUsers'
|
||||
import type { User, CreateUserPayload, UpdateUserPayload } from '../api/allUsersApi'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface UserFormProps {
|
||||
mode: 'create' | 'edit'
|
||||
initialData?: User
|
||||
userId?: number
|
||||
}
|
||||
|
||||
interface FormState {
|
||||
username: string
|
||||
name: string
|
||||
phone: string
|
||||
email: string
|
||||
password: string
|
||||
phoneVerified: boolean
|
||||
isActive: boolean
|
||||
}
|
||||
|
||||
interface FormErrors {
|
||||
username?: string
|
||||
name?: string
|
||||
phone?: string
|
||||
email?: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
// ─── Validation ───────────────────────────────────────────────────────────────
|
||||
|
||||
function validateForm(state: FormState, mode: 'create' | 'edit'): FormErrors {
|
||||
const errors: FormErrors = {}
|
||||
|
||||
if (!state.username.trim()) errors.username = 'Ulanyjy ady hökmany'
|
||||
else if (state.username.length < 3) errors.username = 'Ulanyjy ady iň az 3 harp bolmaly'
|
||||
|
||||
if (!state.name.trim()) errors.name = 'Ady hökmany'
|
||||
|
||||
if (!state.phone.trim()) errors.phone = 'Telefon hökmany'
|
||||
else if (!/^\d[\d\s-]{6,}$/.test(state.phone)) errors.phone = 'Nädogry telefon formaty'
|
||||
|
||||
if (state.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(state.email)) {
|
||||
errors.email = 'Nädogry e-poçta formaty'
|
||||
}
|
||||
|
||||
if (mode === 'create') {
|
||||
if (!state.password) errors.password = 'Açar sözi hökmany'
|
||||
else if (state.password.length < 6) errors.password = 'Açar sözi iň az 6 harp bolmaly'
|
||||
}
|
||||
|
||||
return errors
|
||||
}
|
||||
|
||||
// ─── UserForm ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function UserForm({ mode, initialData, userId }: UserFormProps) {
|
||||
const { t } = useTranslation()
|
||||
const navigate = useNavigate()
|
||||
|
||||
const createUser = useCreateUser()
|
||||
const updateUser = useUpdateUser(userId ?? 0)
|
||||
|
||||
const isPending = createUser.isPending || updateUser.isPending
|
||||
|
||||
const [form, setForm] = useState<FormState>({
|
||||
username: '',
|
||||
name: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
password: '',
|
||||
phoneVerified: false,
|
||||
isActive: true,
|
||||
})
|
||||
|
||||
const [errors, setErrors] = useState<FormErrors>({})
|
||||
|
||||
// Populate form when initialData is available (edit mode)
|
||||
useEffect(() => {
|
||||
if (initialData) {
|
||||
setForm({
|
||||
username: initialData.username,
|
||||
name: initialData.name,
|
||||
phone: initialData.phone.replace(/^\+993[-\s]?/, ''),
|
||||
email: initialData.email ?? '',
|
||||
password: '',
|
||||
phoneVerified: initialData.phoneVerified,
|
||||
isActive: initialData.isActive,
|
||||
})
|
||||
}
|
||||
}, [initialData])
|
||||
|
||||
const setField = <K extends keyof FormState>(key: K, value: FormState[K]) => {
|
||||
setForm((prev) => ({ ...prev, [key]: value }))
|
||||
if (errors[key as keyof FormErrors]) {
|
||||
setErrors((prev) => ({ ...prev, [key]: undefined }))
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
const validationErrors = validateForm(form, mode)
|
||||
if (Object.keys(validationErrors).length > 0) {
|
||||
setErrors(validationErrors)
|
||||
return
|
||||
}
|
||||
|
||||
if (mode === 'create') {
|
||||
const payload: CreateUserPayload = {
|
||||
username: form.username.trim(),
|
||||
name: form.name.trim(),
|
||||
phone: form.phone.trim(),
|
||||
email: form.email.trim() || undefined,
|
||||
password: form.password,
|
||||
phoneVerified: form.phoneVerified,
|
||||
isActive: form.isActive,
|
||||
}
|
||||
await createUser.mutateAsync(payload)
|
||||
navigate('/users')
|
||||
} else {
|
||||
const payload: UpdateUserPayload = {
|
||||
username: form.username.trim(),
|
||||
name: form.name.trim(),
|
||||
phone: form.phone.trim(),
|
||||
email: form.email.trim() || undefined,
|
||||
phoneVerified: form.phoneVerified,
|
||||
isActive: form.isActive,
|
||||
}
|
||||
await updateUser.mutateAsync(payload)
|
||||
navigate(`/users/${userId}`)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
{/* Form card */}
|
||||
<div className="bg-card border border-border rounded-xl divide-y divide-border">
|
||||
|
||||
{/* Username */}
|
||||
<div className="grid grid-cols-[280px_1fr] items-start px-6 py-4">
|
||||
<div className="pt-0.5">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.username', 'Ulanyjy ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.usernameHint', 'Unikal login ady')}
|
||||
</p>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={form.username}
|
||||
onChange={(v) => setField('username', v)}
|
||||
placeholder={t('users.fields.username', 'Ulanyjy ady')}
|
||||
error={errors.username}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Full name */}
|
||||
<div className="grid grid-cols-[280px_1fr] items-start px-6 py-4">
|
||||
<div className="pt-0.5">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.name', 'Ady')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.nameHint', 'Doly ady we familiýasy')}
|
||||
</p>
|
||||
</div>
|
||||
<FormInput
|
||||
type="text"
|
||||
value={form.name}
|
||||
onChange={(v) => setField('name', v)}
|
||||
placeholder={t('users.fields.name', 'Ady')}
|
||||
error={errors.name}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Phone */}
|
||||
<div className="grid grid-cols-[280px_1fr] items-start px-6 py-4">
|
||||
<div className="pt-0.5">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.phone', 'Telefon')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.phoneHint', '+993 bilen başlanýar')}
|
||||
</p>
|
||||
</div>
|
||||
<FormInput
|
||||
type="phone"
|
||||
value={form.phone}
|
||||
onChange={(v) => setField('phone', v)}
|
||||
placeholder="62-38-49-56"
|
||||
error={errors.phone}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Email */}
|
||||
<div className="grid grid-cols-[280px_1fr] items-start px-6 py-4">
|
||||
<div className="pt-0.5">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.email', 'E-poçta')}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.emailHint', 'Islege görä')}
|
||||
</p>
|
||||
</div>
|
||||
<FormInput
|
||||
type="email"
|
||||
value={form.email}
|
||||
onChange={(v) => setField('email', v)}
|
||||
placeholder={t('users.fields.email', 'E-poçta')}
|
||||
error={errors.email}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Password — only in create mode */}
|
||||
{mode === 'create' && (
|
||||
<div className="grid grid-cols-[280px_1fr] items-start px-6 py-4">
|
||||
<div className="pt-0.5">
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.password', 'Açar sözi')}
|
||||
<span className="text-destructive ml-0.5">*</span>
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.passwordHint', 'Iň az 6 harp')}
|
||||
</p>
|
||||
</div>
|
||||
<FormInput
|
||||
type="password"
|
||||
value={form.password}
|
||||
onChange={(v) => setField('password', v)}
|
||||
placeholder={t('users.fields.password', 'Açar sözi')}
|
||||
error={errors.password}
|
||||
disabled={isPending}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Phone verified */}
|
||||
<div className="grid grid-cols-[280px_1fr] items-center px-6 py-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.phoneVerified', 'Telefon tassyklanan')}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.phoneVerifiedHint', 'SMS arkaly tassyklandy')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="phoneVerified"
|
||||
checked={form.phoneVerified}
|
||||
onCheckedChange={(v) => setField('phoneVerified', !!v)}
|
||||
disabled={isPending}
|
||||
/>
|
||||
<Label htmlFor="phoneVerified" className="text-sm text-muted-foreground cursor-pointer">
|
||||
{form.phoneVerified
|
||||
? t('common.yes', 'Hawa')
|
||||
: t('common.no', 'Ýok')}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Active */}
|
||||
<div className="grid grid-cols-[280px_1fr] items-center px-6 py-4">
|
||||
<div>
|
||||
<p className="text-sm font-medium text-foreground">
|
||||
{t('users.fields.isActive', 'Işjeň')}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-0.5">
|
||||
{t('users.fields.isActiveHint', 'Ulanyjynyň ulgama girip-bilmezligi')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="isActive"
|
||||
checked={form.isActive}
|
||||
onCheckedChange={(v) => setField('isActive', !!v)}
|
||||
disabled={isPending}
|
||||
/>
|
||||
<Label htmlFor="isActive" className="text-sm text-muted-foreground cursor-pointer">
|
||||
{form.isActive
|
||||
? t('common.active', 'Işjeň')
|
||||
: t('common.inactive', 'Işjeň däl')}
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer actions */}
|
||||
<div className="flex items-center justify-end gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => navigate(-1)}
|
||||
disabled={isPending}
|
||||
>
|
||||
{t('common.cancel', 'Ýatyr')}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={handleSubmit}
|
||||
disabled={isPending}
|
||||
>
|
||||
{isPending && <Loader2 size={14} className="mr-2 animate-spin" />}
|
||||
{mode === 'create'
|
||||
? t('users.actions.create', 'Ulanyjy dörediň')
|
||||
: t('users.actions.save', 'Ýatda sakla')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
94
src/features/allUsers/hooks/useAllUsers.ts
Normal file
94
src/features/allUsers/hooks/useAllUsers.ts
Normal file
@@ -0,0 +1,94 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { toast } from 'sonner'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import {
|
||||
usersApi,
|
||||
type CreateUserPayload,
|
||||
type UpdateUserPayload,
|
||||
type UsersListParams,
|
||||
} from '../api/allUsersApi'
|
||||
|
||||
// ─── Query Keys ───────────────────────────────────────────────────────────────
|
||||
|
||||
export const userKeys = {
|
||||
all: ['users'] as const,
|
||||
lists: () => [...userKeys.all, 'list'] as const,
|
||||
list: (params: UsersListParams) => [...userKeys.lists(), params] as const,
|
||||
details: () => [...userKeys.all, 'detail'] as const,
|
||||
detail: (id: number) => [...userKeys.details(), id] as const,
|
||||
}
|
||||
|
||||
// ─── useUsers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useUsers(params: UsersListParams = {}) {
|
||||
return useQuery({
|
||||
queryKey: userKeys.list(params),
|
||||
queryFn: () => usersApi.getUsers(params),
|
||||
placeholderData: (prev) => prev,
|
||||
})
|
||||
}
|
||||
|
||||
// ─── useUser ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useUser(id: number) {
|
||||
return useQuery({
|
||||
queryKey: userKeys.detail(id),
|
||||
queryFn: () => usersApi.getUserById(id),
|
||||
enabled: !!id,
|
||||
})
|
||||
}
|
||||
|
||||
// ─── useCreateUser ────────────────────────────────────────────────────────────
|
||||
|
||||
export function useCreateUser() {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: CreateUserPayload) => usersApi.createUser(payload),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: userKeys.lists() })
|
||||
toast.success(t('users.toast.createSuccess', 'Ulanyjy üstünlikli döredildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('users.toast.createError', 'Ulanyjy döretmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// ─── useUpdateUser ────────────────────────────────────────────────────────────
|
||||
|
||||
export function useUpdateUser(id: number) {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: UpdateUserPayload) => usersApi.updateUser(id, payload),
|
||||
onSuccess: (updatedUser) => {
|
||||
queryClient.invalidateQueries({ queryKey: userKeys.lists() })
|
||||
queryClient.setQueryData(userKeys.detail(id), updatedUser)
|
||||
toast.success(t('users.toast.updateSuccess', 'Ulanyjy üstünlikli täzelendi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('users.toast.updateError', 'Ulanyjy täzelemek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// ─── useDeleteUser ────────────────────────────────────────────────────────────
|
||||
|
||||
export function useDeleteUser() {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (id: number) => usersApi.deleteUser(id),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: userKeys.lists() })
|
||||
toast.success(t('users.toast.deleteSuccess', 'Ulanyjy üstünlikli öçürildi'))
|
||||
},
|
||||
onError: () => {
|
||||
toast.error(t('users.toast.deleteError', 'Ulanyjy öçürmek başartmady'))
|
||||
},
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user