diff --git a/src/components/Forms/UserAccount/index.jsx b/src/components/Forms/UserAccount/index.jsx index 32667927..54944d78 100644 --- a/src/components/Forms/UserAccount/index.jsx +++ b/src/components/Forms/UserAccount/index.jsx @@ -1,9 +1,54 @@ -import React from "react"; -import { Box, Card, Typography } from "@mui/material"; +import React, {useState} from "react"; +import { Box, Card, Typography, Button,Modal, Backdrop, Fade, CircularProgress } from "@mui/material"; import useStyles from "./styles"; +import firebase from "firebase/compat/app"; +import "firebase/compat/auth"; +import { useHistory } from "react-router-dom"; + +const style = { + position: 'absolute', + top: '50%', + left: '50%', + transform: 'translate(-50%, -50%)', + width: 400, + bgcolor: 'background.paper', + border: '2px solid #000', + boxShadow: 24, + p: 4, +}; const UserAccount = () => { const classes = useStyles(); + const [deleting, setDeleting] = useState(false); + const [error, setError] = useState(null); + const [open, setOpen] = useState(false); + const [isAccountDeactivated, setIsAccountDeactivated] = useState(false) + const history = useHistory(); + + const handleOpenModal = () => { + setOpen(true); + }; + + const handleCloseModal = () => { + setOpen(false); + }; + + const handleDeleteAccount = () => { + setDeleting(true); + setError(null); + + const user = firebase.auth().currentUser; + + user.delete().then(() => { + console.log('User Account deleted successfully'); + history.push("/login"); + }).catch(error => { + console.log('Error deleting user account: ',error); + setError(error.message); + }).finally(() => { + setDeleting(false); + }); + } return ( @@ -40,20 +85,54 @@ const UserAccount = () => { Add successor - + + {error && {error}} + + + {/* Modal for confirmation */} + - Delete account - + + + + Are you sure you want to delete your account? + + + + + + + + );