From 25ac18acd30af9ab0a7de733b348eefe646ae4bb Mon Sep 17 00:00:00 2001 From: "Kalle (Sendou)" <38327916+Sendouc@users.noreply.github.com> Date: Thu, 22 Oct 2020 13:56:38 +0300 Subject: [PATCH] get default mock options from a func --- lib/getToastOptions.ts | 12 ++++++++++++ scenes/Profile/components/ProfileModal.tsx | 17 +++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 lib/getToastOptions.ts 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")); }, });