@arkyn/components 1.3.129 → 1.3.130

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"AAqBA,iBAAS,aAAa,SA8BrB;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"useAutomation.d.ts","sourceRoot":"","sources":["../../src/hooks/useAutomation.ts"],"names":[],"mappings":"AAsBA,iBAAS,aAAa,SA2CrB;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -1,7 +1,8 @@
1
- import { useActionData } from "@remix-run/react";
1
+ import { useActionData, useLocation, useNavigate } from "@remix-run/react";
2
2
  import { useContext, useEffect } from "react";
3
3
  import { animateScroll } from "react-scroll";
4
4
  import { ModalContext } from "../context/ModalContext";
5
+ import { useScopedParams } from "./useScopedParams";
5
6
  import { useToast } from "./useToast";
6
7
  function isToastProps(obj) {
7
8
  return (obj &&
@@ -15,8 +16,18 @@ function isToastProps(obj) {
15
16
  }
16
17
  function useAutomation() {
17
18
  const actionData = useActionData();
18
- const { closeModal } = useContext(ModalContext);
19
+ const { closeModal, closeAll } = useContext(ModalContext);
19
20
  const { showToast } = useToast();
21
+ const { getParam } = useScopedParams();
22
+ const { pathname } = useLocation();
23
+ const navigate = useNavigate();
24
+ const closeAllModals = getParam("closeAllModals");
25
+ useEffect(() => {
26
+ if (closeAllModals === "true") {
27
+ closeAll();
28
+ navigate(pathname);
29
+ }
30
+ }, [closeAllModals]);
20
31
  useEffect(() => {
21
32
  const closeModalKey = actionData?.closeModalKey;
22
33
  if (closeModalKey)
@@ -1 +1 @@
1
- {"version":3,"file":"ModalProvider.d.ts","sourceRoot":"","sources":["../../src/provider/ModalProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,cAAc,CAAC;AAKhE,iBAAS,aAAa,CAAC,IAAI,EAAE,kBAAkB,2CAiC9C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
1
+ {"version":3,"file":"ModalProvider.d.ts","sourceRoot":"","sources":["../../src/provider/ModalProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,cAAc,CAAC;AAKhE,iBAAS,aAAa,CAAC,IAAI,EAAE,kBAAkB,2CAqC9C;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -24,6 +24,9 @@ function ModalProvider(args) {
24
24
  function closeModal(key) {
25
25
  setOpenedModals(openedModals.filter((modal) => modal.key !== key));
26
26
  }
27
- return (_jsx(ModalContext.Provider, { value: { modalIsOpen, modalData, openModal, closeModal }, children: children }));
27
+ function closeAll() {
28
+ setOpenedModals([]);
29
+ }
30
+ return (_jsx(ModalContext.Provider, { value: { modalIsOpen, modalData, openModal, closeModal, closeAll }, children: children }));
28
31
  }
29
32
  export { ModalProvider };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkyn/components",
3
- "version": "1.3.129",
3
+ "version": "1.3.130",
4
4
  "main": "./dist/bundle.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Lucas Gonçalves",
@@ -1,9 +1,10 @@
1
1
  import { ToastProps } from "@arkyn/types";
2
- import { useActionData } from "@remix-run/react";
2
+ import { useActionData, useLocation, useNavigate } from "@remix-run/react";
3
3
  import { useContext, useEffect } from "react";
4
4
  import { animateScroll } from "react-scroll";
5
5
 
6
6
  import { ModalContext } from "../context/ModalContext";
7
+ import { useScopedParams } from "./useScopedParams";
7
8
  import { useToast } from "./useToast";
8
9
 
9
10
  function isToastProps(obj: any): obj is ToastProps {
@@ -21,9 +22,22 @@ function isToastProps(obj: any): obj is ToastProps {
21
22
 
22
23
  function useAutomation() {
23
24
  const actionData = useActionData<any>();
24
- const { closeModal } = useContext(ModalContext);
25
+ const { closeModal, closeAll } = useContext(ModalContext);
25
26
  const { showToast } = useToast();
26
27
 
28
+ const { getParam } = useScopedParams();
29
+ const { pathname } = useLocation();
30
+ const navigate = useNavigate();
31
+
32
+ const closeAllModals = getParam("closeAllModals");
33
+
34
+ useEffect(() => {
35
+ if (closeAllModals === "true") {
36
+ closeAll();
37
+ navigate(pathname);
38
+ }
39
+ }, [closeAllModals]);
40
+
27
41
  useEffect(() => {
28
42
  const closeModalKey = actionData?.closeModalKey;
29
43
  if (closeModalKey) closeModal(closeModalKey);
@@ -29,9 +29,13 @@ function ModalProvider(args: ModalProviderProps) {
29
29
  setOpenedModals(openedModals.filter((modal) => modal.key !== key));
30
30
  }
31
31
 
32
+ function closeAll() {
33
+ setOpenedModals([]);
34
+ }
35
+
32
36
  return (
33
37
  <ModalContext.Provider
34
- value={{ modalIsOpen, modalData, openModal, closeModal }}
38
+ value={{ modalIsOpen, modalData, openModal, closeModal, closeAll }}
35
39
  >
36
40
  {children}
37
41
  </ModalContext.Provider>