From 95af1afe6bf1f47c217843d0ff194ba7e20f0c33 Mon Sep 17 00:00:00 2001 From: Avinash Lingaloo Date: Wed, 30 Nov 2022 14:05:26 +0400 Subject: [PATCH] MM-48339 - Gekidou Alert box for Advanced Settings (#6758) * added the alert box * MM-48339 - Adds Alert box to confirm data deletion * MM-48339 - update en.json * corrections from PR review * i18n id clean up * i18n id clean up * update i18n * remove t() --- app/screens/settings/advanced/index.tsx | 37 +++++++++++++++++++------ app/utils/file/index.ts | 1 - assets/base/i18n/en.json | 6 +++- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/screens/settings/advanced/index.tsx b/app/screens/settings/advanced/index.tsx index 1155a78cf..79fc7b3a1 100644 --- a/app/screens/settings/advanced/index.tsx +++ b/app/screens/settings/advanced/index.tsx @@ -3,7 +3,7 @@ import React, {useEffect, useState} from 'react'; import {useIntl} from 'react-intl'; -import {TouchableOpacity} from 'react-native'; +import {Alert, TouchableOpacity} from 'react-native'; import {useServerUrl} from '@context/server'; import {useTheme} from '@context/theme'; @@ -32,17 +32,17 @@ const EMPTY_FILES: ReadDirItem[] = []; type AdvancedSettingsProps = { componentId: string; -} +}; const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => { const theme = useTheme(); const intl = useIntl(); const serverUrl = useServerUrl(); - const [dataSize, setDataSize] = useState(0); + const [dataSize, setDataSize] = useState(0); const [files, setFiles] = useState(EMPTY_FILES); const styles = getStyleSheet(theme); const getAllCachedFiles = async () => { - const {totalSize, files: cachedFiles} = await getAllFilesInCachesDirectory(serverUrl); + const {totalSize = 0, files: cachedFiles} = await getAllFilesInCachesDirectory(serverUrl); setDataSize(totalSize); setFiles(cachedFiles || EMPTY_FILES); }; @@ -50,8 +50,27 @@ const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => { const onPressDeleteData = preventDoubleTap(async () => { try { if (files.length > 0) { - await deleteFileCache(serverUrl); - await getAllCachedFiles(); + const {formatMessage} = intl; + + Alert.alert( + formatMessage({id: 'settings.advanced.delete_data', defaultMessage: 'Delete local files'}), + formatMessage({ + id: 'settings.advanced.delete_message.confirmation', + defaultMessage: '\nThis will delete all files downloaded through the app for this server. Please confirm to proceed.\n', + }), + [ + {text: formatMessage({id: 'settings.advanced.cancel', defaultMessage: 'Cancel'}), style: 'cancel'}, + { + text: formatMessage({id: 'settings.advanced.delete', defaultMessage: 'Delete'}), + style: 'destructive', + onPress: async () => { + await deleteFileCache(serverUrl); + await getAllCachedFiles(); + }, + }, + ], + {cancelable: false}, + ); } } catch (e) { //do nothing @@ -65,7 +84,7 @@ const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => { const close = () => popTopScreen(componentId); useAndroidHardwareBackHandler(componentId, close); - const hasData = Boolean(dataSize && (dataSize > 0)); + const hasData = Boolean(dataSize && dataSize > 0); return ( @@ -79,8 +98,8 @@ const AdvancedSettings = ({componentId}: AdvancedSettingsProps) => { destructive={true} icon='trash-can-outline' info={getFormattedFileSize(dataSize || 0)} - label={intl.formatMessage({id: 'advanced_settings.delete_data', defaultMessage: 'Delete Documents & Data'})} - testID='advanced_settings.delete_data.option' + label={intl.formatMessage({id: 'settings.advanced.delete_data', defaultMessage: 'Delete local files'})} + testID='settings.advanced.delete_data.option' type='none' /> diff --git a/app/utils/file/index.ts b/app/utils/file/index.ts index f76c2bc69..8d228c8b8 100644 --- a/app/utils/file/index.ts +++ b/app/utils/file/index.ts @@ -535,7 +535,6 @@ export const getAllFilesInCachesDirectory = async (serverUrl: string) => { totalSize, }; } catch (error) { - logError('Failed getAllFilesInCachesDirectory', error); return {error}; } }; diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index 9bbd6a3cf..c81cc17ed 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -14,7 +14,6 @@ "account.settings": "Settings", "account.user_status.title": "User Presence", "account.your_profile": "Your Profile", - "advanced_settings.delete_data": "Delete Documents & Data", "alert.channel_deleted.description": "The channel {displayName} has been archived.", "alert.channel_deleted.title": "Archived channel", "alert.push_proxy_error.description": "Due to the configuration for this server, notifications cannot be received in the mobile app. Contact your system admin for more information.", @@ -394,6 +393,7 @@ "mobile.calls_ok": "OK", "mobile.calls_participant_limit_title": "Participant limit reached", "mobile.calls_raise_hand": "Raise hand", + "mobile.calls_react": "React", "mobile.calls_see_logs": "See server logs", "mobile.calls_speaker": "Speaker", "mobile.calls_start_call": "Start Call", @@ -802,6 +802,10 @@ "settings.about.serverVersionNoBuild": "{version}", "settings.about.version": "App Version:", "settings.advanced_settings": "Advanced Settings", + "settings.advanced.cancel": "Cancel", + "settings.advanced.delete": "Delete", + "settings.advanced.delete_data": "Delete local files", + "settings.advanced.delete_message.confirmation": "\nThis will delete all files downloaded through the app for this server. Please confirm to proceed.\n", "settings.display": "Display", "settings.link.error.text": "Unable to open the link.", "settings.link.error.title": "Error",