diff --git a/frontend/src/scenes/banner/BannerDefaultPage.jsx b/frontend/src/scenes/banner/BannerDefaultPage.jsx index f143dc85..9c11c738 100644 --- a/frontend/src/scenes/banner/BannerDefaultPage.jsx +++ b/frontend/src/scenes/banner/BannerDefaultPage.jsx @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import {useLocation} from "react-router-dom" import DefaultPageTemplate from '../../templates/DefaultPageTemplate/DefaultPageTemplate'; import { getBanners, deleteBanner } from '../../services/bannerServices'; import { ACTIVITY_TYPES_INFO } from '../../data/guideMainPageData'; @@ -8,6 +9,7 @@ const BannerDefaultPage = () => { const [itemsUpdated, setItemsUpdated] = useState(false); const [isEdit, setIsEdit] = useState(false); const [itemId, setItemId] = useState(null); + const locationData = useLocation() const getBannerDetails = (banner) => ({ title: `Banner ${banner.id}`, @@ -27,6 +29,7 @@ const BannerDefaultPage = () => { itemsUpdated={itemsUpdated} /> { +const BannerPage = ({ autoOpen = false, isEdit, itemId, setItemsUpdated }) => { const [backgroundColor, setBackgroundColor] = useState("#F9F5FF"); const [fontColor, setFontColor] = useState("#344054"); const [activeButton, setActiveButton] = useState(0); @@ -21,12 +21,17 @@ const BannerPage = ({isEdit, itemId, setItemsUpdated}) => { const [url, setUrl] = useState(""); const [actionUrl, setActionUrl] = useState(""); const [buttonAction, setButtonAction] = useState("No action"); - const { closeDialog } = useDialog(); + const { openDialog, closeDialog } = useDialog(); const handleButtonClick = (index) => { setActiveButton(index); }; + + useEffect(() => { + if (autoOpen) openDialog(); + }, [autoOpen, openDialog]); + useEffect(() => { if (isEdit) { const fetchBannerData = async () => { diff --git a/frontend/src/scenes/dashboard/Dashboard.jsx b/frontend/src/scenes/dashboard/Dashboard.jsx index 8debb3eb..88f4d497 100644 --- a/frontend/src/scenes/dashboard/Dashboard.jsx +++ b/frontend/src/scenes/dashboard/Dashboard.jsx @@ -55,17 +55,17 @@ const Dashboard = ({ name }) => { { skeletonType: , placeholder: "Create a popup", - onClick: () => navigate("/popup"), + onClick: () => navigate("/popup", { state: { autoOpen: true } }), }, { skeletonType: , placeholder: "Create a new banner", - onClick: () => navigate("/banner"), + onClick: () => navigate("/banner", { state: { autoOpen: true } }), }, { skeletonType: , placeholder: "Create a new helper link", - onClick: () => navigate("/hint"), + onClick: () => navigate("/hint", { state: { autoOpen: true } }), }, ]; diff --git a/frontend/src/scenes/hints/CreateHintPage.jsx b/frontend/src/scenes/hints/CreateHintPage.jsx index 11b8687c..18d20f7f 100644 --- a/frontend/src/scenes/hints/CreateHintPage.jsx +++ b/frontend/src/scenes/hints/CreateHintPage.jsx @@ -10,9 +10,8 @@ import toastEmitter, { TOAST_EMITTER_KEY } from "../../utils/toastEmitter"; import { emitToastError } from "../../utils/guideHelper"; import { useDialog } from "../../templates/GuideTemplate/GuideTemplateContext"; -const HintPage = ({ isEdit, itemId, setItemsUpdated }) => { - const { closeDialog } = useDialog(); - +const HintPage = ({ autoOpen = false, isEdit, itemId, setItemsUpdated }) => { + const { openDialog, closeDialog } = useDialog(); const [activeButton, setActiveButton] = useState(0); @@ -60,6 +59,10 @@ const HintPage = ({ isEdit, itemId, setItemsUpdated }) => { }, ]; + useEffect(() => { + if (autoOpen) openDialog(); + }, [autoOpen, openDialog]); + useEffect(() => { if (isEdit) { const fetchHintData = async () => { diff --git a/frontend/src/scenes/hints/HintDefaultPage.jsx b/frontend/src/scenes/hints/HintDefaultPage.jsx index 4fe562d9..851baae0 100644 --- a/frontend/src/scenes/hints/HintDefaultPage.jsx +++ b/frontend/src/scenes/hints/HintDefaultPage.jsx @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import {useLocation} from "react-router-dom" import DefaultPageTemplate from "../../templates/DefaultPageTemplate/DefaultPageTemplate"; import CreateHintPage from "./CreateHintPage"; import { ACTIVITY_TYPES_INFO } from "../../data/guideMainPageData"; @@ -8,6 +9,7 @@ const HintDefaultPage = () => { const [itemsUpdated, setItemsUpdated] = useState(false); const [isEdit, setIsEdit] = useState(false); const [itemId, setItemId] = useState(null); + const locationData = useLocation() const getHintDetails = (hint) => ({ title: `Hint ${hint.id}`, @@ -27,6 +29,7 @@ const HintDefaultPage = () => { itemsUpdated={itemsUpdated} /> { const [itemsUpdated, setItemsUpdated] = useState(false); const [isEdit, setIsEdit] = useState(false); const [itemId, setItemId] = useState(null); + const locationData = useLocation() const getPopupDetails = (popup) => ({ title: `Popup ${popup.id}`, @@ -28,6 +30,7 @@ const PopupDefaultPage = () => { itemsUpdated={itemsUpdated} /> null, }) => { const { isOpen, closeDialog } = useDialog(); + const location = useLocation(); + const navigate = useNavigate(); const buttons = ["Content", "Appearance"]; + const onCloseHandler = () => { + if (location.state?.autoOpen) navigate("/", { state: {} }); + + closeDialog(); + }; + return (
@@ -63,9 +72,7 @@ const GuideTemplate = ({