@arkyn/components 1.3.10 → 1.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,15 +2,28 @@ import { useActionData } from "@remix-run/react";
2
2
  import { useContext, useEffect } from "react";
3
3
 
4
4
  import { ModalContext } from "../context/ModalContext";
5
+ import { useToast } from "./useToast";
5
6
 
6
7
  function useAutomation() {
7
8
  const actionData = useActionData<any>();
8
9
  const { closeModal } = useContext(ModalContext);
10
+ const { successToast, errorToast } = useToast();
9
11
 
10
12
  useEffect(() => {
11
13
  const closeModalKey = actionData?.closeModalKey;
12
14
  if (closeModalKey) closeModal(closeModalKey);
13
15
  }, [actionData]);
16
+
17
+ useEffect(() => {
18
+ const showToast =
19
+ typeof actionData?.message === "string" &&
20
+ typeof actionData?.success === "boolean";
21
+
22
+ if (showToast) {
23
+ if (actionData?.success) successToast(actionData?.message);
24
+ else errorToast(actionData?.message);
25
+ }
26
+ }, [actionData]);
14
27
  }
15
28
 
16
29
  export { useAutomation };