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