From 82cafcfcd5d934a3811aa6d30257d3efddcc0d7b Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Fri, 3 May 2024 00:43:32 +0700 Subject: [PATCH 1/3] show category picker for invoices --- src/libs/ReportUtils.ts | 1 + .../iou/request/step/IOURequestStepCategory.tsx | 16 +++++++++------- .../request/step/IOURequestStepConfirmation.tsx | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 9c5e437a874e..48837f26b62c 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -6636,6 +6636,7 @@ export { isExpensifyOnlyParticipantInReport, isGroupChat, isGroupChatAdmin, + isGroupPolicy, isReportInGroupPolicy, isHoldCreator, isIOUOwnedByCurrentUser, diff --git a/src/pages/iou/request/step/IOURequestStepCategory.tsx b/src/pages/iou/request/step/IOURequestStepCategory.tsx index 4b34a6a19600..4cbec02be858 100644 --- a/src/pages/iou/request/step/IOURequestStepCategory.tsx +++ b/src/pages/iou/request/step/IOURequestStepCategory.tsx @@ -71,9 +71,11 @@ function IOURequestStepCategory({ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const reportAction = reportActions?.[report?.parentReportActionID || reportActionID] ?? null; - // The transactionCategory can be an empty string, so to maintain the logic we'd like to keep it in this shape until utils refactor - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const shouldShowCategory = ReportUtils.isReportInGroupPolicy(report) && (!!transactionCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {}))); + const shouldShowCategory = + (ReportUtils.isReportInGroupPolicy(report) || ReportUtils.isGroupPolicy(policy?.type ?? '')) && + // The transactionCategory can be an empty string, so to maintain the logic we'd like to keep it in this shape until utils refactor + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + (!!transactionCategory || OptionsListUtils.hasEnabledOptions(Object.values(policyCategories ?? {}))); const isSplitBill = iouType === CONST.IOU.TYPE.SPLIT; const canEditSplitBill = isSplitBill && reportAction && session?.accountID === reportAction.actorAccountID && TransactionUtils.areRequiredFieldsEmpty(transaction); @@ -140,7 +142,7 @@ function IOURequestStepCategory({ {translate('iou.categorySelection')} @@ -157,13 +159,13 @@ const IOURequestStepCategoryWithOnyx = withOnyx `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, + key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY}${IOU.getIOURequestPolicyID(transaction, report)}`, }, policyCategories: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, + key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${IOU.getIOURequestPolicyID(transaction, report)}`, }, policyTags: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, + key: ({report, transaction}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${IOU.getIOURequestPolicyID(transaction, report)}`, }, reportActions: { key: ({ diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx index e33e4d8fb763..627db886366b 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.tsx +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.tsx @@ -134,7 +134,7 @@ function IOURequestStepConfirmation({ }) ?? [], [transaction?.participants, personalDetails, iouType], ); - const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)), [report]); + const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(report)) || ReportUtils.isGroupPolicy(policy?.type ?? ''), [report, policy]); const formHasBeenSubmitted = useRef(false); useEffect(() => { @@ -563,7 +563,7 @@ function IOURequestStepConfirmation({ // split rather than forcing the user to create a new group, just for that expense. The reportID is empty, when the action was initiated from // the floating-action-button (since it is something that exists outside the context of a report). canModifyParticipants={!transaction?.isFromGlobalCreate} - policyID={report?.policyID} + policyID={report?.policyID ?? policy?.id ?? ''} bankAccountRoute={ReportUtils.getBankAccountRoute(report)} iouMerchant={transaction?.merchant} iouCreated={transaction?.created} From 35df49fb017b59f2bef280776d9ce74b9e6c09d0 Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Fri, 3 May 2024 16:18:37 +0700 Subject: [PATCH 2/3] hide tags and tax fields for invoices --- src/components/MoneyRequestConfirmationList.tsx | 6 ++++-- src/components/ReportActionItem/MoneyRequestView.tsx | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.tsx b/src/components/MoneyRequestConfirmationList.tsx index b2dac85f70eb..45a44f5668b7 100755 --- a/src/components/MoneyRequestConfirmationList.tsx +++ b/src/components/MoneyRequestConfirmationList.tsx @@ -294,10 +294,12 @@ function MoneyRequestConfirmationList({ const canUpdateSenderWorkspace = useMemo(() => PolicyUtils.canSendInvoice(allPolicies) && !!transaction?.isFromGlobalCreate, [allPolicies, transaction?.isFromGlobalCreate]); // A flag for showing the tags field - const shouldShowTags = useMemo(() => isPolicyExpenseChat && OptionsListUtils.hasEnabledTags(policyTagLists), [isPolicyExpenseChat, policyTagLists]); + // TODO: remove the !isTypeInvoice from this condition after BE supports tags for invoices: https://github.com/Expensify/App/issues/41281 + const shouldShowTags = useMemo(() => isPolicyExpenseChat && OptionsListUtils.hasEnabledTags(policyTagLists) && !isTypeInvoice, [isPolicyExpenseChat, policyTagLists, isTypeInvoice]); // A flag for showing tax rate - const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy); + // TODO: remove the !isTypeInvoice from this condition after BE supports tax for invoices: https://github.com/Expensify/App/issues/41281 + const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy) && !isTypeInvoice; // A flag for showing the billable field const shouldShowBillable = policy?.disabledFields?.defaultBillable === false; diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 73bc7898c6df..72f09b5ca554 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -170,13 +170,14 @@ function MoneyRequestView({ // transactionCategory can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const shouldShowCategory = isPolicyExpenseChat && (transactionCategory || OptionsListUtils.hasEnabledOptions(policyCategories ?? {})); - // transactionTag can be an empty string - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - const shouldShowTag = isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)); + // TODO: remove the !isInvoice from this condition after BE supports tags for invoices: https://github.com/Expensify/App/issues/41281 + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- transactionTag can be an empty string + const shouldShowTag = isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)) && !isInvoice; const shouldShowBillable = isPolicyExpenseChat && (!!transactionBillable || !(policy?.disabledFields?.defaultBillable ?? true)); // A flag for showing tax rate - const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy); + // TODO: remove the !isInvoice from this condition after BE supports tax for invoices: https://github.com/Expensify/App/issues/41281 + const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy) && !isInvoice; const {getViolationsForField} = useViolations(transactionViolations ?? []); const hasViolations = useCallback( From 9dca708bd1a9bead4baf0b567263e3bbc39fde04 Mon Sep 17 00:00:00 2001 From: gijoe0295 Date: Fri, 3 May 2024 19:23:35 +0700 Subject: [PATCH 3/3] revert: hide tags and tax in money request view for invoices --- src/components/ReportActionItem/MoneyRequestView.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestView.tsx b/src/components/ReportActionItem/MoneyRequestView.tsx index 72f09b5ca554..73bc7898c6df 100644 --- a/src/components/ReportActionItem/MoneyRequestView.tsx +++ b/src/components/ReportActionItem/MoneyRequestView.tsx @@ -170,14 +170,13 @@ function MoneyRequestView({ // transactionCategory can be an empty string // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const shouldShowCategory = isPolicyExpenseChat && (transactionCategory || OptionsListUtils.hasEnabledOptions(policyCategories ?? {})); - // TODO: remove the !isInvoice from this condition after BE supports tags for invoices: https://github.com/Expensify/App/issues/41281 - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- transactionTag can be an empty string - const shouldShowTag = isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)) && !isInvoice; + // transactionTag can be an empty string + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + const shouldShowTag = isPolicyExpenseChat && (transactionTag || OptionsListUtils.hasEnabledTags(policyTagLists)); const shouldShowBillable = isPolicyExpenseChat && (!!transactionBillable || !(policy?.disabledFields?.defaultBillable ?? true)); // A flag for showing tax rate - // TODO: remove the !isInvoice from this condition after BE supports tax for invoices: https://github.com/Expensify/App/issues/41281 - const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy) && !isInvoice; + const shouldShowTax = isTaxTrackingEnabled(isPolicyExpenseChat, policy); const {getViolationsForField} = useViolations(transactionViolations ?? []); const hasViolations = useCallback(