-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientProfile.jsx
More file actions
92 lines (80 loc) · 2.64 KB
/
ClientProfile.jsx
File metadata and controls
92 lines (80 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import "./styles.css";
import { useState } from "react";
import { toast } from "react-toastify";
import { useNavigate } from "react-router-dom";
import "react-toastify/dist/ReactToastify.css";
import axiosBaseUrl from "../../../Axios/axios";
import InputField from "../../../Components/CommonComponents/InputField/InputField";
import ActionButton from "../../../Components/CommonComponents/ActionButton/ActionButton";
const ClientProfile = () => {
const [currentPassword, setCurrentPassword] = useState("");
const [newPassword, setNewPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();
if (newPassword !== confirmPassword) {
toast.error("New password and confirmation do not match.");
return;
}
const password = newPassword;
try {
const response = await axiosBaseUrl.post("/clients/editProfile", {
password,
});
if (response.data.success) {
toast.success("Password updated successfully.");
setTimeout(() => navigate("/client/dashboard"), 1000);
} else {
toast.error(response.data.message || "Failed to update password.");
}
} catch (error) {
toast.error("An error occurred. Please try again.");
}
};
return (
<div className="client-profile-container">
<h2>Change Password</h2>
<form className="password-form" onSubmit={handleSubmit}>
<div className="form-group">
<InputField
label="Current Password"
placeholder="Enter current password"
value={currentPassword}
onChange={(e) => setCurrentPassword(e.target.value)}
type="password"
width="90%"
/>
</div>
<div className="form-group">
<InputField
label="New Password"
placeholder="Enter new password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
type="password"
width="90%"
/>
</div>
<div className="form-group">
<InputField
label="Confirm New Password"
placeholder="Confirm new password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
type="password"
width="90%"
/>
</div>
<ActionButton
text="Save Changes"
backgroundColor="#233A7E"
color="#FFF"
width="50%"
margin="20px 0 0"
/>
</form>
</div>
);
};
export default ClientProfile;