All files / src/sections/PayBuilder ProductWrapper.tsx

0% Statements 0/16
0% Branches 0/6
0% Functions 0/3
0% Lines 0/15

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 27 28 29 30 31 32 33 34 35                                                                     
import LoadingSpinner from "@components/Snipper/LoadingSpinner";
import { useGetPublicForm } from "./components/hooks/useGetPublicForm";
import PayBuilder from "./PayBuilder";
import { useEffect } from "react";
import { useLocation, useNavigate, useParams } from "react-router-dom";
 
const PublicProductWrapper = () => {
  const { id } = useParams();
  const navigate = useNavigate();
  const { isFetched } = useGetPublicForm();
  const { search: queryParams } = useLocation();
  const { pathname } = useLocation();
 
  useEffect(() => {
    // TODO: Remove this once we have app-wide solution
    // In case user navigates to /:id/ we should remove extra "/"
    if (pathname.endsWith("/")) {
      const correctPath = pathname.replace(/\/+$/, "");
      navigate(correctPath, { replace: true });
    }
  }, [pathname]);
 
  useEffect(() => {
    if (isNaN(Number(id))) {
      navigate(`/${queryParams}`);
    }
  }, []);
 
  if (!isFetched) return <LoadingSpinner />;
 
  return <PayBuilder />;
};
 
export default PublicProductWrapper;