get default mock options from a func

This commit is contained in:
Kalle (Sendou)
2020-10-22 13:56:38 +03:00
parent ad116e96df
commit 25ac18acd3
2 changed files with 15 additions and 14 deletions

12
lib/getToastOptions.ts Normal file
View File

@@ -0,0 +1,12 @@
import { UseToastOptions } from "@chakra-ui/core";
export const getToastOptions = (
description: NonNullable<UseToastOptions["description"]>,
status: NonNullable<UseToastOptions["status"]>
): UseToastOptions => ({
description,
status,
duration: 9000,
isClosable: true,
position: "top-right",
});

View File

@@ -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<Props> = ({
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"));
},
});