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

Change password is added to the profile and integrated with backend #1030

Merged
merged 1 commit into from
Dec 18, 2023
Merged
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
7 changes: 6 additions & 1 deletion app/frontend/src/Components/Profile/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ function EditProfile({ profile }: { profile: any }) {

return (
<>
<Button icon={<EditFilled />} type="primary" onClick={showModal}>
<Button
size="small"
icon={<EditFilled />}
type="primary"
onClick={showModal}
>
Edit Profile
</Button>
<Modal
Expand Down
36 changes: 23 additions & 13 deletions app/frontend/src/Pages/ChangePassword/ChangePassword.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { Button, Form, Input, Card, message } from "antd";
import styles from "./ChangePassword.module.scss";
import { changePassword } from "../../Services/changepassword";
import { useNavigate } from "react-router-dom";

const ChangePassword = () => {
const [form] = Form.useForm();
const navigate = useNavigate();

const handleChangePassword = async (event: any) => {
const { currentPassword, newPassword } = event;
try {
const response = await changePassword(currentPassword, newPassword);
if (response?.status == 200) {
message.success("Password is changed successfully!");
navigate("/profile");
}
} catch (error: any) {
message.error(error.message);
return;
}

const handleChangePassword = () => {
/*
const values = form.getFieldsValue();

const body = {
email: values.email,
new_password: values.new_password,
};
*/
message.success("Password is changed successfully!");
};

Expand All @@ -29,23 +36,26 @@ const ChangePassword = () => {
onFinishFailed={onFinishFailed}
size="large"
>
<Form.Item name="password" rules={[{ required: true, message: "" }]}>
<Form.Item
name="currentPassword"
rules={[{ required: true, message: "" }]}
>
<Input placeholder="Password" />
</Form.Item>

<Form.Item name="newpassword" rules={[{ required: true, message: "" }]}>
<Form.Item name="newPassword" rules={[{ required: true, message: "" }]}>
<Input.Password placeholder="Enter a new password" />
</Form.Item>
<Form.Item
name="conf-password"
dependencies={["newpassword"]}
dependencies={["newPassword"]}
rules={[
{
required: true,
},
({ getFieldValue }) => ({
validator(_, value) {
if (!value || getFieldValue("newpassword") === value) {
if (!value || getFieldValue("newPassword") === value) {
return Promise.resolve();
}
return Promise.reject(
Expand Down
8 changes: 4 additions & 4 deletions app/frontend/src/Pages/Profile/Profile.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
padding: 0.5em;
position: relative;

.edit {
position: absolute;
top: 1em;
right: 1em;
.settings {
display: flex;
justify-content: flex-end;
gap: 5px;
}

.profilePicture {
Expand Down
23 changes: 18 additions & 5 deletions app/frontend/src/Pages/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { PacmanLoader } from "react-spinners";
import { useAuth } from "../../Components/Hooks/useAuth";
import styles from "./Profile.module.scss";
import { useQueryClient } from "react-query";
import { Popover } from "antd";
import { Button, Popover } from "antd";
import { useState } from "react";
import EditProfile from "../../Components/Profile/EditProfile";
import ProfileIcon from "../../Components/Icons/ProfileIcon";
import ProfileAchievements from "../../Components/Profile/ProfileAchievements/ProfileAchievements";
import LastActivities from "../../Components/LastActivities/LastActivities";
import { SyncOutlined } from "@ant-design/icons";
import { useNavigate } from "react-router-dom";
const subPages = ["Achievements", "Last Activities"];
function Profile() {
const { user, isLoading, profile } = useAuth();
const [subPage, setSubPage] = useState(subPages[0]);

const navigate = useNavigate();
return (
<div className={styles.profilePage}>
{isLoading ? (
Expand All @@ -21,9 +24,6 @@ function Profile() {
) : (
<>
<div className={styles.profileCard}>
<div className={styles.edit}>
<EditProfile profile={profile} key={profile?.id} />
</div>
<div className={styles.profilePicture}>
{profile.profilePhoto ? (
<img
Expand All @@ -36,6 +36,19 @@ function Profile() {
)}
</div>
<div className={styles.profileDetails}>
<div className={styles.settings}>
<EditProfile profile={profile} key={profile?.id} />

<Button
icon={<SyncOutlined />}
type="primary"
onClick={() => navigate("/change-password")}
size="small"
>
Change Password
</Button>
</div>

<div className={styles.profileName}>
<h1>{user.username}</h1>
<span>{user.email}</span>
Expand Down
14 changes: 14 additions & 0 deletions app/frontend/src/Services/changepassword.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import axios from "axios";

export async function changePassword(
currentPassword: string,
newPassword: string
) {
try {
const response = await axios.post(
`${import.meta.env.VITE_APP_API_URL}/auth/change-password`,
{ currentPassword, newPassword }
);
return response;
} catch (error) {}
}
2 changes: 1 addition & 1 deletion app/frontend/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const router = createBrowserRouter([
element: <ForgotPassword />,
},
{
path: "change",
path: "change-password",
element: <ChangePassword />,
},
{
Expand Down