From db496d07a5e8eca463bf2d0bb2df15f51e286044 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 29 Nov 2025 01:56:09 -0500 Subject: [PATCH] testing the new Dash look --- client/src/containers/User/UserDash/Dash.css | 26 +- client/src/containers/User/UserDash/Dash.tsx | 549 ++++++++++++++++--- 2 files changed, 506 insertions(+), 69 deletions(-) diff --git a/client/src/containers/User/UserDash/Dash.css b/client/src/containers/User/UserDash/Dash.css index 59957cc..9ba5793 100644 --- a/client/src/containers/User/UserDash/Dash.css +++ b/client/src/containers/User/UserDash/Dash.css @@ -20,19 +20,33 @@ color: #555; } +.profile-img { + width: 80px; + height: 80px; + border-radius: 50%; + object-fit: cover; + margin-bottom: 15px; + border: 2px solid #007bff; +} + .user-info { - background: #f7f7f7; - padding: 20px; - border-radius: 12px; margin-bottom: 40px; } .info-grid { display: grid; - grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); + grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px; } +.info-card { + background: #f7f7f7; + padding: 15px; + border-radius: 12px; + box-shadow: 0 2px 6px rgba(0,0,0,0.1); + font-size: 0.95rem; +} + .chart-container { display: flex; flex-direction: column; @@ -45,10 +59,6 @@ margin-bottom: 30px; } -.pie-chart-wrapper { - margin: 0 20px; -} - .bar-chart-wrapper { overflow-x: auto; margin-top: 20px; diff --git a/client/src/containers/User/UserDash/Dash.tsx b/client/src/containers/User/UserDash/Dash.tsx index 6bdbb01..b8a345b 100644 --- a/client/src/containers/User/UserDash/Dash.tsx +++ b/client/src/containers/User/UserDash/Dash.tsx @@ -143,6 +143,398 @@ // export default Dash; +// import React, { useEffect, useState } from "react"; +// import { Link } from "react-router-dom"; +// import { +// PieChart, +// Pie, +// Cell, +// BarChart, +// Bar, +// XAxis, +// YAxis, +// CartesianGrid, +// Tooltip, +// Legend, +// ReferenceLine, +// Brush, +// } from "recharts"; +// import axios from "axios"; +// import "./Dash.css"; + +// const SERVER_PORT = process.env.REACT_APP_SOCKET_IO_CLIENT_PORT || "http://localhost:3001"; + +// // Colors for pie charts +// const PIE_COLORS = ["#0088FE", "#00C49F", "#FFBB28", "#FF8042"]; + +// const Dash = () => { +// const [userData, setUserData] = useState(null); +// const [loading, setLoading] = useState(true); +// const [error, setError] = useState(""); + +// // Fetch user data +// useEffect(() => { +// const userId = localStorage.getItem("userId"); +// if (!userId) { +// setError("User ID not found in local storage."); +// setLoading(false); +// return; +// } + +// const fetchUserData = async () => { +// try { +// const res = await axios.get(`${SERVER_PORT}/api/user/view/${userId}`); +// setUserData(res.data); +// } catch (err) { +// console.error("Error fetching user data:", err); +// setError("Failed to load user data."); +// } finally { +// setLoading(false); +// } +// }; + +// fetchUserData(); +// }, []); + +// if (loading) return
Loading user data...
; +// if (error) return
{error}
; + +// // Prepare chart data +// const barData = userData?.loadDetails?.map((load: any, idx: number) => ({ +// name: `Load ${idx + 1}`, +// weight: load.weight || 0, +// value: load.value || 0, +// })) || [{ name: "No Data", weight: 0, value: 0 }]; + +// const pieData = [ +// { name: "Available", value: userData.availableFrom ? 1 : 0 }, +// { name: "Unavailable", value: userData.availableFrom ? 0 : 1 }, +// ]; + +// return ( +//
+//
+//

Dashboard

+//

Welcome back, {userData.firstName}!

+//
+ +// {/* User Info */} +//
+//

User Information

+//
+//
+// Name: {userData.firstName} {userData.lastName} +//
+//
+// Email: {userData.email} +//
+//
+// Phone: {userData.phoneNumber || "Not provided"} +//
+//
+// Address: {userData.address || "Not provided"} +//
+//
+// Status: {userData.loadStatus || "N/A"} +//
+//
+// Customer Since:{" "} +// {userData.availableFrom +// ? new Date(userData.availableFrom).toLocaleDateString() +// : "N/A"} +//
+//
+// Type of Owner: {userData.userType || "N/A"} +//
+//
+// Experience Level: {userData.experienceLevel || "N/A"} +//
+//
+// Preferred Load: {userData.preferredLoadType || "N/A"} +//
+//
+// Company: {userData.company || "N/A"} +//
+//
+// Subscribed: {userData.subscribed ? "Yes" : "No"} +//
+//
+// Rating: {userData.rating || "N/A"} +//
+//
+//
+ +// {/* Charts */} +//
+//

Analytics

+ +// {/* Pie Chart */} +//
+// +// +// {pieData.map((entry, index) => ( +// +// ))} +// +// +// +//
+ +// {/* Bar Chart */} +//
+// +// +// +// +// +// +// +// +// +// +// +//
+//
+ +// +// Back to Home +// +//
+// ); +// }; + +// export default Dash; + +// import React, { useEffect, useState } from "react"; +// import { Link } from "react-router-dom"; +// import { +// PieChart, +// Pie, +// Cell, +// BarChart, +// Bar, +// XAxis, +// YAxis, +// CartesianGrid, +// Tooltip, +// Legend, +// ReferenceLine, +// Brush, +// } from "recharts"; +// import axios from "axios"; +// import "./Dash.css"; + +// const SERVER_PORT = process.env.REACT_APP_SOCKET_IO_CLIENT_PORT || "http://localhost:3001"; + +// // Colors for pie charts +// const PIE_COLORS = ["#0088FE", "#00C49F", "#FFBB28", "#FF8042"]; + +// interface LoadData { +// weight: number; +// value: number; +// rating: number; +// } + +// interface UserData { +// firstName: string; +// lastName: string; +// email: string; +// phoneNumber?: string; +// address?: string; +// loadStatus?: string; +// availableFrom?: string; +// userType?: string; +// experienceLevel?: string; +// preferredLoadType?: string; +// company?: string; +// subscribed?: boolean; +// rating?: number; +// profileImage?: string; +// loadDetails?: LoadData[]; +// } + +// const Dash: React.FC = () => { +// const [userData, setUserData] = useState(null); +// const [loading, setLoading] = useState(true); +// const [error, setError] = useState(""); + +// useEffect(() => { +// const userId = localStorage.getItem("userId"); +// if (!userId) { +// setError("User ID not found in local storage."); +// setLoading(false); +// return; +// } + +// const fetchUserData = async () => { +// try { +// const res = await axios.get(`${SERVER_PORT}/api/user/view/${userId}`); +// setUserData(res.data); +// } catch (err) { +// console.error("Error fetching user data:", err); +// setError("Failed to load user data."); +// } finally { +// setLoading(false); +// } +// }; + +// fetchUserData(); +// }, []); + +// if (loading) return
Loading user data...
; +// if (error) return
{error}
; +// if (!userData) return
No user data available.
; + +// const barData: LoadData[] = +// userData?.loadDetails?.map((load) => ({ +// weight: load.weight || 0, +// value: load.value || 0, +// rating: load.rating || 0, +// })) || [{ weight: 0, value: 0, rating: 0 }]; + +// const pieData = [ +// { name: "Available", value: userData.availableFrom ? 1 : 0 }, +// { name: "Unavailable", value: userData.availableFrom ? 0 : 1 }, +// ]; + +// // Find top-rated load for highlight +// const topLoadIndex = barData.reduce((maxIdx: number, currentLoad: LoadData, idx: number, arr: LoadData[]) => +// currentLoad.rating > arr[maxIdx].rating ? idx : maxIdx +// , 0); + +// return ( +//
+//
+// {userData.profileImage && ( +// Profile +// )} +//

Dashboard

+//

Welcome back, {userData.firstName}!

+//
+ +//
+//

User Information

+//
+//
+// Name: {userData.firstName} {userData.lastName} +//
+//
+// Email: {userData.email} +//
+//
+// Phone: {userData.phoneNumber || "Not provided"} +//
+//
+// Address: {userData.address || "Not provided"} +//
+//
+// Status: {userData.loadStatus || "N/A"} +//
+//
+// Customer Since:{" "} +// {userData.availableFrom ? new Date(userData.availableFrom).toLocaleDateString() : "N/A"} +//
+//
+// Type of Owner: {userData.userType || "N/A"} +//
+//
+// Experience Level: {userData.experienceLevel || "N/A"} +//
+//
+// Preferred Load: {userData.preferredLoadType || "N/A"} +//
+//
+// Company: {userData.company || "N/A"} +//
+//
+// Subscribed: {userData.subscribed ? "Yes" : "No"} +//
+//
+// Rating: {userData.rating || "N/A"} +//
+//
+//
+ +//
+//

Analytics

+ +//
+// +// +// {pieData.map((slice, index) => ( +// +// ))} +// +// +// +//
+ +//
+// +// +// +// +// +// +// +// +// +// {barData.map((_, idx) => +// idx === topLoadIndex ? : null +// )} +// +// +// +//
+//
+ +// +// Back to Home +// +//
+// ); +// }; + +// export default Dash; + import React, { useEffect, useState } from "react"; import { Link } from "react-router-dom"; import { @@ -164,15 +556,38 @@ import "./Dash.css"; const SERVER_PORT = process.env.REACT_APP_SOCKET_IO_CLIENT_PORT || "http://localhost:3001"; -// Colors for pie charts const PIE_COLORS = ["#0088FE", "#00C49F", "#FFBB28", "#FF8042"]; -const Dash = () => { - const [userData, setUserData] = useState(null); +interface LoadData { + weight: number; + value: number; + rating: number; + name?: string; // optional name for display on chart +} + +interface UserData { + firstName: string; + lastName: string; + email: string; + phoneNumber?: string; + address?: string; + loadStatus?: string; + availableFrom?: string; + userType?: string; + experienceLevel?: string; + preferredLoadType?: string; + company?: string; + subscribed?: boolean; + rating?: number; + profileImage?: string; + loadDetails?: LoadData[]; +} + +const Dash: React.FC = () => { + const [userData, setUserData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(""); - // Fetch user data useEffect(() => { const userId = localStorage.getItem("userId"); if (!userId) { @@ -183,7 +598,7 @@ const Dash = () => { const fetchUserData = async () => { try { - const res = await axios.get(`${SERVER_PORT}/api/user/view/${userId}`); + const res = await axios.get(`${SERVER_PORT}/api/user/view/${userId}`); setUserData(res.data); } catch (err) { console.error("Error fetching user data:", err); @@ -198,88 +613,102 @@ const Dash = () => { if (loading) return
Loading user data...
; if (error) return
{error}
; + if (!userData) return
No user data available.
; + + // ✅ TypeScript knows userData is not null here + const { + firstName, + lastName, + email, + phoneNumber, + address, + loadStatus, + availableFrom, + userType, + experienceLevel, + preferredLoadType, + company, + subscribed, + rating, + profileImage, + loadDetails, + } = userData; - // Prepare chart data - const barData = userData?.loadDetails?.map((load: any, idx: number) => ({ - name: `Load ${idx + 1}`, - weight: load.weight || 0, - value: load.value || 0, - })) || [{ name: "No Data", weight: 0, value: 0 }]; + const barData: LoadData[] = + loadDetails?.map((load, idx) => ({ + ...load, + name: `Load ${idx + 1}`, // optional for x-axis + })) || [{ weight: 0, value: 0, rating: 0, name: "N/A" }]; const pieData = [ - { name: "Available", value: userData.availableFrom ? 1 : 0 }, - { name: "Unavailable", value: userData.availableFrom ? 0 : 1 }, + { name: "Available", value: availableFrom ? 1 : 0 }, + { name: "Unavailable", value: availableFrom ? 0 : 1 }, ]; + const topLoadIndex = barData.reduce( + (maxIdx: number, currentLoad: LoadData, idx: number, arr: LoadData[]) => + currentLoad.rating > arr[maxIdx].rating ? idx : maxIdx, + 0 + ); + return (
+ {profileImage && Profile}

Dashboard

-

Welcome back, {userData.firstName}!

+

Welcome back, {firstName}!

- {/* User Info */}

User Information

-
- Name: {userData.firstName} {userData.lastName} +
+ Name: {firstName} {lastName}
-
- Email: {userData.email} +
+ Email: {email}
-
- Phone: {userData.phoneNumber || "Not provided"} +
+ Phone: {phoneNumber || "Not provided"}
-
- Address: {userData.address || "Not provided"} +
+ Address: {address || "Not provided"}
-
- Status: {userData.loadStatus || "N/A"} +
+ Status: {loadStatus || "N/A"}
-
+
Customer Since:{" "} - {userData.availableFrom - ? new Date(userData.availableFrom).toLocaleDateString() - : "N/A"} + {availableFrom ? new Date(availableFrom).toLocaleDateString() : "N/A"}
-
- Type of Owner: {userData.userType || "N/A"} +
+ Type of Owner: {userType || "N/A"}
-
- Experience Level: {userData.experienceLevel || "N/A"} +
+ Experience Level: {experienceLevel || "N/A"}
-
- Preferred Load: {userData.preferredLoadType || "N/A"} +
+ Preferred Load: {preferredLoadType || "N/A"}
-
- Company: {userData.company || "N/A"} +
+ Company: {company || "N/A"}
-
- Subscribed: {userData.subscribed ? "Yes" : "No"} +
+ Subscribed: {subscribed ? "Yes" : "No"}
-
- Rating: {userData.rating || "N/A"} +
+ Rating: {rating || "N/A"}
- {/* Charts */}

Analytics

- {/* Pie Chart */}
- - {pieData.map((entry, index) => ( + + {pieData.map((slice, index) => ( ))} @@ -287,14 +716,8 @@ const Dash = () => {
- {/* Bar Chart */}
- + @@ -302,8 +725,12 @@ const Dash = () => { - - + + {barData.map((_, idx) => + idx === topLoadIndex ? : null + )} + +