|
| 1 | +import type { FC } from 'react'; |
| 2 | +import { useCallback } from 'react'; |
| 3 | +import { useTranslation } from 'react-i18next'; |
| 4 | +import { Box } from 'react-native-flex-layout'; |
| 5 | +import type { ModalProps } from 'react-native-paper'; |
| 6 | +import { Button, Portal, Text } from 'react-native-paper'; |
| 7 | + |
| 8 | +import { setEnableAppUpdates } from '@/slices/settings'; |
| 9 | + |
| 10 | +import BaseModal from '@/components/BaseModal'; |
| 11 | + |
| 12 | +import { useAppDispatch } from '@/store'; |
| 13 | + |
| 14 | +const EnableAppUpdatesModal: FC<Omit<ModalProps, 'children'>> = props => { |
| 15 | + const { onDismiss } = props; |
| 16 | + const { t } = useTranslation(); |
| 17 | + const dispatch = useAppDispatch(); |
| 18 | + |
| 19 | + const handleAbort = useCallback(() => { |
| 20 | + onDismiss?.(); |
| 21 | + }, [onDismiss]); |
| 22 | + |
| 23 | + const handleEnable = useCallback(() => { |
| 24 | + console.log('handleEnable'); |
| 25 | + dispatch(setEnableAppUpdates({ enable: true })); |
| 26 | + handleAbort(); |
| 27 | + }, [dispatch, handleAbort]); |
| 28 | + |
| 29 | + const handleDisable = useCallback(() => { |
| 30 | + dispatch(setEnableAppUpdates({ enable: false })); |
| 31 | + handleAbort(); |
| 32 | + }, [dispatch, handleAbort]); |
| 33 | + |
| 34 | + return ( |
| 35 | + <Portal> |
| 36 | + <BaseModal {...props}> |
| 37 | + <Box p={16}> |
| 38 | + <Box mb={8}> |
| 39 | + <Text variant="bodyLarge"> |
| 40 | + {t('settings.doYouWantToEnableAppUpdates')} |
| 41 | + </Text> |
| 42 | + </Box> |
| 43 | + </Box> |
| 44 | + <Box |
| 45 | + style={{ |
| 46 | + flexDirection: 'row', |
| 47 | + justifyContent: 'flex-end', |
| 48 | + alignItems: 'center', |
| 49 | + padding: 8, |
| 50 | + }} |
| 51 | + > |
| 52 | + <Button |
| 53 | + style={{ marginRight: 8 }} |
| 54 | + onPress={handleEnable} |
| 55 | + mode="contained" |
| 56 | + > |
| 57 | + {t('enable')} |
| 58 | + </Button> |
| 59 | + <Button onPress={handleDisable} mode="text"> |
| 60 | + {t('disable')} |
| 61 | + </Button> |
| 62 | + </Box> |
| 63 | + </BaseModal> |
| 64 | + </Portal> |
| 65 | + ); |
| 66 | +}; |
| 67 | + |
| 68 | +export default EnableAppUpdatesModal; |
0 commit comments