added error handling, fixed authenticaton, added toaster
This commit is contained in:
parent
40c35bda13
commit
b6b7cea210
18 changed files with 1327 additions and 68 deletions
0
app/client/hooks/useIdentity.tsx
Normal file
0
app/client/hooks/useIdentity.tsx
Normal file
38
app/client/hooks/useToastMutation.tsx
Normal file
38
app/client/hooks/useToastMutation.tsx
Normal 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
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue