All files / src/features/GiveOnboarding/container DrawerAccount.tsx

72.72% Statements 8/11
0% Branches 0/2
50% Functions 2/4
80% Lines 8/10

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 43 44 45 46 47 48 49 50          10x                     94x 94x   94x   94x       94x 88x                               94x              
import { useRef, useState, useCallback } from "react";
 
import DrawerAccountSelect from "@features/Drawer/DrawerAccountSelect";
import { TParsedAccount } from "@pages/Login/modals/hooks/useAccountSelectionModal";
 
export const useDrawerAccountWithUI = ({
  baseRender,
  onChooseAccount,
  hideAvatar,
  CustomButton,
}: {
  baseRender?: () => React.ReactNode;
  onChooseAccount?: (cb: () => void) => void;
  hideAvatar?: boolean;
  CustomButton?: (props: { onClick: any }) => JSX.Element;
}) => {
  const accountSelectorRef = useRef<HTMLDivElement>(null);
  const [hasManyAccounts, setHasManyAccounts] = useState(false);
 
  const isManyAccounts = Boolean(accountSelectorRef.current);
 
  const handleSuccess = (res: TParsedAccount[]) => {
    if (res.length > 1) setHasManyAccounts(true);
  };
 
  const UI = useCallback(() => {
    return (
      <DrawerAccountSelect
        drawerOpen
        accountSelectorRef={accountSelectorRef}
        baseRender={baseRender}
        onChooseAccount={onChooseAccount}
        handleDrawerOpen={() => {
          return;
        }}
        onSuccessFecth={handleSuccess}
        hideAvatar={hideAvatar}
        CustomButton={CustomButton}
      />
    );
  }, []);
 
  return {
    DrawerAccountComponent: UI,
    accountSelectorRef,
    isManyAccounts,
    hasManyAccounts,
  };
};