added error handling, fixed authenticaton, added toaster

This commit is contained in:
lnn0q 2025-03-30 17:31:12 +03:00
parent 40c35bda13
commit b6b7cea210
18 changed files with 1327 additions and 68 deletions

View file

@ -0,0 +1,38 @@
import {
ApolloCache,
DefaultContext,
DocumentNode,
FetchResult,
MaybeMasked,
MutationFunctionOptions,
OperationVariables,
useMutation
} from '@apollo/client';
import { toaster } from '../components/ui/toaster';
interface UseToastMutationProps {
mutation: DocumentNode;
successMsg?: string;
}
interface UseToastMutationReturn<T> {
update: (
options?:
| MutationFunctionOptions<T, OperationVariables, DefaultContext, ApolloCache<any>>
| undefined
) => Promise<FetchResult<MaybeMasked<T>>>;
}
export function useToastMutation<T>(props: UseToastMutationProps): UseToastMutationReturn<T> {
const [update] = useMutation<T>(props.mutation, {
onCompleted: () => toaster.create({ description: props.successMsg, type: 'success' }),
onError: error => {
toaster.create({ description: `${error.message}`, type: 'error' });
console.error(error);
}
});
return {
update
};
}