Untitled

mail@pastecode.io avatar
unknown
tsx
a year ago
1.1 kB
3
Indexable
Never
 const [activedTypeId, setActivedTypeId] = useState<0 | 1 | 2 | 3>(0);
  const router = useRouter();
  useEffect(() => {
    if (router.isReady) {
      router.query['typeId'] === '2'
        ? setActivedTypeId(2)
        : router.query['typeId'] === '3'
        ? setActivedTypeId(3)
        : setActivedTypeId(1);
    }
  }, [router]);



async function fetcherFetchSellRecordOrders() {
    try {
      const data = await APIfetchSellRecordOrders({
        type: activedTypeId,
        token: localStorageUserAuthData!.token,
        phoneNumber: localStorageUserAuthData!.loginid,
      });
      return data;
    } catch (error: any) {
      if (!error.response) {
        toast(TOASTMSG.routes.global.pleaseCheckNetworkConnection);
      } else {
        toast(TOASTMSG.routes.global.sorryUnexpectedError);
      }
    }
    return null;
  }



  const { data: sellRecordOrdersData } = useSWR<SellRecordOrderType[] | null>(
    activedTypeId !== 0 ? `sellRecordOrdersForType${activedTypeId}` : null,
    fetcherFetchSellRecordOrders,
  );