diff --git a/lib/getToastOptions.ts b/lib/getToastOptions.ts new file mode 100644 index 000000000..0896701eb --- /dev/null +++ b/lib/getToastOptions.ts @@ -0,0 +1,12 @@ +import { UseToastOptions } from "@chakra-ui/core"; + +export const getToastOptions = ( + description: NonNullable, + status: NonNullable +): UseToastOptions => ({ + description, + status, + duration: 9000, + isClosable: true, + position: "top-right", +}); diff --git a/scenes/Profile/components/ProfileModal.tsx b/scenes/Profile/components/ProfileModal.tsx index 8eaf70764..72485cf01 100644 --- a/scenes/Profile/components/ProfileModal.tsx +++ b/scenes/Profile/components/ProfileModal.tsx @@ -22,6 +22,7 @@ import { UpdateUserProfileInput, useUpdateUserProfileMutation, } from "generated/graphql"; +import { getToastOptions } from "lib/getToastOptions"; import { useTranslation } from "lib/useMockT"; import { useForm } from "react-hook-form"; import { FaTwitch, FaTwitter, FaYoutube } from "react-icons/fa"; @@ -50,23 +51,11 @@ const ProfileModal: React.FC = ({ const toast = useToast(); const [updateUserProfile] = useUpdateUserProfileMutation({ onCompleted: () => { - toast({ - description: t("users;Profile updated"), - status: "success", - duration: 9000, - isClosable: true, - position: "top-right", - }); + toast(getToastOptions(t("users;Profile updated"), "success")); onClose(); }, onError: (error) => { - toast({ - description: error.message, - status: "error", - duration: 9000, - isClosable: true, - position: "top-right", - }); + toast(getToastOptions(error.message, "error")); }, });