fix(employees): после create — invalidate list query (не показывался сразу)
Найдено через UI-deep: после успешного создания нового сотрудника
EmployeesPage не вызывал refetch/invalidate на list-query, и список
показывал старые данные до ручного refresh страницы. Причина:
direct api.post вместо useCatalogMutations.create (нужен custom response
shape с generatedPassword для one-shot модалки).
Фикс: await qc.invalidateQueries({queryKey:[URL]}) сразу после успеха.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
87e60e7309
commit
f36fb146b6
|
|
@ -1,5 +1,5 @@
|
|||
import { useEffect, useState } from 'react'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { validateEmail, validatePhone } from '@/lib/validation'
|
||||
import { Plus, Trash2, Copy } from 'lucide-react'
|
||||
import { api, humanizeError } from '@/lib/api'
|
||||
|
|
@ -82,6 +82,7 @@ const blankForm = (): Form => ({
|
|||
})
|
||||
|
||||
export function EmployeesPage() {
|
||||
const qc = useQueryClient()
|
||||
const { update, remove } = useCatalogMutations(URL, URL)
|
||||
const [form, setForm] = useState<Form | null>(null)
|
||||
// Сгенерированный пароль возвращается с сервера один раз — показываем
|
||||
|
|
@ -140,6 +141,9 @@ export function EmployeesPage() {
|
|||
} else {
|
||||
const res = await api.post<{ employee: EmployeeDto; generatedPassword: string | null }>(URL, payload)
|
||||
setForm(null); setActiveEmployee(null); setFieldErrors({})
|
||||
// Direct api.post — invalidate сам, useCatalogMutations.create мы тут
|
||||
// не используем (нужен custom response shape с generatedPassword).
|
||||
await qc.invalidateQueries({ queryKey: [URL] })
|
||||
// Если сервер вернул password — показываем модалку one-shot.
|
||||
if (res.data.generatedPassword && res.data.employee.email) {
|
||||
setCreatedAccount({ email: res.data.employee.email, password: res.data.generatedPassword })
|
||||
|
|
|
|||
Loading…
Reference in a new issue