added confirm dialog, some translations
This commit is contained in:
@@ -8,8 +8,6 @@ import {
|
||||
type UsersListParams,
|
||||
} from '../api/allUsersApi'
|
||||
|
||||
// ─── Query Keys ───────────────────────────────────────────────────────────────
|
||||
|
||||
export const userKeys = {
|
||||
all: ['users'] as const,
|
||||
lists: () => [...userKeys.all, 'list'] as const,
|
||||
@@ -18,8 +16,6 @@ export const userKeys = {
|
||||
detail: (id: number) => [...userKeys.details(), id] as const,
|
||||
}
|
||||
|
||||
// ─── useUsers ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useUsers(params: UsersListParams = {}) {
|
||||
return useQuery({
|
||||
queryKey: userKeys.list(params),
|
||||
@@ -28,8 +24,6 @@ export function useUsers(params: UsersListParams = {}) {
|
||||
})
|
||||
}
|
||||
|
||||
// ─── useUser ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export function useUser(id: number) {
|
||||
return useQuery({
|
||||
queryKey: userKeys.detail(id),
|
||||
@@ -38,8 +32,6 @@ export function useUser(id: number) {
|
||||
})
|
||||
}
|
||||
|
||||
// ─── useCreateUser ────────────────────────────────────────────────────────────
|
||||
|
||||
export function useCreateUser() {
|
||||
const { t } = useTranslation()
|
||||
const queryClient = useQueryClient()
|
||||
@@ -50,14 +42,9 @@ export function useCreateUser() {
|
||||
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()
|
||||
@@ -69,14 +56,9 @@ export function useUpdateUser(id: number) {
|
||||
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()
|
||||
@@ -87,8 +69,5 @@ export function useDeleteUser() {
|
||||
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'))
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
import { z } from 'zod'
|
||||
import i18next from 'i18next'
|
||||
import type { CreateUserPayload } from '../api/allUsersApi'
|
||||
|
||||
const t = i18next.t.bind(i18next)
|
||||
|
||||
const baseSchema = z.object({
|
||||
username: z.string()
|
||||
.min(1, 'Ulanyjy ady hökmany')
|
||||
.min(3, 'Ulanyjy ady iň az 3 harp bolmaly'),
|
||||
name: z.string().min(1, 'Ady hökmany'),
|
||||
.min(1, t('validation.required', 'Ulanyjy ady hökmany'))
|
||||
.min(3, t('validation.minLength', 'Ulanyjy ady iň az 3 harp bolmaly')),
|
||||
name: z.string().min(1, t('validation.required', 'Ady hökmany')),
|
||||
phone: z.string()
|
||||
.min(1, 'Telefon hökmany')
|
||||
.regex(/^\d[\d\s-]{6,}$/, 'Nädogry telefon formaty'),
|
||||
.min(1, t('validation.required', 'Telefon hökmany'))
|
||||
.regex(/^\d[\d\s-]{6,}$/, t('validation.invalidPhone', 'Nädogry telefon formaty')),
|
||||
email: z.string()
|
||||
.refine(
|
||||
(v) => !v || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(v),
|
||||
'Nädogry e-poçta formaty',
|
||||
t('validation.invalidEmail', 'Nädogry e-poçta formaty'),
|
||||
)
|
||||
.default(''),
|
||||
password: z.string(),
|
||||
@@ -24,8 +27,8 @@ export function allUserFormSchema(mode: 'create' | 'edit') {
|
||||
return mode === 'create'
|
||||
? baseSchema.extend({
|
||||
password: z.string()
|
||||
.min(1, 'Açar sözi hökmany')
|
||||
.min(6, 'Açar sözi iň az 6 harp bolmaly'),
|
||||
.min(1, t('validation.required', 'Açar sözi hökmany'))
|
||||
.min(6, t('validation.minLength', 'Açar sözi iň az 6 harp bolmaly')),
|
||||
})
|
||||
: baseSchema
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user