All files / src/features/Merchants/MerchantSidePanel/UnderwritingTasks/hooks useAdjustAddressType.tsx

100% Statements 8/8
85.71% Branches 24/28
100% Functions 2/2
100% Lines 8/8

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      8x 9x   1x   1x             1x 1x   1x                               9x    
import { TBusinessOwner } from "@components/Merchants/MerchantPreview/data.types";
import { formatInUTCMoment } from "@utils/date.helpers";
 
export const useAdjustAddressType = () => {
  const adjustAddressType = (owner: TBusinessOwner) => {
    const { id, dob, businessAddress, address, isBusinessAddress, ownership } =
      owner;
 
    const customAddress = {
      city: address?.city || businessAddress?.city,
      country: address?.country || businessAddress?.country,
      street: address?.line1 || businessAddress?.line1,
      zip: address?.zip || businessAddress?.zip,
      province: address?.state || businessAddress?.state,
    };
    const { city, country, street, zip, province } = customAddress;
    const dateOfBirth = typeof dob === "string" ? dob : formatInUTCMoment(dob);
 
    return {
      ...owner,
      id: parseInt(id),
      dob: dob ? dateOfBirth : null,
      businessAddress: {
        city: city || "",
        country: country || "US",
        street: street || "",
        zip: zip || "",
        province: province || "",
      },
      useBusinessAddress: isBusinessAddress || false,
      ownership: ownership || "0",
    };
  };
 
  return { adjustAddressType };
};