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