From cbf0885e126eb18a6b64f05d58c7c3d2261b5589 Mon Sep 17 00:00:00 2001 From: truph01 Date: Tue, 22 Oct 2024 15:44:15 +0700 Subject: [PATCH] fix: hide Add shipping details if deactivated --- .../ReportActionItem/IssueCardMessage.tsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/components/ReportActionItem/IssueCardMessage.tsx b/src/components/ReportActionItem/IssueCardMessage.tsx index c9fa9a6f2df0..17b445a052c7 100644 --- a/src/components/ReportActionItem/IssueCardMessage.tsx +++ b/src/components/ReportActionItem/IssueCardMessage.tsx @@ -6,6 +6,7 @@ import RenderHTML from '@components/RenderHTML'; import useLocalize from '@hooks/useLocalize'; import useThemeStyles from '@hooks/useThemeStyles'; import Navigation from '@libs/Navigation/Navigation'; +import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; @@ -24,6 +25,9 @@ function IssueCardMessage({action, policyID}: IssueCardMessageProps) { const styles = useThemeStyles(); const [privatePersonalDetails] = useOnyx(ONYXKEYS.PRIVATE_PERSONAL_DETAILS); const [session] = useOnyx(ONYXKEYS.SESSION); + const workspaceAccountID = PolicyUtils.getWorkspaceAccountID(policyID ?? '-1'); + const [cardList = {}] = useOnyx(ONYXKEYS.CARD_LIST); + const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); const assigneeAccountID = (ReportActionsUtils.getOriginalMessage(action) as IssueNewCardOriginalMessage)?.assigneeAccountID; @@ -37,7 +41,18 @@ function IssueCardMessage({action, policyID}: IssueCardMessageProps) { const isAssigneeCurrentUser = !isEmptyObject(session) && session.accountID === assigneeAccountID; - const shouldShowAddMissingDetailsButton = action?.actionName === CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS && missingDetails && isAssigneeCurrentUser; + const cardIssuedActionOriginalMessage = ReportActionsUtils.isActionOfType( + action, + CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED, + CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL, + CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS, + ) + ? ReportActionsUtils.getOriginalMessage(action) + : undefined; + const cardID = cardIssuedActionOriginalMessage?.cardID ?? -1; + const isPolicyAdmin = PolicyUtils.isPolicyAdmin(PolicyUtils.getPolicy(policyID)); + const card = isPolicyAdmin ? cardsList?.[cardID] : cardList[cardID]; + const shouldShowAddMissingDetailsButton = !isEmptyObject(card) && action?.actionName === CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS && missingDetails && isAssigneeCurrentUser; return ( <>