All files / src/sections/PayBuilder/hooks useOpenCampaignPanel.ts

55.55% Statements 5/9
0% Branches 0/5
50% Functions 1/2
55.55% Lines 5/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26        46x 1800x 1800x 1800x                           1800x        
import useRedirect from "@hooks/common/router/useRedirect";
import { CAMPAIGN_DETAILS_MODAL } from "modals/modal_names";
import { useLocation } from "react-router-dom";
 
const useOpenCampaignPanel = () => {
  const { redirectToModal } = useRedirect();
  const location = useLocation();
  const openCampaignPanel = (id: any, isPublishedForm?: boolean) => {
    const prevPath = location.state?.prevUrl;
 
    const isDetailsPage = prevPath?.includes(id);
 
    // we dont show the panel if its still draft
    if (id && isPublishedForm && !isDetailsPage) {
      redirectToModal(CAMPAIGN_DETAILS_MODAL, {
        id,
        isFirst: true,
        isLast: true,
      });
    }
  };
  return { openCampaignPanel };
};
 
export default useOpenCampaignPanel;