All files / src/hooks/enterprise-api/merchants useListBusinessProfiles.tsx

0% Statements 0/13
0% Branches 0/8
0% Functions 0/5
0% Lines 0/13

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 36 37 38 39 40 41 42                                                                                   
import { useAppSelector } from "@redux/hooks";
import { selectSelectedAccount } from "@redux/slices/auth/accounts";
import { getLegalEntities } from "@services/api/businessProfile";
import { useQuery } from "react-query";
 
const useListBusinessProfiles = () => {
  const { data, isLoading } = useQuery(
    "list-all-business-profiles",
    async () =>
      await getLegalEntities(undefined, {
        filter: `allowMultipleMerchants:true`,
      }),
  );
 
  return { data: data?.data || [], isLoading };
};
 
export const useListApprovedBusinessProfiles = () => {
  const selectedUser = useAppSelector(selectSelectedAccount);
  const merchantId = selectedUser?.id ? selectedUser?.id : undefined;
 
  const { data, isLoading } = useQuery(
    "list-approved-business-profiles",
    async () => {
      const profiles = await getLegalEntities(merchantId, {
        filter: `statusName:"approved"%3BallowMultipleMerchants:true&max=1000`,
      });
 
      const profilesCache: { [key: number]: any } = (
        (profiles?.data as any[]) || []
      ).reduce((obj, item) => Object.assign(obj, { [item.id]: item }), {});
 
      return Object.values(profilesCache);
    },
    { refetchOnWindowFocus: false },
  );
 
  return { data: data || [], isLoading };
};
 
export default useListBusinessProfiles;