-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from TaskRatchet/pre-initial-release-changes
delete account functionality
- Loading branch information
Showing
12 changed files
with
1,594 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ Identity/ | |
devReferances | ||
*.log | ||
yarn.lock | ||
.env | ||
|
||
# OSX | ||
# | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import {useMutation} from '@tanstack/react-query'; | ||
import React from 'react'; | ||
import {Modal, Pressable, Text, View} from 'react-native'; | ||
|
||
import deleteMe from '../services/taskratchet/deleteMe'; | ||
import {styles} from '../styles/deleteAccountPopupStyle'; | ||
import PressableLoading from './pressableLoading'; | ||
import type {DeleteAccountPopupProps} from './types'; | ||
|
||
export default function DeleteAccountPopup({ | ||
navigation, | ||
modalVisible, | ||
setModalVisible, | ||
}: DeleteAccountPopupProps) { | ||
const mutation = useMutation({ | ||
mutationFn: deleteMe, | ||
onError: error => { | ||
console.log('delete account error ' + String(error)); | ||
}, | ||
}); | ||
|
||
return ( | ||
<View> | ||
<Modal visible={modalVisible} transparent={true} animationType="none"> | ||
<View style={styles.centeredView}> | ||
<View style={styles.modalView}> | ||
<Text style={styles.title}>Delete Account</Text> | ||
{mutation.isSuccess ? ( | ||
<> | ||
<Text style={styles.description}> | ||
Your account has been successfully deleted. | ||
</Text> | ||
<Pressable | ||
style={({pressed}) => [ | ||
{ | ||
backgroundColor: pressed | ||
? 'rgba(33, 150, 243, 0.5)' | ||
: '#2196F3', | ||
}, | ||
styles.cancelButton, | ||
]}> | ||
<Text | ||
style={styles.textStyle} | ||
onPress={() => { | ||
setModalVisible(false); | ||
navigation?.navigate('LoginScreen'); | ||
}}> | ||
Logout | ||
</Text> | ||
</Pressable> | ||
</> | ||
) : ( | ||
<> | ||
<Text style={styles.description}> | ||
Are you sure you want to delete your account? This will | ||
permanently delete all data associated with your account, and | ||
you will no longer be able to access your account in the app | ||
or online. This action cannot be undone. | ||
</Text> | ||
<PressableLoading | ||
style={({pressed}) => [ | ||
{ | ||
backgroundColor: pressed ? 'rgba(255, 0, 0, 0.5)' : 'red', | ||
}, | ||
styles.confirmButton, | ||
]} | ||
onPress={() => mutation.mutate()} | ||
loading={mutation.isPending} | ||
loadingTextStyle={styles.loadingText}> | ||
<Text style={styles.textStyle}>Confirm</Text> | ||
</PressableLoading> | ||
<Pressable | ||
onPress={() => setModalVisible(false)} | ||
style={({pressed}) => [ | ||
{ | ||
backgroundColor: pressed | ||
? 'rgba(33, 150, 243, 0.5)' | ||
: '#2196F3', | ||
}, | ||
styles.cancelButton, | ||
]}> | ||
<Text style={styles.textStyle}>Cancel</Text> | ||
</Pressable> | ||
{mutation.error ? ( | ||
<> | ||
<Text style={styles.error}>Failed to Delete Account</Text> | ||
<Text style={styles.error}> | ||
Please email [email protected] | ||
</Text> | ||
</> | ||
) : null} | ||
</> | ||
)} | ||
</View> | ||
</View> | ||
</Modal> | ||
</View> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import {useQuery} from '@tanstack/react-query'; | ||
import React from 'react'; | ||
import {Button, Image, ImageSourcePropType, Text, View} from 'react-native'; | ||
import React, {useState} from 'react'; | ||
import {Image, ImageSourcePropType, Pressable, Text, View} from 'react-native'; | ||
import {SafeAreaView} from 'react-native-safe-area-context'; | ||
|
||
import logo from '../../assets/images/[email protected]'; | ||
import DeleteAccountPopup from '../components/deleteAccountPopup'; | ||
import {Props} from '../components/types'; | ||
import themeProvider from '../providers/themeProvider'; | ||
import {getMe} from '../services/taskratchet/getMe'; | ||
import {styles} from '../styles/profileScreenStyle'; | ||
import useIsDarkMode from '../utils/checkDarkMode'; | ||
|
||
export default function ProfileScreen({navigation}: Props) { | ||
const [modalVisible, setModalVisible] = useState(false); | ||
|
||
const isDarkMode = useIsDarkMode(); | ||
const backgroundStyle = { | ||
backgroundColor: isDarkMode | ||
|
@@ -38,6 +41,12 @@ export default function ProfileScreen({navigation}: Props) { | |
source={logo as ImageSourcePropType} | ||
/> | ||
|
||
<DeleteAccountPopup | ||
navigation={navigation} | ||
modalVisible={modalVisible} | ||
setModalVisible={setModalVisible} | ||
/> | ||
|
||
<View style={styles.profileTitle}> | ||
<Text style={[textColorStyle, styles.name]}>Profile</Text> | ||
</View> | ||
|
@@ -79,11 +88,36 @@ export default function ProfileScreen({navigation}: Props) { | |
<Text>Loading...</Text> | ||
)} | ||
<View style={styles.buttons}> | ||
<Button | ||
title="Go to Home" | ||
onPress={() => navigation.navigate('HomeScreen')} | ||
/> | ||
<Button title="Logout" onPress={goToLoginScreen} /> | ||
<Pressable onPress={() => navigation?.navigate('HomeScreen')}> | ||
{({pressed}) => ( | ||
<Text | ||
// eslint-disable-next-line react-native/no-inline-styles | ||
style={[styles.button, {color: pressed ? 'blue' : '#0178FA'}]}> | ||
Go to Home | ||
</Text> | ||
)} | ||
</Pressable> | ||
<Pressable onPress={goToLoginScreen}> | ||
{({pressed}) => ( | ||
<Text | ||
// eslint-disable-next-line react-native/no-inline-styles | ||
style={[styles.button, {color: pressed ? 'blue' : '#0178FA'}]}> | ||
Logout | ||
</Text> | ||
)} | ||
</Pressable> | ||
<Pressable | ||
onPress={() => setModalVisible(true)} | ||
style={({pressed}) => [ | ||
{ | ||
backgroundColor: pressed ? 'rgba(255, 0, 0, 0.5)' : 'red', | ||
}, | ||
styles.deleteAccountButton, | ||
]}> | ||
<Text style={[textColorStyle, styles.deleteAccount]}> | ||
Delete Account | ||
</Text> | ||
</Pressable> | ||
</View> | ||
</View> | ||
</SafeAreaView> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import fetch2 from './fetch2'; | ||
|
||
export default async function deleteMe(): Promise<void> { | ||
await fetch2('me', true, 'DELETE'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import secureKeystore from 'react-native-secure-key-store'; | ||
|
||
import {API2_BASE} from './constants'; | ||
import {logout} from './sessions'; | ||
|
||
const _trim = (s: string, c: string) => { | ||
if (c === ']') { | ||
c = '\\]'; | ||
} | ||
if (c === '\\') { | ||
c = '\\\\'; | ||
} | ||
return s.replace(new RegExp('^[' + c + ']+|[' + c + ']+$', 'g'), ''); | ||
}; | ||
|
||
export default async function fetch2( | ||
route: string, | ||
protected_ = false, | ||
method = 'GET', | ||
data: unknown = null, | ||
): Promise<Response> { | ||
const token = ((await secureKeystore.get('firebase_token')) as string) || ''; | ||
const route_ = _trim(route, '/'); | ||
|
||
if (protected_ && !token) { | ||
throw new Error('User not logged in'); | ||
} | ||
|
||
// noinspection SpellCheckingInspection | ||
const response = await fetch(API2_BASE + route_, { | ||
method: method, | ||
body: data ? JSON.stringify(data) : undefined, | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}); | ||
|
||
if (response.status === 403) { | ||
await logout(); | ||
} | ||
|
||
return response; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import {StyleSheet} from 'react-native'; | ||
|
||
export const styles = StyleSheet.create({ | ||
centeredView: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
marginTop: 22, | ||
}, | ||
modalView: { | ||
width: '90%', | ||
backgroundColor: 'white', | ||
borderRadius: 20, | ||
padding: 35, | ||
shadowColor: '#000', | ||
shadowOffset: { | ||
width: 0, | ||
height: 2, | ||
}, | ||
shadowOpacity: 0.25, | ||
shadowRadius: 4, | ||
elevation: 5, | ||
}, | ||
title: { | ||
fontSize: 24, | ||
fontWeight: 'bold', | ||
textAlign: 'center', | ||
}, | ||
confirmButton: { | ||
borderRadius: 20, | ||
margin: 5, | ||
padding: 10, | ||
elevation: 2, | ||
}, | ||
cancelButton: { | ||
borderRadius: 20, | ||
margin: 5, | ||
padding: 10, | ||
elevation: 2, | ||
}, | ||
textStyle: { | ||
fontSize: 18, | ||
color: 'white', | ||
fontWeight: 'bold', | ||
textAlign: 'center', | ||
}, | ||
error: { | ||
color: 'red', | ||
textAlign: 'center', | ||
}, | ||
loadingText: { | ||
fontSize: 18, | ||
color: 'white', | ||
fontWeight: 'bold', | ||
textAlign: 'center', | ||
}, | ||
description: { | ||
marginBottom: 20, | ||
marginTop: 20, | ||
textAlign: 'center', | ||
fontSize: 16, | ||
}, | ||
}); |
Oops, something went wrong.