Skip to content

Commit

Permalink
chore: improve reset password alert
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Nov 25, 2023
1 parent 2d897a8 commit 92e7168
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 19 deletions.
34 changes: 34 additions & 0 deletions components/ResetPassword/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { resetPassword } from "@lib/api";
import Swal from "sweetalert2";

const onResetPassword = (user: any) => {
resetPassword(user.email)
.then((_) =>
Swal.fire({
icon: "success",
title: "Password Reset",
text: "An email has been sent to your account for you to recover your password!",
})
)
.catch((_) => {
Swal.fire({
icon: "error",
title: "Oops...",
text: "Something went wrong!",
});
});
};

export default function ResetPassword(user) {
return (
<button
className="inline-block h-auto pl-6 pb-5 text-quinary underline"
onClick={(e) => {
e.preventDefault();
onResetPassword(user);
}}
>
Reset Password
</button>
);
}
21 changes: 2 additions & 19 deletions layout/Attendee/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Input from "@components/Input";

import Layout from "@components/Layout";
import Heading from "@components/Heading";
import ResetPassword from "@components/ResetPassword";

import { CheckpointTracker, CodeInput } from "./components";
import CVInput from "./components/CVInput";
Expand Down Expand Up @@ -46,16 +47,6 @@ function Profile() {

const levelEntries = [10, 30, 60, 100, 150];

const onResetPassword = () => {
resetPassword(user.email)
.then((_) =>
alert(
"An email has been sent to your account for you to recover your password"
)
)
.catch((_) => alert("An error occured"));
};

const handleSubmitForm = (e: React.FormEvent) => {
e.preventDefault();
const formData = new FormData();
Expand Down Expand Up @@ -152,15 +143,7 @@ function Profile() {
onChange={(e) => setUsername(e.currentTarget.value)}
/>

<button
className="inline-block h-auto pl-6 pb-5 text-quinary underline"
onClick={(e) => {
e.preventDefault();
onResetPassword();
}}
>
Reset Password
</button>
<ResetPassword user={user} />
</Form>
</div>

Expand Down
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-map-gl": "^6.1.17",
"react-p5": "^1.3.21",
"sharp": "^0.30.0",
"sweetalert2": "^11.10.1",
"typewriter-effect": "^2.21.0"
},
"devDependencies": {
Expand Down

0 comments on commit 92e7168

Please sign in to comment.