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:
parent
4836dd0436
commit
27359bd45f
|
|
@ -0,0 +1 @@
|
||||||
|
export * from './use-toast';
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
import { useToast as useToastChakra } from '@chakra-ui/react';
|
||||||
|
|
||||||
|
export const useToast = () => {
|
||||||
|
return useToastChakra({
|
||||||
|
duration: 3000,
|
||||||
|
isClosable: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -8,8 +8,6 @@ import {
|
||||||
Button,
|
Button,
|
||||||
FormErrorMessage,
|
FormErrorMessage,
|
||||||
IconButton,
|
IconButton,
|
||||||
useToast,
|
|
||||||
UseToastOptions,
|
|
||||||
Textarea,
|
Textarea,
|
||||||
Grid,
|
Grid,
|
||||||
GridItem,
|
GridItem,
|
||||||
|
|
@ -21,6 +19,7 @@ import { mintSiteNFT } from '@/mocks';
|
||||||
import { getRepoAndCommit } from '@/utils';
|
import { getRepoAndCommit } from '@/utils';
|
||||||
import { validateFields } from './mint-site.utils';
|
import { validateFields } from './mint-site.utils';
|
||||||
import { InputFieldForm } from '@/components';
|
import { InputFieldForm } from '@/components';
|
||||||
|
import { useToast } from '@/hooks';
|
||||||
|
|
||||||
interface FormValues {
|
interface FormValues {
|
||||||
name: string;
|
name: string;
|
||||||
|
|
@ -43,22 +42,7 @@ const initialValues = {
|
||||||
} as FormValues;
|
} as FormValues;
|
||||||
|
|
||||||
export const MintSite = () => {
|
export const MintSite = () => {
|
||||||
const toast = useToast();
|
const setToastInfo = 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 handleSubmitForm = useCallback(async (values: FormValues) => {
|
const handleSubmitForm = useCallback(async (values: FormValues) => {
|
||||||
const {
|
const {
|
||||||
|
|
@ -85,13 +69,18 @@ export const MintSite = () => {
|
||||||
repo,
|
repo,
|
||||||
});
|
});
|
||||||
//TODO connect with the integration
|
//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) {
|
} catch (err) {
|
||||||
showToast(
|
setToastInfo({
|
||||||
'Error!',
|
title: 'Error!',
|
||||||
'We had an error while minting your site. Please try again later',
|
description:
|
||||||
'error'
|
'We had an error while minting your site. Please try again later',
|
||||||
);
|
status: 'error',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue