|
| 1 | +import {useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; |
| 2 | +import useLocalize from '@hooks/useLocalize'; |
| 3 | +import useResponsiveLayout from '@hooks/useResponsiveLayout'; |
| 4 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 5 | +import type {CountdownTime, TrialReminderVariant} from '@hooks/useTrialPaymentReminder'; |
| 6 | + |
| 7 | +import colors from '@styles/theme/colors'; |
| 8 | + |
| 9 | +import CONST from '@src/CONST'; |
| 10 | + |
| 11 | +import React from 'react'; |
| 12 | +import {View} from 'react-native'; |
| 13 | + |
| 14 | +import Button from './Button'; |
| 15 | +import ImageSVG from './ImageSVG'; |
| 16 | +import Modal from './Modal'; |
| 17 | +import Text from './Text'; |
| 18 | + |
| 19 | +type TrialPaymentReminderModalProps = { |
| 20 | + /** Whether the modal is visible */ |
| 21 | + isVisible: boolean; |
| 22 | + |
| 23 | + /** The variant of the modal to display */ |
| 24 | + variant: TrialReminderVariant; |
| 25 | + |
| 26 | + /** Number of days remaining for 'nearEnd' variant */ |
| 27 | + daysRemaining?: number; |
| 28 | + |
| 29 | + /** Countdown time for 'countdown' variant */ |
| 30 | + countdownTime?: CountdownTime; |
| 31 | + |
| 32 | + /** Called when user presses Close */ |
| 33 | + onClose: () => void; |
| 34 | + |
| 35 | + /** Called when user presses Add payment card */ |
| 36 | + onAddPaymentCard: () => void; |
| 37 | +}; |
| 38 | + |
| 39 | +function padZero(num: number): string { |
| 40 | + return num.toString().padStart(2, '0'); |
| 41 | +} |
| 42 | + |
| 43 | +function TrialPaymentReminderModal({isVisible, variant, daysRemaining, countdownTime, onClose, onAddPaymentCard}: TrialPaymentReminderModalProps) { |
| 44 | + const {shouldUseNarrowLayout} = useResponsiveLayout(); |
| 45 | + const styles = useThemeStyles(); |
| 46 | + const illustrations = useMemoizedLazyIllustrations(['ArmWithCardPos']); |
| 47 | + const {translate} = useLocalize(); |
| 48 | + |
| 49 | + return ( |
| 50 | + <Modal |
| 51 | + onClose={onClose} |
| 52 | + onBackdropPress={() => {}} |
| 53 | + isVisible={isVisible} |
| 54 | + type={shouldUseNarrowLayout ? CONST.MODAL.MODAL_TYPE.BOTTOM_DOCKED : CONST.MODAL.MODAL_TYPE.CONFIRM} |
| 55 | + innerContainerStyle={styles.pv0} |
| 56 | + > |
| 57 | + <View style={[styles.alignItemsCenter, styles.wAuto, {backgroundColor: colors.blue800, height: CONST.CONFIRM_CONTENT_SVG_SIZE.HEIGHT}, styles.pb7]}> |
| 58 | + <ImageSVG |
| 59 | + src={illustrations.ArmWithCardPos} |
| 60 | + contentFit="contain" |
| 61 | + /> |
| 62 | + </View> |
| 63 | + <View style={[styles.m5]}> |
| 64 | + {variant === CONST.TRIAL_REMINDER_VARIANT.NEAR_END && daysRemaining !== undefined && ( |
| 65 | + <Text style={[styles.textSuccess, styles.textStrong, styles.mb2]}>{translate('trialPaymentReminder.trialEndsInDays', {count: daysRemaining})}</Text> |
| 66 | + )} |
| 67 | + {variant === CONST.TRIAL_REMINDER_VARIANT.COUNTDOWN && !!countdownTime && ( |
| 68 | + <Text style={[styles.textSuccess, styles.textStrong, styles.mb2]}> |
| 69 | + {translate('trialPaymentReminder.trialEndsCountdown', { |
| 70 | + hours: padZero(countdownTime.hours), |
| 71 | + minutes: padZero(countdownTime.minutes), |
| 72 | + seconds: padZero(countdownTime.seconds), |
| 73 | + })} |
| 74 | + </Text> |
| 75 | + )} |
| 76 | + |
| 77 | + <Text style={[styles.textHeadlineH1, styles.mb3]}>{translate('trialPaymentReminder.title')}</Text> |
| 78 | + <Text style={[styles.textSupporting]}>{translate('trialPaymentReminder.subtitle')}</Text> |
| 79 | + |
| 80 | + <Button |
| 81 | + success |
| 82 | + style={[styles.mt5]} |
| 83 | + onPress={onAddPaymentCard} |
| 84 | + pressOnEnter |
| 85 | + text={translate('trialPaymentReminder.addPaymentCardButton')} |
| 86 | + large |
| 87 | + /> |
| 88 | + <Button |
| 89 | + style={[styles.mt3]} |
| 90 | + onPress={onClose} |
| 91 | + text={translate('trialPaymentReminder.closeButton')} |
| 92 | + large |
| 93 | + /> |
| 94 | + </View> |
| 95 | + </Modal> |
| 96 | + ); |
| 97 | +} |
| 98 | + |
| 99 | +export default TrialPaymentReminderModal; |
0 commit comments