useRemoveSuccessfulChannelOrder.ts raw
1 import React from "react";
2 import { useLocation } from "react-router";
3 import useChannelOrderStore from "src/state/ChannelOrderStore";
4
5 export function useRemoveSuccessfulChannelOrder() {
6 const location = useLocation();
7 const [prevLocation, setPrevLocation] = React.useState(location.pathname);
8
9 React.useEffect(() => {
10 if (
11 location.pathname != "/channels/order" &&
12 prevLocation === "/channels/order" &&
13 useChannelOrderStore.getState().order?.status === "success"
14 ) {
15 useChannelOrderStore.getState().removeOrder();
16 }
17 setPrevLocation(location.pathname);
18 }, [location.pathname, prevLocation]);
19 }
20