-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathReferralProgramCTA.tsx
90 lines (82 loc) · 3.25 KB
/
ReferralProgramCTA.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React, {useEffect} from 'react';
import type {StyleProp, ViewStyle} from 'react-native';
import useDismissedReferralBanners from '@hooks/useDismissedReferralBanners';
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';
import Icon from './Icon';
import {Close} from './Icon/Expensicons';
import {PressableWithoutFeedback} from './Pressable';
import Text from './Text';
import Tooltip from './Tooltip';
type ReferralProgramCTAProps = {
referralContentType:
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.SUBMIT_EXPENSE
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.START_CHAT
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.PAY_SOMEONE
| typeof CONST.REFERRAL_PROGRAM.CONTENT_TYPES.REFER_FRIEND;
style?: StyleProp<ViewStyle>;
onDismiss?: () => void;
};
function ReferralProgramCTA({referralContentType, style, onDismiss}: ReferralProgramCTAProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();
const theme = useTheme();
const {isDismissed, setAsDismissed} = useDismissedReferralBanners({referralContentType});
const handleDismissCallToAction = () => {
setAsDismissed();
onDismiss?.();
};
const shouldShowBanner = referralContentType && !isDismissed;
useEffect(() => {
if (shouldShowBanner) {
return;
}
onDismiss?.();
}, [onDismiss, shouldShowBanner]);
if (!shouldShowBanner) {
return null;
}
return (
<PressableWithoutFeedback
onPress={() => {
Navigation.navigate(ROUTES.REFERRAL_DETAILS_MODAL.getRoute(referralContentType, Navigation.getActiveRouteWithoutParams()));
}}
style={[styles.br2, styles.highlightBG, styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter, {gap: 10, padding: 10}, styles.pl5, style]}
accessibilityLabel="referral"
role={CONST.ROLE.BUTTON}
>
<Text>
{translate(`referralProgram.${referralContentType}.buttonText1`)}
<Text
color={theme.success}
style={styles.textStrong}
>
{translate(`referralProgram.${referralContentType}.buttonText2`)}
</Text>
</Text>
<Tooltip text={translate('common.close')}>
<PressableWithoutFeedback
onPress={handleDismissCallToAction}
onMouseDown={(e) => {
e.preventDefault();
}}
style={[styles.touchableButtonImage]}
role={CONST.ROLE.BUTTON}
accessibilityLabel={translate('common.close')}
>
<Icon
src={Close}
height={20}
width={20}
fill={theme.icon}
/>
</PressableWithoutFeedback>
</Tooltip>
</PressableWithoutFeedback>
);
}
export default ReferralProgramCTA;