All files / src/features/GiveOnboarding/hooks useIdentityOnlyMode.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 2/2
100% Lines 7/7

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                    9x                                 9x 128x   128x 41x 1x   40x        
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import {
  removeHiddenStepKeys,
  setHiddenStepKeys,
} from "@redux/slices/onboardingWizard";
import { IStep } from "@features/GiveOnboarding/types";
 
// Every onboarding step except the Identity sub-steps. PAH006 SS-4: an already
// approved merchant onboarding a reassigned PAH must only complete Identity.
const nonIdentitySteps: IStep[] = [
  "business_profile",
  "business_address",
  "business_owners",
  "business_details",
  "business_bank_connect",
  "business_bank_statement",
  "business_bank_confirm",
  "agreement_review",
  "agreement_sign",
];
 
/**
 * PAH006 SS-4 — toggles "Identity-only" onboarding. When enabled, hides all
 * non-identity steps so the wizard only surfaces the Identity flow; when
 * disabled, restores them. Driven by a BE flag at the call site.
 */
export const useIdentityOnlyMode = (isIdentityOnly: boolean) => {
  const dispatch = useDispatch();
 
  useEffect(() => {
    if (isIdentityOnly) {
      dispatch(setHiddenStepKeys(nonIdentitySteps));
    } else {
      dispatch(removeHiddenStepKeys(nonIdentitySteps));
    }
  }, [isIdentityOnly, dispatch]);
};