|
| 1 | +import React, {useState} from 'react'; |
| 2 | +import {View} from 'react-native'; |
| 3 | +import Button from '@components/Button'; |
| 4 | +import FixedFooter from '@components/FixedFooter'; |
| 5 | +import HeaderWithBackButton from '@components/HeaderWithBackButton'; |
| 6 | +import Icon from '@components/Icon'; |
| 7 | +import Modal from '@components/Modal'; |
| 8 | +import type {ModalProps} from '@components/Modal/Global/ModalContext'; |
| 9 | +import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback'; |
| 10 | +import ScreenWrapper from '@components/ScreenWrapper'; |
| 11 | +import ScrollView from '@components/ScrollView'; |
| 12 | +import Text from '@components/Text'; |
| 13 | +import {useMemoizedLazyExpensifyIcons, useMemoizedLazyIllustrations} from '@hooks/useLazyAsset'; |
| 14 | +import useLocalize from '@hooks/useLocalize'; |
| 15 | +import useTheme from '@hooks/useTheme'; |
| 16 | +import useThemeStyles from '@hooks/useThemeStyles'; |
| 17 | +import type {GustoSyncResult, GustoSyncResultUser} from '@libs/API/GustoSyncResult'; |
| 18 | +import CONST from '@src/CONST'; |
| 19 | + |
| 20 | +type GustoSyncResultsModalProps = ModalProps & { |
| 21 | + /** Sync result returned by the completed Gusto sync job */ |
| 22 | + result: GustoSyncResult; |
| 23 | +}; |
| 24 | + |
| 25 | +function getResultCount(users?: GustoSyncResultUser[]) { |
| 26 | + return users?.length ?? 0; |
| 27 | +} |
| 28 | + |
| 29 | +function GustoSyncResultsModal({result, closeModal}: GustoSyncResultsModalProps) { |
| 30 | + const {translate} = useLocalize(); |
| 31 | + const styles = useThemeStyles(); |
| 32 | + const theme = useTheme(); |
| 33 | + const icons = useMemoizedLazyExpensifyIcons(['DownArrow', 'Sync']); |
| 34 | + const illustrations = useMemoizedLazyIllustrations(['NewUser']); |
| 35 | + const [isSkippedSectionExpanded, setIsSkippedSectionExpanded] = useState(false); |
| 36 | + |
| 37 | + const addedCount = getResultCount(result.added); |
| 38 | + const removedCount = getResultCount(result.removed); |
| 39 | + const skippedCount = getResultCount(result.skipped); |
| 40 | + const closeResultsModal = () => closeModal(); |
| 41 | + |
| 42 | + const renderResultSummary = (label: string, count: number) => ( |
| 43 | + <View style={[styles.mb6]}> |
| 44 | + <Text style={[styles.textSupporting, styles.mb1]}>{label}</Text> |
| 45 | + <Text style={[styles.textNormalThemeText, styles.textStrong]}>{translate('workspace.hr.gusto.syncResults.employeeCount', {count})}</Text> |
| 46 | + </View> |
| 47 | + ); |
| 48 | + |
| 49 | + return ( |
| 50 | + <Modal |
| 51 | + type={CONST.MODAL.MODAL_TYPE.RIGHT_DOCKED} |
| 52 | + isVisible |
| 53 | + onClose={closeResultsModal} |
| 54 | + shouldHandleNavigationBack |
| 55 | + enableEdgeToEdgeBottomSafeAreaPadding |
| 56 | + > |
| 57 | + <ScreenWrapper |
| 58 | + includePaddingTop={false} |
| 59 | + enableEdgeToEdgeBottomSafeAreaPadding |
| 60 | + testID="GustoSyncResultsModal" |
| 61 | + > |
| 62 | + <HeaderWithBackButton |
| 63 | + title={translate('workspace.hr.gusto.syncResults.title')} |
| 64 | + onBackButtonPress={closeResultsModal} |
| 65 | + /> |
| 66 | + <ScrollView contentContainerStyle={[styles.flexGrow1, styles.ph5]}> |
| 67 | + <View style={[styles.alignItemsCenter, styles.mt8, styles.mb8, styles.pRelative]}> |
| 68 | + <Icon |
| 69 | + src={illustrations.NewUser} |
| 70 | + width={88} |
| 71 | + height={88} |
| 72 | + /> |
| 73 | + <View style={[styles.pAbsolute, styles.rn3, styles.b0]}> |
| 74 | + <Icon |
| 75 | + src={icons.Sync} |
| 76 | + fill={theme.success} |
| 77 | + width={36} |
| 78 | + height={36} |
| 79 | + /> |
| 80 | + </View> |
| 81 | + </View> |
| 82 | + <Text style={[styles.textHeadlineH1, styles.mb8]}>{translate('workspace.hr.gusto.syncResults.successTitle')}</Text> |
| 83 | + {renderResultSummary(translate('workspace.hr.gusto.syncResults.added'), addedCount)} |
| 84 | + {renderResultSummary(translate('workspace.hr.gusto.syncResults.removed'), removedCount)} |
| 85 | + <PressableWithoutFeedback |
| 86 | + accessibilityLabel={translate('workspace.hr.gusto.syncResults.skipped')} |
| 87 | + role={CONST.ROLE.BUTTON} |
| 88 | + onPress={() => setIsSkippedSectionExpanded((isExpanded) => !isExpanded)} |
| 89 | + style={[styles.flexRow, styles.justifyContentBetween, styles.alignItemsCenter]} |
| 90 | + > |
| 91 | + <View> |
| 92 | + <Text style={[styles.textSupporting, styles.mb1]}>{translate('workspace.hr.gusto.syncResults.skipped')}</Text> |
| 93 | + <Text style={[styles.textNormalThemeText, styles.textStrong]}>{translate('workspace.hr.gusto.syncResults.employeeCount', {count: skippedCount})}</Text> |
| 94 | + </View> |
| 95 | + <Icon |
| 96 | + src={icons.DownArrow} |
| 97 | + fill={theme.icon} |
| 98 | + additionalStyles={isSkippedSectionExpanded ? {transform: [{rotate: '180deg'}]} : undefined} |
| 99 | + /> |
| 100 | + </PressableWithoutFeedback> |
| 101 | + {isSkippedSectionExpanded && |
| 102 | + result.skipped?.map((user) => ( |
| 103 | + <View |
| 104 | + key={user.email} |
| 105 | + style={[styles.mt4]} |
| 106 | + > |
| 107 | + <Text style={[styles.textNormalThemeText, styles.textStrong]}>{user.displayName ?? user.email}</Text> |
| 108 | + <Text style={[styles.textSupporting]}>{user.reason}</Text> |
| 109 | + </View> |
| 110 | + ))} |
| 111 | + </ScrollView> |
| 112 | + <FixedFooter> |
| 113 | + <Button |
| 114 | + large |
| 115 | + success |
| 116 | + text={translate('common.buttonConfirm')} |
| 117 | + onPress={closeResultsModal} |
| 118 | + /> |
| 119 | + </FixedFooter> |
| 120 | + </ScreenWrapper> |
| 121 | + </Modal> |
| 122 | + ); |
| 123 | +} |
| 124 | + |
| 125 | +export default GustoSyncResultsModal; |
0 commit comments