From eaae14bf48d62847b8c90472f0ebab9da12e19b4 Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Fri, 4 Oct 2024 15:22:52 +0200 Subject: [PATCH 1/3] add create expense option to IOU actions --- src/languages/en.ts | 1 + .../AttachmentPickerWithMenuItems.tsx | 54 ++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index e72c6a422ee3..6ceac0f2953e 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -685,6 +685,7 @@ const translations = { submit: 'submit an expense', track: 'track an expense', invoice: 'invoice an expense', + create: 'create an expense', }, }, adminOnlyCanPost: 'Only admins can send messages in this room.', diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 005ca4df153a..9d07562f45ba 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -12,6 +12,7 @@ import PopoverMenu from '@components/PopoverMenu'; import PressableWithFeedback from '@components/Pressable/PressableWithFeedback'; import Tooltip from '@components/Tooltip/PopoverAnchorTooltip'; import useLocalize from '@hooks/useLocalize'; +import usePermissions from '@hooks/usePermissions'; import usePrevious from '@hooks/usePrevious'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; @@ -120,6 +121,7 @@ function AttachmentPickerWithMenuItems({ const {isDelegateAccessRestricted, delegatorEmail} = useDelegateUserDetails(); const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); const [policy] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`); + const {canUseCombinedTrackSubmit} = usePermissions(); /** * Returns the list of IOU Options @@ -168,10 +170,58 @@ function AttachmentPickerWithMenuItems({ }, }; - return ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipantIDs ?? []).map((option) => ({ + let list: PopoverMenuItem[] = ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipantIDs ?? []).map((option) => ({ ...options[option], })); - }, [translate, report, policy, reportParticipantIDs, isDelegateAccessRestricted]); + + if (canUseCombinedTrackSubmit) { + const trackOnlyCreateExpense = { + icon: getIconForAction(CONST.IOU.TYPE.CREATE), + text: translate('iou.createExpense'), + onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, report?.reportID ?? '-1'), true), + }; + + const submitOnlyCreateExpense = { + icon: getIconForAction(CONST.IOU.TYPE.CREATE), + text: translate('iou.createExpense'), + onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, report?.reportID ?? '-1'), true), + }; + + if (list.some((option) => options[CONST.IOU.TYPE.TRACK].text === option.text) && list.some((option) => options[CONST.IOU.TYPE.SUBMIT].text === option.text)) { + list = list.reduce((acc, item) => { + if (item.text === translate('iou.submitExpense')) { + acc.push(submitOnlyCreateExpense); + } else if (item.text !== translate('iou.trackExpense')) { + acc.push(item); + } + + return acc; + }, [] as PopoverMenuItem[]); + } else if (list.some((option) => options[CONST.IOU.TYPE.TRACK].text === option.text)) { + list = list.reduce((acc, item) => { + if (item.text === translate('iou.trackExpense')) { + acc.push(trackOnlyCreateExpense); + } else { + acc.push(item); + } + + return acc; + }, [] as PopoverMenuItem[]); + } else if (list.some((option) => options[CONST.IOU.TYPE.SUBMIT].text === option.text)) { + list = list.reduce((acc, item) => { + if (item.text === translate('iou.submitExpense')) { + acc.push(submitOnlyCreateExpense); + } else { + acc.push(item); + } + + return acc; + }, [] as PopoverMenuItem[]); + } + } + + return list; + }, [translate, canUseCombinedTrackSubmit, report, policy, reportParticipantIDs, isDelegateAccessRestricted]); /** * Determines if we can show the task option From a1d92ef9feae7fd81c35956164a13d9ffad7fb02 Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Fri, 4 Oct 2024 21:07:59 +0200 Subject: [PATCH 2/3] fix titles for the tabs at IOU start page --- src/languages/en.ts | 1 - src/pages/iou/request/IOURequestStartPage.tsx | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/languages/en.ts b/src/languages/en.ts index 6ceac0f2953e..e72c6a422ee3 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -685,7 +685,6 @@ const translations = { submit: 'submit an expense', track: 'track an expense', invoice: 'invoice an expense', - create: 'create an expense', }, }, adminOnlyCanPost: 'Only admins can send messages in this room.', diff --git a/src/pages/iou/request/IOURequestStartPage.tsx b/src/pages/iou/request/IOURequestStartPage.tsx index c4abf714502a..09fe67ab882f 100644 --- a/src/pages/iou/request/IOURequestStartPage.tsx +++ b/src/pages/iou/request/IOURequestStartPage.tsx @@ -45,19 +45,19 @@ function IOURequestStartPage({ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const [transaction] = useOnyx(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${route?.params.transactionID || -1}`); const [allPolicies] = useOnyx(ONYXKEYS.COLLECTION.POLICY); + const {canUseP2PDistanceRequests, canUseCombinedTrackSubmit} = usePermissions(iouType); const tabTitles = { [CONST.IOU.TYPE.REQUEST]: translate('iou.submitExpense'), - [CONST.IOU.TYPE.SUBMIT]: translate('iou.submitExpense'), + [CONST.IOU.TYPE.SUBMIT]: canUseCombinedTrackSubmit ? translate('iou.createExpense') : translate('iou.submitExpense'), [CONST.IOU.TYPE.SEND]: translate('iou.paySomeone', {name: ReportUtils.getPayeeName(report)}), [CONST.IOU.TYPE.PAY]: translate('iou.paySomeone', {name: ReportUtils.getPayeeName(report)}), [CONST.IOU.TYPE.SPLIT]: translate('iou.splitExpense'), - [CONST.IOU.TYPE.TRACK]: translate('iou.trackExpense'), + [CONST.IOU.TYPE.TRACK]: canUseCombinedTrackSubmit ? translate('iou.createExpense') : translate('iou.trackExpense'), [CONST.IOU.TYPE.INVOICE]: translate('workspace.invoices.sendInvoice'), [CONST.IOU.TYPE.CREATE]: translate('iou.createExpense'), }; const transactionRequestType = useRef(TransactionUtils.getRequestType(transaction)); - const {canUseP2PDistanceRequests, canUseCombinedTrackSubmit} = usePermissions(iouType); const isFromGlobalCreate = isEmptyObject(report?.reportID); // Clear out the temporary expense if the reportID in the URL has changed from the transaction's reportID From f6e9d871b1114dc54d90497a9630f8baf1ef2f1b Mon Sep 17 00:00:00 2001 From: Yauheni Pasiukevich Date: Mon, 7 Oct 2024 23:30:59 +0200 Subject: [PATCH 3/3] change the approach to using filter --- .../AttachmentPickerWithMenuItems.tsx | 61 +++---------------- 1 file changed, 9 insertions(+), 52 deletions(-) diff --git a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx index 9d07562f45ba..c1702381b668 100644 --- a/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx +++ b/src/pages/home/report/ReportActionCompose/AttachmentPickerWithMenuItems.tsx @@ -143,8 +143,8 @@ function AttachmentPickerWithMenuItems({ onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SPLIT, report?.reportID ?? '-1'), true), }, [CONST.IOU.TYPE.SUBMIT]: { - icon: getIconForAction(CONST.IOU.TYPE.REQUEST), - text: translate('iou.submitExpense'), + icon: canUseCombinedTrackSubmit ? getIconForAction(CONST.IOU.TYPE.CREATE) : getIconForAction(CONST.IOU.TYPE.REQUEST), + text: canUseCombinedTrackSubmit ? translate('iou.createExpense') : translate('iou.submitExpense'), onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, report?.reportID ?? '-1'), true), }, [CONST.IOU.TYPE.PAY]: { @@ -159,8 +159,8 @@ function AttachmentPickerWithMenuItems({ }, }, [CONST.IOU.TYPE.TRACK]: { - icon: getIconForAction(CONST.IOU.TYPE.TRACK), - text: translate('iou.trackExpense'), + icon: canUseCombinedTrackSubmit ? getIconForAction(CONST.IOU.TYPE.CREATE) : getIconForAction(CONST.IOU.TYPE.TRACK), + text: canUseCombinedTrackSubmit ? translate('iou.createExpense') : translate('iou.trackExpense'), onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, report?.reportID ?? '-1'), true), }, [CONST.IOU.TYPE.INVOICE]: { @@ -170,57 +170,14 @@ function AttachmentPickerWithMenuItems({ }, }; - let list: PopoverMenuItem[] = ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipantIDs ?? []).map((option) => ({ + const moneyRequestOptionsList = ReportUtils.temporary_getMoneyRequestOptions(report, policy, reportParticipantIDs ?? []).map((option) => ({ ...options[option], })); - if (canUseCombinedTrackSubmit) { - const trackOnlyCreateExpense = { - icon: getIconForAction(CONST.IOU.TYPE.CREATE), - text: translate('iou.createExpense'), - onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.TRACK, report?.reportID ?? '-1'), true), - }; - - const submitOnlyCreateExpense = { - icon: getIconForAction(CONST.IOU.TYPE.CREATE), - text: translate('iou.createExpense'), - onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, report?.reportID ?? '-1'), true), - }; - - if (list.some((option) => options[CONST.IOU.TYPE.TRACK].text === option.text) && list.some((option) => options[CONST.IOU.TYPE.SUBMIT].text === option.text)) { - list = list.reduce((acc, item) => { - if (item.text === translate('iou.submitExpense')) { - acc.push(submitOnlyCreateExpense); - } else if (item.text !== translate('iou.trackExpense')) { - acc.push(item); - } - - return acc; - }, [] as PopoverMenuItem[]); - } else if (list.some((option) => options[CONST.IOU.TYPE.TRACK].text === option.text)) { - list = list.reduce((acc, item) => { - if (item.text === translate('iou.trackExpense')) { - acc.push(trackOnlyCreateExpense); - } else { - acc.push(item); - } - - return acc; - }, [] as PopoverMenuItem[]); - } else if (list.some((option) => options[CONST.IOU.TYPE.SUBMIT].text === option.text)) { - list = list.reduce((acc, item) => { - if (item.text === translate('iou.submitExpense')) { - acc.push(submitOnlyCreateExpense); - } else { - acc.push(item); - } - - return acc; - }, [] as PopoverMenuItem[]); - } - } - - return list; + return canUseCombinedTrackSubmit + ? // Removes track option for the workspace with the canUseCombinedTrackSubmit enabled + moneyRequestOptionsList.filter((item, index, self) => index === self.findIndex((t) => t.text === item.text)) + : moneyRequestOptionsList; }, [translate, canUseCombinedTrackSubmit, report, policy, reportParticipantIDs, isDelegateAccessRestricted]); /**