fix(templates): show clear message after auto-import instead of "undefined"
Some checks failed
Deploy to Production / Trigger production update (push) Has been cancelled
Some checks failed
Deploy to Production / Trigger production update (push) Has been cancelled
Frontend read res.count but the auto-import endpoint returns imported_count, so the toast showed "Импортировано: undefined". Read imported_count and show a distinct message when no new templates were imported. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -46,7 +46,12 @@ export default function TemplatesPage() {
|
||||
if (!importServerId) return;
|
||||
autoImport.mutate(Number(importServerId), {
|
||||
onSuccess: (res) => {
|
||||
toast.success(`${t('templates.imported')}: ${res.count}`);
|
||||
const count = res.imported_count ?? 0;
|
||||
toast.success(
|
||||
count > 0
|
||||
? t('templates.imported_count', { count })
|
||||
: t('templates.imported_none'),
|
||||
);
|
||||
setImportDialogOpen(false);
|
||||
},
|
||||
onError: (err: Error) => toast.error(err.message),
|
||||
|
||||
@@ -60,7 +60,7 @@ export function useDiscoverTemplates(serverId: number) {
|
||||
export function useAutoImportTemplates() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (serverId: number) => apiClient.post<{ success: boolean; count: number }>(`/templates/api/auto-import/${serverId}`),
|
||||
mutationFn: (serverId: number) => apiClient.post<{ success: boolean; imported_count: number }>(`/templates/api/auto-import/${serverId}`),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: templateKeys.groups });
|
||||
qc.invalidateQueries({ queryKey: ['templates'] });
|
||||
|
||||
@@ -1007,6 +1007,8 @@
|
||||
"os": "Operating System",
|
||||
"version": "Version",
|
||||
"imported": "Imported",
|
||||
"imported_count": "Templates imported: {{count}}",
|
||||
"imported_none": "No new templates found to import",
|
||||
"select_server": "Select server",
|
||||
"import_btn": "Import Templates",
|
||||
"group": "Group",
|
||||
|
||||
@@ -1007,6 +1007,8 @@
|
||||
"os": "Операционная система",
|
||||
"version": "Версия",
|
||||
"imported": "Импортировано",
|
||||
"imported_count": "Импортировано шаблонов: {{count}}",
|
||||
"imported_none": "Новых шаблонов для импорта не найдено",
|
||||
"select_server": "Выберите сервер",
|
||||
"import_btn": "Импортировать шаблоны",
|
||||
"group": "Группа",
|
||||
|
||||
Reference in New Issue
Block a user