Skip to content
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
92 changes: 87 additions & 5 deletions amp-client/src/Pages/ClientPages/ClientProfile/ClientProfile.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,94 @@
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>Client Profile</h2>
</div>
</>
<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>
);
};

Expand Down
48 changes: 46 additions & 2 deletions amp-client/src/Pages/ClientPages/ClientProfile/styles.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,47 @@
.client-profile-container {
padding: 20px;
}
padding: 20px;
background-color: #fff9f3;
max-width: 500px;
margin: 50px auto;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

h2 {
margin-bottom: 30px;
}

.password-form {
display: flex;
flex-direction: column;
}

.form-group {
margin-bottom: 20px;
}

.form-group h4 {
display: block;
margin-bottom: 5px;
}

.password-form input {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 6px;
width: 95%;
}

.form-message {
margin-top: 15px;
color: #d00;
font-weight: 500;
}

.password-form label {
font-weight: 500;
margin-bottom: 5px;
margin-top: 10px;
display: block;
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,38 +532,6 @@ const ProviderDashboard = () => {
<p>No detailed metrics data available.</p>
)}
</div>

{/* <div className="chart-widget all-metrics-widget">
<h3>All Metrics</h3>
{allMetrics && Object.keys(allMetrics).length > 0 ? (
<table>
<thead>
<tr>
<th>ID</th>
<th>Voltage</th>
<th>Current</th>
<th>Power</th>
<th>Energy</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody>
{allMetrics.map((metric, index) => (
<tr key={metric.id}>
<td>{metric.id}</td>
<td>{metric.voltage}</td>
<td>{metric.current}</td>
<td>{metric.power}</td>
<td>{metric.energy}</td>
<td>{new Date(metric.created_at).toLocaleString()}</td>
</tr>
))}
</tbody>
</table>
) : (
<p>No detailed metrics data available.</p>
)}
</div> */}
</div>
)}
</div>
Expand Down
2 changes: 0 additions & 2 deletions amp-laravel/app/Http/Requests/Client/EditProfileRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ public function authorize(): bool
public function rules(): array
{
return [
'name' => 'sometimes|required|string|max:255',
'email' => 'sometimes|required|email|max:255',
'password' => 'sometimes|nullable|string|min:6',
];
}
Expand Down
8 changes: 0 additions & 8 deletions amp-laravel/app/Services/Client/ClientEditProfileService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ class ClientEditProfileService
public static function editProfile(array $data)
{
$user = JWTAuth::user();

if (isset($data['name'])) {
$user->name = $data['name'];
}

if (isset($data['email'])) {
$user->email = $data['email'];
}

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