-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClientProfile.jsx
More file actions
95 lines (83 loc) · 2.78 KB
/
ClientProfile.jsx
File metadata and controls
95 lines (83 loc) · 2.78 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
93
94
95
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 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">
<h4 htmlFor="current-password">Current Password:</h4>
<input
id="current-password"
type="password"
placeholder="Enter current password"
value={currentPassword}
onChange={(e) => setCurrentPassword(e.target.value)}
required
/>
</div>
<div className="form-group">
<h4 htmlFor="new-password">New Password:</h4>
<input
id="new-password"
type="password"
placeholder="Enter new password"
value={newPassword}
onChange={(e) => setNewPassword(e.target.value)}
required
/>
</div>
<div className="form-group">
<h4 htmlFor="confirm-password">Confirm New Password:</h4>
<input
id="confirm-password"
type="password"
placeholder="Confirm new password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
required
/>
</div>
<ActionButton
text="Save Changes"
backgroundColor="#233A7E"
color="#FFF"
width="100%"
margin="20px 0 0"
/>
{/* {message && <p className="form-message">{message}</p>} */}
</form>
</div>
);
};
export default ClientProfile;