fix(app/edge-stack): UI notification on creation error (#325)

pull/11389/merge
LP B 2025-01-17 20:33:01 +01:00 committed by GitHub
parent 154ca9f1b1
commit cab667c23b
2 changed files with 20 additions and 8 deletions

View File

@ -10,8 +10,13 @@ import {
import { notifyError } from '@/portainer/services/notifications';
/**
* @deprecated use withGlobalError
* `onError` and other callbacks are not supported on react-query v5
* @deprecated for `useQuery` ONLY. Use `withGlobalError`.
*
* `onError` and other callbacks are not supported on `useQuery` in react-query v5
*
* Using `withError` is fine for mutations (`useMutation`)
*
* see https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose
*/
export function withError(fallbackMessage?: string, title = 'Failure') {
return {

View File

@ -6,6 +6,7 @@ import { TemplateViewModel } from '@/react/portainer/templates/app-templates/vie
import { CustomTemplate } from '@/react/portainer/templates/custom-templates/types';
import { notifySuccess } from '@/portainer/services/notifications';
import { transformAutoUpdateViewModel } from '@/react/portainer/gitops/AutoUpdateFieldset/utils';
import { mutationOptions, withError } from '@/react-tools/react-query';
import {
BasePayload,
@ -49,12 +50,18 @@ export function useCreate({
),
});
mutation.mutate(getPayload(method, values), {
onSuccess: () => {
notifySuccess('Success', 'Edge stack created');
router.stateService.go('^');
},
});
mutation.mutate(
getPayload(method, values),
mutationOptions(
{
onSuccess: () => {
notifySuccess('Success', 'Edge stack created');
router.stateService.go('^');
},
},
withError('unable to create edge stack')
)
);
function getPayload(
method: 'string' | 'file' | 'git',