Skip to content

Commit

Permalink
Merge pull request #265 from anqi20/branch-terminate-account
Browse files Browse the repository at this point in the history
Branch terminate account
  • Loading branch information
tsh22 authored Mar 2, 2022
2 parents f500157 + fbaf7cf commit 22e9b1c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 45 deletions.
28 changes: 27 additions & 1 deletion App.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ export default function App() {
}, []);

const authContext = {
terminateAccount: (data) => {
const usersRef = firebase.firestore().collection("users");
// Remove user data
usersRef
.doc(data.uid)
.delete()
.then(() => {
console.log(`Document ${data.uid} successfully deleted!`);

// Remove auth for user
data.user
.delete()
.then(() => {
setUser(null);
setValidated(false);
console.log(`User ${data.uid} account terminated!`);
})
.catch((error) => {
console.log(error);
console.log("Error terminating account");
});
})
.catch((error) => {
console.error("Error removing document: ", error);
});
},
signUpSuccess: () => {
if (!isValidated) {
console.log("sign up success");
Expand Down Expand Up @@ -228,7 +254,7 @@ export default function App() {
<SafeAreaProvider>
<AuthContext.Provider value={authContext}>
<NavigationContainer>
{console.log(isValidated)}
{console.log(`Authentication check isValidated? : ${isValidated}`)}
{user && isValidated ? (
<Stack.Navigator>
<Stack.Screen
Expand Down
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "GOZeroWaste",
"slug": "GOZeroWaste",
"version": "2.1.0",
"version": "2.2.3",
"orientation": "portrait",
"icon": "./assets/icons/icon.png",
"splash": {
Expand All @@ -29,7 +29,7 @@
"backgroundColor": "#FFFFFF"
},
"package": "com.tsh22.gozerowaste",
"versionCode": 2
"versionCode": 6
},
"web": {
"favicon": "./assets/icons/favicon.png"
Expand Down
8 changes: 4 additions & 4 deletions screens/settings-screens/MainSettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ const tabs = [
},
// {id: 2,
// title: "Feedback to us!"}
// {
// id: "4",
// title: "Terminate my account",
// },
{
id: "2",
title: "Terminate my account",
},
];
22 changes: 15 additions & 7 deletions screens/settings-screens/TerminateAccountScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import {
TouchableOpacity,
TouchableWithoutFeedback,
Keyboard,
Image,
} from "react-native";
import { Input } from "react-native-elements";
import colors from "../../assets/colors";
import { globalStyles } from "../../assets/globalStyles";
import { Entypo } from "@expo/vector-icons";
import firebase from "../../database/firebaseDB";

export default function TerminateAccountScreen({ navigation }) {
const [isMatching, setMatching] = useState(false);
const [showError, setShow] = useState(false);

const user = firebase.auth().currentUser;

function onPress() {
if (isMatching) {
setShow(false);
navigation.navigate("Account terminated");
navigation.navigate("Account terminated", { user: user });
} else {
setShow(true);
}
Expand All @@ -36,12 +39,11 @@ export default function TerminateAccountScreen({ navigation }) {
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.container}>
<Entypo
name="emoji-sad"
size={60}
color="black"
style={{ textAlign: "center", marginBottom: 20 }}
<Image
source={require("../../assets/AppImages/sadSmile.png")}
style={styles.sadSmile}
/>

<Text style={styles.boldText}>
Are you sure you want to terminate your account?
</Text>
Expand Down Expand Up @@ -105,4 +107,10 @@ const styles = StyleSheet.create({
terminateContainer: {
marginVertical: 20,
},
sadSmile: {
alignSelf: "center",
marginBottom: 20,
height: 60,
width: 60,
},
});
40 changes: 9 additions & 31 deletions screens/settings-screens/TerminateConfirmationScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,21 @@ import { globalStyles } from "../../assets/globalStyles";
import firebase from "../../database/firebaseDB";
import { AuthContext } from "../../assets/AuthContext";

export default function TerminateConfirmationScreen({ navigation }) {
function terminateAccount() {
return null;
// useEffect(() => {
// const usersRef = firebase.firestore().collection("users");
// firebase.auth().onAuthStateChanged((user) => {
// if (user) {
// // Remove user data
// usersRef
// .doc(user.uid)
// .delete()
// .then(() => {
// console.log("Document successfully deleted!");
// })
// .catch((error) => {
// console.error("Error removing document: ", error);
// });
export default function TerminateConfirmationScreen({ navigation, route }) {
const { user } = route.params;
const { terminateAccount } = useContext(AuthContext);

// // Remove auth for user
// user
// .delete()
// .then(() => {
// console.log("Account terminated");
// })
// .catch((error) => console.log("Error terminating account"));
// } else {
// console.log("No user");
// }
// });
// }, []);
const uid = user.uid;

function terminate() {
return terminateAccount({ user, uid });
}

return (
<View style={styles.container}>
<Text style={styles.boldText}>Account successfully terminated.</Text>
<TouchableOpacity style={globalStyles.button} onPress={terminateAccount}>
<Text style={globalStyles.buttonText}>Go to sign in page</Text>
<TouchableOpacity style={globalStyles.button} onPress={terminate}>
<Text style={globalStyles.buttonText}>Go to welcome screen</Text>
</TouchableOpacity>
</View>
);
Expand Down

0 comments on commit 22e9b1c

Please sign in to comment.