Skip to content

Commit 9264728

Browse files
authored
Merge pull request #146 from Riyad-Murad/client_profile_dev
Client profile dev
2 parents 1150306 + f5b6302 commit 9264728

File tree

5 files changed

+133
-49
lines changed

5 files changed

+133
-49
lines changed

amp-client/src/Pages/ClientPages/ClientProfile/ClientProfile.jsx

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,94 @@
11
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";
28

39
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+
442
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>
1092
);
1193
};
1294

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
11
.client-profile-container {
2-
padding: 20px;
3-
}
2+
padding: 20px;
3+
background-color: #fff9f3;
4+
max-width: 500px;
5+
margin: 50px auto;
6+
border-radius: 10px;
7+
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
8+
}
9+
10+
h2 {
11+
margin-bottom: 30px;
12+
}
13+
14+
.password-form {
15+
display: flex;
16+
flex-direction: column;
17+
}
18+
19+
.form-group {
20+
margin-bottom: 20px;
21+
}
22+
23+
.form-group h4 {
24+
display: block;
25+
margin-bottom: 5px;
26+
}
27+
28+
.password-form input {
29+
padding: 10px;
30+
font-size: 16px;
31+
border: 1px solid #ccc;
32+
border-radius: 6px;
33+
width: 95%;
34+
}
35+
36+
.form-message {
37+
margin-top: 15px;
38+
color: #d00;
39+
font-weight: 500;
40+
}
41+
42+
.password-form label {
43+
font-weight: 500;
44+
margin-bottom: 5px;
45+
margin-top: 10px;
46+
display: block;
47+
}

amp-client/src/Pages/ProviderPages/ProviderDashboard/ProviderDashboard.jsx

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -532,38 +532,6 @@ const ProviderDashboard = () => {
532532
<p>No detailed metrics data available.</p>
533533
)}
534534
</div>
535-
536-
{/* <div className="chart-widget all-metrics-widget">
537-
<h3>All Metrics</h3>
538-
{allMetrics && Object.keys(allMetrics).length > 0 ? (
539-
<table>
540-
<thead>
541-
<tr>
542-
<th>ID</th>
543-
<th>Voltage</th>
544-
<th>Current</th>
545-
<th>Power</th>
546-
<th>Energy</th>
547-
<th>Timestamp</th>
548-
</tr>
549-
</thead>
550-
<tbody>
551-
{allMetrics.map((metric, index) => (
552-
<tr key={metric.id}>
553-
<td>{metric.id}</td>
554-
<td>{metric.voltage}</td>
555-
<td>{metric.current}</td>
556-
<td>{metric.power}</td>
557-
<td>{metric.energy}</td>
558-
<td>{new Date(metric.created_at).toLocaleString()}</td>
559-
</tr>
560-
))}
561-
</tbody>
562-
</table>
563-
) : (
564-
<p>No detailed metrics data available.</p>
565-
)}
566-
</div> */}
567535
</div>
568536
)}
569537
</div>

amp-laravel/app/Http/Requests/Client/EditProfileRequest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public function authorize(): bool
2222
public function rules(): array
2323
{
2424
return [
25-
'name' => 'sometimes|required|string|max:255',
26-
'email' => 'sometimes|required|email|max:255',
2725
'password' => 'sometimes|nullable|string|min:6',
2826
];
2927
}

amp-laravel/app/Services/Client/ClientEditProfileService.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ class ClientEditProfileService
99
public static function editProfile(array $data)
1010
{
1111
$user = JWTAuth::user();
12-
13-
if (isset($data['name'])) {
14-
$user->name = $data['name'];
15-
}
16-
17-
if (isset($data['email'])) {
18-
$user->email = $data['email'];
19-
}
2012

2113
if (!empty($data['password'])) {
2214
$user->password = bcrypt($data['password']);

0 commit comments

Comments
 (0)