feat: add toast hook (#44)

* feat: add toast hook

* refactor: changes on useToast based on PR comments

* reactor: refactor on useToast
This commit is contained in:
Camila Sosa Morales 2022-12-16 16:51:35 -03:00 committed by GitHub
parent 4836dd0436
commit 27359bd45f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 24 deletions

1
ui/src/hooks/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './use-toast';

View File

@ -0,0 +1,9 @@
import { useToast as useToastChakra } from '@chakra-ui/react';
export const useToast = () => {
return useToastChakra({
duration: 3000,
isClosable: true,
});
};

View File

@ -8,8 +8,6 @@ import {
Button,
FormErrorMessage,
IconButton,
useToast,
UseToastOptions,
Textarea,
Grid,
GridItem,
@ -21,6 +19,7 @@ import { mintSiteNFT } from '@/mocks';
import { getRepoAndCommit } from '@/utils';
import { validateFields } from './mint-site.utils';
import { InputFieldForm } from '@/components';
import { useToast } from '@/hooks';
interface FormValues {
name: string;
@ -43,22 +42,7 @@ const initialValues = {
} as FormValues;
export const MintSite = () => {
const toast = useToast();
//TODO add hook to show the toast
const showToast = (
title: string,
description: string,
status: UseToastOptions['status']
) => {
toast({
title,
description,
status,
duration: 3000,
isClosable: true,
});
};
const setToastInfo = useToast();
const handleSubmitForm = useCallback(async (values: FormValues) => {
const {
@ -85,13 +69,18 @@ export const MintSite = () => {
repo,
});
//TODO connect with the integration
showToast('Success!', 'Your site has been minted.', 'success');
setToastInfo({
title: 'Success!',
description: 'Your site has been minted.',
status: 'success',
});
} catch (err) {
showToast(
'Error!',
'We had an error while minting your site. Please try again later',
'error'
);
setToastInfo({
title: 'Error!',
description:
'We had an error while minting your site. Please try again later',
status: 'error',
});
}
}, []);