Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete account view #461

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions frontend/src/api/accountApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import axios from "axios";
import { Constants } from "../config/constants";

const api = axios.create({
baseURL: `${Constants.idpUrl}/api`
});

const AccountApi = {
deleteAccount: (user, password) =>
api.post("/DeleteAccount", { Username: user, Password: password })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we pass the user and not taking it from the session ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point! Had a chat with @RaduCStefanescu and my takeaway was we need to ask for them to type the email and password. It might be that I got it wrong and we only need to ask for the password. @RaduCStefanescu can you clarify if there is a requirement to ask the user to put in the email?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on this comment I'm guessing he's on-board with the idea 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool! I will update the PR accordingly

};

export default AccountApi;
2 changes: 2 additions & 0 deletions frontend/src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ export const getUserToken = async () => {
}
return user.access_token;
};

export const removeUser = () => userManager.removeUser();
81 changes: 81 additions & 0 deletions frontend/src/components/DeleteAccount/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React, { useState } from "react";
import SidebarLayout from "../SidebarLayout";
import AccountApi from "../../api/accountApi";
import "./style.scss";
import { removeUser } from "../../api/auth";
const DeleteAccount = () => {
const [user, setUser] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const [errorDeleting, setErrorDeleting] = useState(false);

const fieldsFilled = user && password;

const updateUser = event => setUser(event.target.value);
const updatePassword = event => setPassword(event.target.value);

const deleteProfile = () => {
setLoading(true);
AccountApi.deleteAccount(user, password)
.then(() => {
setLoading(false);
})
.then(removeUser)
.catch(() => {
setErrorDeleting(true);
setLoading(false);
});
};

const buttonClasses = "button is-danger" + (loading ? " is-loading" : "");
return (
<SidebarLayout>
<div>
Contul tău va fi șters. Pentru a putea reutiliza această aplicație va
trebui să îți refaci contul de utilizator. Informațiile pe care le-ai
transmis până acum prin intermediul aplicație vor rămâne stocate în baza
de date. Dacă dorești ca toate informațiile să fie eliminate din baza de
date te rugăm să adresezi această cerere către:
<p>Adresa: Strada Italiană, nr. 22, Sector 2, 020976, București</p>
<p>E-mail: [email protected]</p>
</div>
<form onSubmit={() => {}}>
<div className="field">
<label className="label">Email</label>
<input
className="input is-medium"
type="text"
placeholder="Email"
value={user}
onChange={updateUser}
/>
</div>
<div className="field">
<label className="label">Parola</label>
<input
className="input is-medium"
type="password"
placeholder="Parola"
value={password}
onChange={updatePassword}
/>
</div>
<div className="field">
<button
className={buttonClasses}
onClick={deleteProfile}
disabled={!fieldsFilled || loading}
>
Șterge cont
</button>
</div>
</form>
<div className="notification is-warning" hidden={!errorDeleting}>
<button className="delete" onClick={() => setErrorDeleting(false)} />
Încercarea de ștergere a eșuat!
</div>
</SidebarLayout>
);
};

export default DeleteAccount;
3 changes: 3 additions & 0 deletions frontend/src/components/DeleteAccount/style.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.notification {
margin-top: 1em;
}
1 change: 1 addition & 0 deletions frontend/src/components/Header/ProfileItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ProfileItems = () => {
<NavLink to="/account">Contul meu</NavLink>
<div className="account-separator" />
<button onClick={handleLogout}>Logout</button>
<NavLink to="/delete-account">Ștergere cont</NavLink>
</>
) : (
<>
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UpdateProfile from "./components/UpdateProfile";
import Evaluation from "./components/Evaluation";
import Account from "./components/Account";
import TermsAndConditions from "./components/TermsAndConditions";
import DeleteAccount from "./components/DeleteAccount";

import {
redirectSilentSignin,
Expand Down Expand Up @@ -75,6 +76,10 @@ export const ROUTES = {
updateprofile: {
path: "/update-profile",
component: UpdateProfile
},
deleteaccount: {
path: "/delete-account",
component: DeleteAccount
}
}
};
2 changes: 2 additions & 0 deletions frontend/src/styles/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
@import "~bulma/sass/utilities/_all.sass";
@import "~bulma/sass/base/_all.sass";
@import "~bulma/sass/elements/container.sass";
@import "~bulma/sass/elements/notification.sass";
@import "~bulma/sass/elements/other.sass";
@import "~bulma/sass/grid/columns.sass";

@import "~bulma/sass/components/tabs";