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 quick fix searchpage list refactor #35058

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 25 additions & 7 deletions src/components/ReferralProgramCTA.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
import React from 'react';
import {withOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
import Navigation from '@src/libs/Navigation/Navigation';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {DismissedReferralBanners} from '@src/types/onyx/Account';
import Icon from './Icon';
import {Close} from './Icon/Expensicons';
import {PressableWithoutFeedback} from './Pressable';
import Text from './Text';
import Tooltip from './Tooltip';

type ReferralProgramCTAProps = {
type ReferralProgramCTAOnyxProps = {
dismissedReferralBanners: DismissedReferralBanners;
};

type ReferralProgramCTAProps = ReferralProgramCTAOnyxProps & {
referralContentType:
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.MONEY_REQUEST
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.START_CHAT
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.SEND_MONEY
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND;

/** Method to trigger when pressing close button of the banner */
onCloseButtonPress?: () => void;
};

function ReferralProgramCTA({referralContentType, onCloseButtonPress = () => {}}: ReferralProgramCTAProps) {
function ReferralProgramCTA({referralContentType, dismissedReferralBanners}: ReferralProgramCTAProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();

const handleDismissCallToAction = () => {
User.dismissReferralBanner(CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have been referralContentType instead of CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND to dismiss the correct banner

};

if (!referralContentType || dismissedReferralBanners[referralContentType]) {
return null;
}

return (
<PressableWithoutFeedback
onPress={() => {
Expand All @@ -47,7 +60,7 @@ function ReferralProgramCTA({referralContentType, onCloseButtonPress = () => {}}
</Text>
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={onCloseButtonPress}
onPress={handleDismissCallToAction}
onMouseDown={(e) => {
e.preventDefault();
}}
Expand All @@ -67,4 +80,9 @@ function ReferralProgramCTA({referralContentType, onCloseButtonPress = () => {}}
);
}

export default ReferralProgramCTA;
export default withOnyx<ReferralProgramCTAProps, ReferralProgramCTAOnyxProps>({
dismissedReferralBanners: {
key: ONYXKEYS.ACCOUNT,
selector: (data) => data?.dismissedReferralBanners ?? {},
},
})(ReferralProgramCTA);
2 changes: 2 additions & 0 deletions src/components/SelectionList/BaseSelectionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
shouldShowTooltips = true,
shouldUseDynamicMaxToRenderPerBatch = false,
rightHandSideComponent,
isLoadingNewOptions = false,
}: BaseSelectionListProps<TItem>,
inputRef: ForwardedRef<RNTextInput>,
) {
Expand Down Expand Up @@ -412,6 +413,7 @@ function BaseSelectionList<TItem extends User | RadioItem>(
spellCheck={false}
onSubmitEditing={selectFocusedOption}
blurOnSubmit={!!flattenedSections.allOptions.length}
isLoading={isLoadingNewOptions}
/>
</View>
)}
Expand Down
3 changes: 3 additions & 0 deletions src/components/SelectionList/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ type BaseSelectionListProps<TItem extends User | RadioItem> = Partial<ChildrenPr

/** Component to display on the right side of each child */
rightHandSideComponent?: ((item: TItem) => ReactElement<TItem>) | ReactElement | null;

/** Whether to show the loading indicator for new options */
isLoadingNewOptions?: boolean;
};

type ItemLayout = {
Expand Down
227 changes: 0 additions & 227 deletions src/pages/SearchPage.js

This file was deleted.

37 changes: 6 additions & 31 deletions src/pages/SearchPage/SearchPageFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
import React, {useState} from 'react';
import React from 'react';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import ReferralProgramCTA from '@components/ReferralProgramCTA';
import useThemeStyles from '@hooks/useThemeStyles';
import * as User from '@userActions/User';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {DismissedReferralBanners} from '@src/types/onyx/Account';

type SearchPageFooterOnyxProps = {
dismissedReferralBanners: DismissedReferralBanners;
};
function SearchPageFooter({dismissedReferralBanners}: SearchPageFooterOnyxProps) {
const [shouldShowReferralCTA, setShouldShowReferralCTA] = useState(!dismissedReferralBanners[CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND]);
function SearchPageFooter() {
const themeStyles = useThemeStyles();

const closeCallToActionBanner = () => {
setShouldShowReferralCTA(false);
User.dismissReferralBanner(CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND);
};

return (
<>
{shouldShowReferralCTA && (
<View style={[themeStyles.pb5, themeStyles.flexShrink0]}>
<ReferralProgramCTA
referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND}
onCloseButtonPress={closeCallToActionBanner}
/>
</View>
)}
</>
<View style={[themeStyles.flexShrink0]}>
<ReferralProgramCTA referralContentType={CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND} />
</View>
);
}

SearchPageFooter.displayName = 'SearchPageFooter';

export default withOnyx<SearchPageFooterOnyxProps, SearchPageFooterOnyxProps>({
dismissedReferralBanners: {
key: ONYXKEYS.ACCOUNT,
selector: (data) => data?.dismissedReferralBanners ?? {},
},
})(SearchPageFooter);
export default SearchPageFooter;
Loading
Loading