-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add create expense option to IOU actions #50239
Changes from 3 commits
eaae14b
a1d92ef
5a0f9a0
167af2f
f6e9d87
d590354
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could just reuse the object from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, since we need to use the before methods for onSelected, but the new icon and text There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated to reuse |
||
|
||
const submitOnlyCreateExpense = { | ||
icon: getIconForAction(CONST.IOU.TYPE.CREATE), | ||
text: translate('iou.createExpense'), | ||
onSelected: () => selectOption(() => IOU.startMoneyRequest(CONST.IOU.TYPE.SUBMIT, report?.reportID ?? '-1'), true), | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
||
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[]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be easier to not add the other options to the list in the first place? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to the approach without new elements |
||
} 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should avoid using
let
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a more descriptive name for this variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated