From cd75cfa999e198beeebf42f84c431a6b2321bfad Mon Sep 17 00:00:00 2001 From: Aditya Pawar Date: Thu, 13 Jun 2024 16:43:01 -0700 Subject: [PATCH 1/3] Add delete users functionality --- README.md | 6 ++- src/app/(tabs)/settings/index.tsx | 67 ++++++++++++++++++++++++++++++- src/app/index.tsx | 1 + src/queries/auth.tsx | 8 ++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 479822bd..0550132b 100644 --- a/README.md +++ b/README.md @@ -5,16 +5,21 @@ This project is designed and developed by a team of UC Berkeley students through Learn more about [Girls Write Now](https://girlswritenow.org/) and [Cal Blueprint](https://calblueprint.org/). ## App Preview + ### Story Search/Filtering + https://github.com/calblueprint/girls-write-now/assets/34043950/6277c625-fa8a-495d-b2eb-ba70807cfd87 ### Story Recommendation + ![Simulator Screen Recording - iPhone 15 - 2024-04-25 at 14 09 19](https://github.com/calblueprint/girls-write-now/assets/34043950/6a92dbf7-be0e-4210-8a66-35fddd578fee) ### Saving/Favoriting Stories + ![saved stories](https://github.com/calblueprint/girls-write-now/assets/34043950/e40b5a50-d53c-497a-8b70-433def6dde67) ### Reacting To Stories + ![reactions](https://github.com/calblueprint/girls-write-now/assets/34043950/32d5c54e-5a4e-4517-8475-ea38b2e4cf69) --- @@ -77,4 +82,3 @@ We strongly recommend using a Node version manager like [nvm](https://github.com - **Expo Go (Recommended)**: [download Expo Go](https://docs.expo.dev/get-started/installation/#2-expo-go-app-for-android-and) on your phone, **connect to same network as your laptop**, and use your phone camera to scan the QR code displayed in the command line. - Web: typing `w` into the expo command line opens the app in a web view. - Warning: since the app is designed to be used on a mobile app, web compatibility might be limited, and some functionality might be different when using the web setup. - diff --git a/src/app/(tabs)/settings/index.tsx b/src/app/(tabs)/settings/index.tsx index 0b0115ac..f5c28eab 100644 --- a/src/app/(tabs)/settings/index.tsx +++ b/src/app/(tabs)/settings/index.tsx @@ -7,6 +7,7 @@ import { Platform, Pressable, Appearance, + TouchableOpacity, } from 'react-native'; import { Icon } from 'react-native-elements'; import { ScrollView } from 'react-native-gesture-handler'; @@ -22,6 +23,7 @@ import colors from '../../../styles/colors'; import globalStyles from '../../../styles/globalStyles'; import { useSession } from '../../../utils/AuthContext'; import supabase from '../../../utils/supabase'; +import { deleteUser } from '../../../queries/auth'; /* * This screen shows the user's profile information, and allows the user to edit profile information. @@ -114,6 +116,37 @@ function SettingsScreen() { if (!session) resetAndPushToRouter('/auth/login'); }, [session]); + const showAlert = () => + Alert.alert( + 'Are you sure you want to delete your account?', + '', + [ + { + text: 'Cancel', + onPress: () => {}, + style: 'cancel', + }, + { + text: 'OK', + onPress: onDelete, + style: 'destructive', + }, + ], + { + cancelable: true, + onDismiss: () => {}, + }, + ); + + const onDelete = async () => { + const uuid = session?.user.id; + + if (uuid) { + deleteUser(uuid); + signOut(); + } + }; + const updateProfile = async () => { try { setLoading(true); @@ -206,7 +239,39 @@ function SettingsScreen() { Settings - Account + + Account + + + ( + + + + Delete account + + + + ) + + + diff --git a/src/app/index.tsx b/src/app/index.tsx index ac213e24..176d24c6 100644 --- a/src/app/index.tsx +++ b/src/app/index.tsx @@ -3,6 +3,7 @@ import { useEffect, useState } from 'react'; import SplashScreen from '../components/SplashScreen/SplashScreen'; import { useSession } from '../utils/AuthContext'; + import { useFonts, Manrope_700Bold, diff --git a/src/queries/auth.tsx b/src/queries/auth.tsx index 1114153f..74fc7165 100644 --- a/src/queries/auth.tsx +++ b/src/queries/auth.tsx @@ -16,3 +16,11 @@ export const queryEmailByUsername = async (username: string) => { .limit(1) .eq('username', username); }; + +export const deleteUser = async (uuid: string) => { + let { data, error } = await supabase.rpc('delete_user', { + uuid, + }); + if (error) console.error(error); + else console.log(data); +}; From deacf10b18a0bf42270ba07e4926c721e2673d0e Mon Sep 17 00:00:00 2001 From: Aditya Pawar Date: Thu, 13 Jun 2024 16:48:00 -0700 Subject: [PATCH 2/3] Finish --- src/app/(tabs)/settings/index.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/(tabs)/settings/index.tsx b/src/app/(tabs)/settings/index.tsx index f5c28eab..7787edf0 100644 --- a/src/app/(tabs)/settings/index.tsx +++ b/src/app/(tabs)/settings/index.tsx @@ -121,20 +121,20 @@ function SettingsScreen() { 'Are you sure you want to delete your account?', '', [ - { - text: 'Cancel', - onPress: () => {}, - style: 'cancel', - }, { text: 'OK', onPress: onDelete, style: 'destructive', }, + { + text: 'Cancel', + onPress: () => { }, + style: 'cancel', + }, ], { cancelable: true, - onDismiss: () => {}, + onDismiss: () => { }, }, ); From d03e93391b7ff29b131f0ea77fee877e53c3b26b Mon Sep 17 00:00:00 2001 From: Aditya Pawar Date: Thu, 13 Jun 2024 16:50:23 -0700 Subject: [PATCH 3/3] Run prettier --- src/app/(tabs)/settings/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/(tabs)/settings/index.tsx b/src/app/(tabs)/settings/index.tsx index 7787edf0..acafa68e 100644 --- a/src/app/(tabs)/settings/index.tsx +++ b/src/app/(tabs)/settings/index.tsx @@ -128,13 +128,13 @@ function SettingsScreen() { }, { text: 'Cancel', - onPress: () => { }, + onPress: () => {}, style: 'cancel', }, ], { cancelable: true, - onDismiss: () => { }, + onDismiss: () => {}, }, );