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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | 22x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 81x 55x 26x 26x 26x 81x 81x 140x 140x 81x | import { palette } from "@palette";
import { IParsedData } from "../../../../../components/Merchants/MerchantPreview/data.types";
import { BusinessProfileStatusType } from "@common/Tag/BusinessProfileTag";
import { isEmpty } from "lodash";
import { useEnterprisePermissions } from "@components/AcquirerEnterprises/CreateEnterprise/hooks/useEnterprisePermissions";
import { OFAC_STATUS } from "@constants/constants";
type StatusObject = { text: string; color: string; backgroundColor: string };
type StatusType = Extract<
BusinessProfileStatusType,
"declined" | "suspended" | "pending" | "approved"
>;
export type ActionType =
| Extract<BusinessProfileStatusType, "declined" | "suspended" | "approved">
| "move_back_to_pending";
export const useBusinessProfileActions = (data: IParsedData) => {
const status = data?.businessProfile.statusName;
const {
statusName,
declinedAt,
suspendedAt,
declinedByName,
suspendedByName,
approvedAt,
approvedByName,
movedPendingAt,
movedPendingByName,
reason,
ofac,
} = data.businessProfile;
const { merchant_underwriting } = useEnterprisePermissions();
//in mobile view show tooltip with message instead of info message for approved and pending status
const isPending =
status === "pending" ||
status === "pending_review" ||
status === "pending_review_issue";
const isApproved = status === "approved";
const isDeclined = status === "declined";
const isSuspended = status === "suspended";
const isReadyForVerification = status === "ready_for_verification";
const isOFACConfirmedMatch =
ofac?.lastCheckStatusName === OFAC_STATUS.CONFIRMED_MATCH;
const showToolTip =
(isApproved && !isEmpty(approvedAt) && !isEmpty(approvedByName)) ||
(status === "pending" && isEmpty(movedPendingAt));
const getMessageMetaData = () => {
if (
statusName === "pending_review" ||
statusName === "ready_for_verification" ||
statusName === "move_back_to_pending" ||
statusName === "declined_by_msp" ||
statusName === "pending_review_issue" ||
statusName === "In progress" ||
statusName === "Delivered" ||
statusName === "Undeliverable"
)
return;
const sanitizedReason = reason ? `, reason: "${reason}"` : "";
const BusinessProfileMessage: Record<StatusType, StatusObject> = {
pending: {
text:
movedPendingAt && movedPendingByName
? `Moved to pending on ${movedPendingAt} by ${movedPendingByName}${sanitizedReason}`
: "Merchants need to provide all the information to be ready for verification",
color: palette.warning["text"],
backgroundColor: palette.tag.warning["bg"],
},
approved: {
text:
approvedAt && approvedByName
? `Approved on ${approvedAt} by ${approvedByName}`
: "",
color: palette.warning["text"],
backgroundColor: palette.tag.warning["bg"],
},
declined: {
text:
declinedAt && declinedByName
? `Declined on ${declinedAt} by ${declinedByName}${sanitizedReason}`
: "",
color: palette.tag.error["text"],
backgroundColor: palette.tag.error["bg"],
},
suspended: {
text:
suspendedAt && suspendedByName
? `Suspended on ${suspendedAt} ${
!isOFACConfirmedMatch
? `by ${suspendedByName}`
: "due to OFAC confirmed match"
}${sanitizedReason}`
: "",
color: palette.warning["text"],
backgroundColor: palette.tag.warning["bg"],
},
};
return BusinessProfileMessage[statusName];
};
const message = getMessageMetaData();
const isHidden = ({ actionItem }: { actionItem: ActionType }) => {
const checkIsHidden: Record<ActionType, boolean> = {
move_back_to_pending: isPending || isApproved || isSuspended,
approved: isApproved || isDeclined,
declined: isDeclined || isApproved || isSuspended,
suspended:
isPending || isDeclined || isSuspended || isReadyForVerification,
};
return checkIsHidden[actionItem] || !merchant_underwriting;
};
return { message, showToolTip, isHidden, isPending };
};
|