diff --git a/client/src/containers/User/UserDash/Dash.css b/client/src/containers/User/UserDash/Dash.css index 9ba5793..780ad03 100644 --- a/client/src/containers/User/UserDash/Dash.css +++ b/client/src/containers/User/UserDash/Dash.css @@ -83,3 +83,26 @@ padding: 50px; color: #ff4d4f; } + +.qr-section { + margin-top: 30px; + text-align: center; +} + +.qr-card { + background: #fff; + padding: 20px; + border-radius: 12px; + display: inline-block; + box-shadow: 0 2px 5px rgba(0,0,0,0.1); +} + +.qr-image { + width: 200px; + height: 200px; + object-fit: contain; + border-radius: 10px; + border: 1px solid #eee; + padding: 10px; + background: #fff; +} diff --git a/client/src/containers/User/UserDash/Dash.tsx b/client/src/containers/User/UserDash/Dash.tsx index b68fec4..f40c394 100644 --- a/client/src/containers/User/UserDash/Dash.tsx +++ b/client/src/containers/User/UserDash/Dash.tsx @@ -535,6 +535,258 @@ // 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"; + +// const PIE_COLORS = ["#0088FE", "#00C49F", "#FFBB28", "#FF8042"]; + +// 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; +// qrCode?: string; +// qrCodeId?: string; +// qrData?: string; +// qrPNG?: 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.
; + +// // ✅ TypeScript knows userData is not null here +// const { +// firstName, +// lastName, +// email, +// phoneNumber, +// address, +// qrCode, +// qrCodeId, +// qrData, +// qrPNG, +// loadStatus, +// availableFrom, +// userType, +// experienceLevel, +// preferredLoadType, +// company, +// subscribed, +// rating, +// profileImage, +// loadDetails, +// } = userData; + +// 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: 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, {firstName}!

+//
+ +//
+//

User Information

+//
+//
+// Name: {firstName} {lastName} +//
+//
+// Email: {email} +//
+//
+// Phone: {phoneNumber || "Not provided"} +//
+//
+// Address: {address || "Not provided"} +//
+//
+// QR Code: {qrCode || "N/A"} +//
+//
+// QR Code ID: {qrCodeId || "N/A"} +//
+//
+// QR Data: {qrData || "N/A"} +//
+//
+// QR PNG: {qrPNG || "N/A"} +//
+// {/* QR Code Card */} +//
+//

Your QR Code

+ +// {qrPNG ? ( +// QR Code +// ) : ( +//

No QR code available

+// )} +//
+ +//
+// Status: {loadStatus || "N/A"} +//
+//
+// Customer Since: {availableFrom ? new Date(availableFrom).toLocaleDateString() : "N/A"} +//
+//
+// Type of Owner: {userType || "N/A"} +//
+//
+// Experience Level: {experienceLevel || "N/A"} +//
+//
+// Preferred Load: {preferredLoadType || "N/A"} +//
+//
+// Company: {company || "N/A"} +//
+//
+// Subscribed: {subscribed ? "Yes" : "No"} +//
+//
+// Rating: {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 { @@ -554,7 +806,8 @@ import { import axios from "axios"; import "./Dash.css"; -const SERVER_PORT = process.env.REACT_APP_SOCKET_IO_CLIENT_PORT || "http://localhost:3001"; +const SERVER_PORT = + process.env.REACT_APP_SOCKET_IO_CLIENT_PORT || "http://localhost:3001"; const PIE_COLORS = ["#0088FE", "#00C49F", "#FFBB28", "#FF8042"]; @@ -562,7 +815,7 @@ interface LoadData { weight: number; value: number; rating: number; - name?: string; // optional name for display on chart + name?: string; } interface UserData { @@ -602,7 +855,9 @@ const Dash: React.FC = () => { 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); @@ -619,7 +874,6 @@ const Dash: React.FC = () => { if (error) return
{error}
; if (!userData) return
No user data available.
; - // ✅ TypeScript knows userData is not null here const { firstName, lastName, @@ -645,7 +899,7 @@ const Dash: React.FC = () => { const barData: LoadData[] = loadDetails?.map((load, idx) => ({ ...load, - name: `Load ${idx + 1}`, // optional for x-axis + name: `Load ${idx + 1}`, })) || [{ weight: 0, value: 0, rating: 0, name: "N/A" }]; const pieData = [ @@ -662,11 +916,14 @@ const Dash: React.FC = () => { return (
- {profileImage && Profile} + {profileImage && ( + Profile + )}

Dashboard

Welcome back, {firstName}!

+ {/* USER INFO */}

User Information

@@ -694,35 +951,14 @@ const Dash: React.FC = () => {
QR PNG: {qrPNG || "N/A"}
- {/* QR Code Card */} -
-

Your QR Code

- - {qrPNG ? ( - QR Code - ) : ( -

No QR code available

- )} -
-
Status: {loadStatus || "N/A"}
- Customer Since: {availableFrom ? new Date(availableFrom).toLocaleDateString() : "N/A"} + Customer Since:{" "} + {availableFrom + ? new Date(availableFrom).toLocaleDateString() + : "N/A"}
Type of Owner: {userType || "N/A"} @@ -745,14 +981,41 @@ const Dash: React.FC = () => {
+ {/* ✅ QR PNG DISPLAY SECTION */} +
+

Your QR Code

+
+ {qrPNG ? ( + User QR Code + ) : ( +

No QR Image Available

+ )} +
+
+ + {/* ANALYTICS */}

Analytics

- + {pieData.map((slice, index) => ( - + ))} @@ -760,7 +1023,12 @@ const Dash: React.FC = () => {
- + @@ -768,12 +1036,26 @@ const Dash: React.FC = () => { - + {barData.map((_, idx) => - idx === topLoadIndex ? : null + idx === topLoadIndex ? ( + + ) : null )} - +