Skip to content
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

20354 money request participants selector list refactoring #32692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5737385
useEffects refactoring
lukemorawski Nov 29, 2023
fec08cf
logic refactoring
lukemorawski Nov 30, 2023
ddd5695
fixes
lukemorawski Dec 1, 2023
e101119
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 1, 2023
40c3b74
styling fixes
lukemorawski Dec 1, 2023
9c4b4b8
refactored to split button
lukemorawski Dec 6, 2023
e5489e9
ref refactoring
lukemorawski Dec 7, 2023
7bfc447
removed unnecessary import
lukemorawski Dec 7, 2023
c2f869e
removed comment
lukemorawski Dec 7, 2023
f36e36a
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 7, 2023
47812b1
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 8, 2023
ae3ed97
prettier
lukemorawski Dec 8, 2023
3b161c6
iouType from CONST
lukemorawski Dec 8, 2023
e294815
cleaner right hand side component rendering syntax
lukemorawski Dec 8, 2023
8b4d2e5
removed unused prop
lukemorawski Dec 8, 2023
2790197
offline message cleaner syntax
lukemorawski Dec 8, 2023
099049b
Update src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestPa…
lukemorawski Dec 8, 2023
6153e6a
Update src/components/SelectionList/BaseListItem.js
lukemorawski Dec 8, 2023
98ed390
lint
lukemorawski Dec 8, 2023
a9abe8e
removed comment
lukemorawski Dec 11, 2023
1406791
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 12, 2023
9c79b10
moving changes to MoneyTemporaryForRefactorRequestParticipantsSelector
lukemorawski Dec 12, 2023
43ca072
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 13, 2023
c60409d
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 14, 2023
e942f0d
removed doubled imports
lukemorawski Dec 14, 2023
cd96252
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Dec 14, 2023
459b093
removed doubled imports
lukemorawski Dec 14, 2023
0b8701d
fixed useTheme imports
lukemorawski Dec 18, 2023
ad632c4
Merge remote-tracking branch 'origin/20354-MoneyRequestParticipantsSe…
lukemorawski Dec 18, 2023
6eb03d0
memoized list footer and fixed voucher cta padding
lukemorawski Dec 20, 2023
65d2710
send money referral program CTA layout fix
lukemorawski Jan 3, 2024
7a295ba
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Jan 3, 2024
b232142
more refactoring
lukemorawski Jan 3, 2024
936a17d
linting
lukemorawski Jan 3, 2024
6ad3dcd
fix/selecting options upon search
lukemorawski Jan 8, 2024
55b2c46
Merge branch 'main' into 20354-MoneyRequestParticipantsSelector_list_…
lukemorawski Jan 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/components/SelectionList/BaseListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function BaseListItem({
canSelectMultiple = false,
onSelectRow,
onDismissError = () => {},
rightHandSideComponent,
keyForList,
}) {
const theme = useTheme();
Expand All @@ -33,6 +34,18 @@ function BaseListItem({
const isUserItem = lodashGet(item, 'icons.length', 0) > 0;
const ListItem = isUserItem ? UserListItem : RadioListItem;

const rightHandSideComponentRender = () => {
if (canSelectMultiple || !rightHandSideComponent) {
return null;
}

if (typeof rightHandSideComponent === 'function') {
return rightHandSideComponent(item);
}

return rightHandSideComponent;
};

return (
<OfflineWithFeedback
onClose={() => onDismissError(item)}
Expand Down Expand Up @@ -62,7 +75,10 @@ function BaseListItem({
]}
>
{canSelectMultiple && (
<View style={StyleUtils.getCheckboxPressableStyle()}>
<View
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
style={StyleUtils.getCheckboxPressableStyle()}
>
<View
style={[
StyleUtils.getCheckboxContainerStyle(20),
Expand Down Expand Up @@ -98,7 +114,7 @@ function BaseListItem({
onSelectRow={onSelectRow}
showTooltip={showTooltip}
/>
{!canSelectMultiple && item.isSelected && (
{!canSelectMultiple && item.isSelected && !rightHandSideComponent && (
<View
style={[styles.flexRow, styles.alignItemsCenter, styles.ml3]}
accessible={false}
Expand All @@ -111,6 +127,7 @@ function BaseListItem({
</View>
</View>
)}
{rightHandSideComponentRender()}
</View>
{Boolean(item.invitedSecondaryLogin) && (
<Text style={[styles.ml9, styles.ph5, styles.pb3, styles.textLabelSupporting]}>
Expand Down
4 changes: 4 additions & 0 deletions src/components/SelectionList/BaseSelectionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function BaseSelectionList({
textInputLabel = '',
textInputPlaceholder = '',
textInputValue = '',
textInputHint = '',
textInputMaxLength,
inputMode = CONST.INPUT_MODE.TEXT,
onChangeText,
Expand All @@ -63,6 +64,7 @@ function BaseSelectionList({
children,
shouldStopPropagation = false,
shouldUseDynamicMaxToRenderPerBatch = false,
rightHandSideComponent,
}) {
const theme = useTheme();
const styles = useThemeStyles();
Expand Down Expand Up @@ -316,6 +318,7 @@ function BaseSelectionList({
disableIsFocusStyle={disableInitialFocusOptionStyle}
onDismissError={onDismissError}
shouldPreventDefaultFocusOnSelectRow={shouldPreventDefaultFocusOnSelectRow}
rightHandSideComponent={rightHandSideComponent}
keyForList={item.keyForList}
/>
);
Expand Down Expand Up @@ -413,6 +416,7 @@ function BaseSelectionList({
}}
label={textInputLabel}
accessibilityLabel={textInputLabel}
hint={textInputHint}
role={CONST.ROLE.PRESENTATION}
value={textInputValue}
placeholder={textInputPlaceholder}
Expand Down
5 changes: 4 additions & 1 deletion src/components/SelectionList/selectionListPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const commonListItemPropTypes = {
/** Whether to use the Checkbox (multiple selection) instead of the Checkmark (single selection) */
canSelectMultiple: PropTypes.bool,

/** Callback to fire when the item is pressed */
/** Callback to fire when the item is selected */
onSelectRow: PropTypes.func.isRequired,

/** Callback to fire when an error is dismissed */
Expand Down Expand Up @@ -192,6 +192,9 @@ const propTypes = {

/** Whether to use dynamic maxToRenderPerBatch depending on the visible number of elements */
shouldUseDynamicMaxToRenderPerBatch: PropTypes.bool,

/** Right hand side component to display in the list item. Function has list item passed as the param */
rightHandSideComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.node]),
};

export {propTypes, baseListItemPropTypes, radioListItemPropTypes, userListItemPropTypes};
23 changes: 23 additions & 0 deletions src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ function getParticipantsOption(participant, personalDetails) {
],
phoneNumber: lodashGet(detail, 'phoneNumber', ''),
selected: participant.selected,
isSelected: participant.selected,
searchText: participant.searchText,
};
}
Expand Down Expand Up @@ -607,6 +608,7 @@ function getPolicyExpenseReportOption(report) {
option.text = ReportUtils.getPolicyName(expenseReport);
option.alternateText = Localize.translateLocal('workspace.common.workspace');
option.selected = report.selected;
option.isSelected = report.selected;
return option;
}

Expand Down Expand Up @@ -1231,6 +1233,25 @@ function getTaxRatesSection(policyTaxRates, selectedOptions, searchInputValue) {
return policyRatesSections;
}

/**
* Checks if a report option is selected based on matching accountID or reportID.
*
* @param {Object} reportOption - The report option to be checked.
* @param {Object[]} selectedOptions - Array of selected options to compare with.
* @param {number} reportOption.accountID - The account ID of the report option.
* @param {number} reportOption.reportID - The report ID of the report option.
* @param {number} [selectedOptions[].accountID] - The account ID in the selected options.
* @param {number} [selectedOptions[].reportID] - The report ID in the selected options.
* @returns {boolean} True if the report option matches any of the selected options by accountID or reportID, false otherwise.
*/
function isReportSelected(reportOption, selectedOptions) {
if (!selectedOptions || selectedOptions.length === 0) {
return false;
}

return _.some(selectedOptions, (option) => (option.accountID && option.accountID === reportOption.accountID) || (option.reportID && option.reportID === reportOption.reportID));
}

/**
* Build the options
*
Expand Down Expand Up @@ -1488,6 +1509,8 @@ function getOptions(
}
}

reportOption.isSelected = isReportSelected(reportOption, selectedOptions);

recentReportOptions.push(reportOption);

// Add this login to the exclude list so it won't appear when we process the personal details
Expand Down
49 changes: 49 additions & 0 deletions src/pages/iou/MoneyRequestReferralProgramCTA.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react';
import Icon from '@components/Icon';
import {Info} from '@components/Icon/Expensicons';
import {PressableWithoutFeedback} from '@components/Pressable';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import CONST from '@src/CONST';
import Navigation from '@src/libs/Navigation/Navigation';
import ROUTES from '@src/ROUTES';

type MoneyRequestReferralProgramCTAProps = {
referralContentType: typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.SEND_MONEY | typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.MONEY_REQUEST;
};

function MoneyRequestReferralProgramCTA({referralContentType}: MoneyRequestReferralProgramCTAProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();

return (
<PressableWithoutFeedback
onPress={() => {
Navigation.navigate(ROUTES.REFERRAL_DETAILS_MODAL.getRoute(referralContentType));
}}
style={[styles.p5, styles.w100, styles.br2, styles.highlightBG, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, {gap: 10}]}
accessibilityLabel="referral"
role={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
<Text>
{translate(`referralProgram.${referralContentType}.buttonText1`)}
<Text
color={theme.success}
style={styles.textStrong}
>
{translate(`referralProgram.${referralContentType}.buttonText2`)}
</Text>
</Text>
<Icon
src={Info}
height={20}
width={20}
/>
</PressableWithoutFeedback>
);
}

export default MoneyRequestReferralProgramCTA;
Loading
Loading