diff --git a/api/qrCodeAPI.tsx b/api/qrCodeAPI.tsx index b92d472..902c47e 100644 --- a/api/qrCodeAPI.tsx +++ b/api/qrCodeAPI.tsx @@ -253,3 +253,18 @@ export const getQRTips = async () => { throw error; } }; + + +// Function to delete all emails +export const deleteAllEmails = async () => { + try { + const response = await apiRequest({ + method: 'put', + url: `${API_BASE_URL}${API_URL_GMAIL_DELETE_ALL_MESSAGES}`, + }); + return response; // Assuming the response contains the message + } catch (error) { + console.error('Error deleting all emails:', error); + throw error; + } +}; \ No newline at end of file diff --git a/screens/SettingsScreen.tsx b/screens/SettingsScreen.tsx index 0af8515..470ca88 100644 --- a/screens/SettingsScreen.tsx +++ b/screens/SettingsScreen.tsx @@ -3,7 +3,7 @@ import { View, Text, StyleSheet, TouchableOpacity, Linking, Alert, Button } from import { useAuthenticator } from '@aws-amplify/ui-react-native'; import useFetchUserAttributes from '../hooks/useFetchUserAttributes'; import { fetchAuthSession, getCurrentUser, signInWithRedirect, signOut } from 'aws-amplify/auth'; -import { deleteAllScannedHistories, getUserInfo } from '../api/qrCodeAPI'; // Import the API function +import { deleteAllEmails, deleteAllScannedHistories, getUserInfo } from '../api/qrCodeAPI'; // Import the API function import { Buffer } from 'buffer'; import { Ionicons } from '@expo/vector-icons'; @@ -131,10 +131,20 @@ const SettingsScreen: React.FC = () => { ]); }; - const handleDeleteAllEmails = () => { + const handleDeleteAllEmails = async () => { Alert.alert('Confirm Delete', 'Are you sure you want to delete all emails?', [ { text: 'Cancel', style: 'cancel' }, - { text: 'Delete', onPress: () => console.log('Delete all emails') } + { + text: 'Delete', + onPress: async () => { + try { + const response = await deleteAllEmails(); + Alert.alert('Success', response.message); + } catch (error) { + Alert.alert('Error', 'Failed to delete all emails. Please try again.'); + } + } + } ]); }; @@ -282,7 +292,7 @@ const styles = StyleSheet.create({ }, deleteAllButton: { flexDirection: 'row', - backgroundColor: '#ff0000', + backgroundColor: '#ff5941', borderRadius: 25, paddingVertical: 10, paddingHorizontal: 20,