This commit is contained in:
2025-01-17 20:29:50 -05:00
parent a1fc36f175
commit c0f582a346
2 changed files with 23 additions and 47 deletions

View File

@@ -14,6 +14,11 @@ export const getUserByEmail = async (email:string) => {
return data; return data;
}; };
export const getUserByUUID = async (uuid:string) => {
const data = await db.select().from(users).where(eq(users.uuid, uuid));
return data;
};
export const addUser = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => { export const addUser = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => {
await db.insert(users).values({ await db.insert(users).values({
first_name : first_name, last_name: last_name, username: email, email: email, password_hash : password_hash first_name : first_name, last_name: last_name, username: email, email: email, password_hash : password_hash

View File

@@ -1,25 +1,24 @@
import { getUserByUUID } from "@src/actions/userActions";
import { NextPage } from "next"; import { NextPage } from "next";
import { Herr_Von_Muellerhoff } from "next/font/google"; import { Herr_Von_Muellerhoff } from "next/font/google";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import {db} from "@db/index";
export default function UserProfilePage() { export default function UserProfilePage() {
const router = useRouter(); const router = useRouter();
const { uuid } = router.query; const { uuid } = router.query;
const [user, setUser] = useState<{ uuid: string | null; id: string; username: string; email: string; emailVerifiedOn: Date | null; password_hash: string; first_name: string | null; last_name: string | null; full_name: string | null; buildPrivacySetting: string | null; }[] | null>(null);
useEffect(() => { useEffect(() => {
if (uuid) { if (uuid) {
// Fetch product data based on the id getUserByUUID(uuid as string)
fetch(`/api/products/${id}`) .then((user) => setUser(user))
.then((response) => response.json()) .catch((error) => console.error("Error fetching user data:", error));
.catch((error) => console.error("Error fetching product data:", error));
} }
}, [uuid]); }, [uuid]);
if (!product) { if (!user) {
return <div>Loading...</div>; return <div>Loading...</div>;
} }
@@ -29,13 +28,13 @@ export default function UserProfilePage() {
{/* Product Info */} {/* Product Info */}
<div> <div>
<h1 className="text-3xl font-bold mb-4">{product.name}</h1> <h1 className="text-3xl font-bold mb-4">{user[0].first_name}</h1>
{/* Vendor Pricing Table */} {/* Vendor Pricing Table */}
<div className="bg-white rounded-lg shadow-md p-4 mb-6"> <div className="bg-white rounded-lg shadow-md p-4 mb-6">
<h2 className="text-xl font-semibold mb-4">Available From</h2> <h2 className="text-xl font-semibold mb-4">Available From</h2>
<div className="overflow-x-auto"> <div className="overflow-x-auto">
<table className="min-w-full table-auto"> {/* <table className="min-w-full table-auto">
<thead> <thead>
<tr className="bg-gray-50 border-b"> <tr className="bg-gray-50 border-b">
<th className="px-4 py-2 text-left">Vendor</th> <th className="px-4 py-2 text-left">Vendor</th>
@@ -58,44 +57,16 @@ export default function UserProfilePage() {
</tr> </tr>
))} ))}
</tbody> </tbody>
</table> </table> */}
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{/* Product Description */}
<div className="bg-white rounded-lg shadow-md p-6 mb-8">
<h2 className="text-xl font-semibold mb-4">Product Description</h2>
<p className="text-gray-600">
{product.description}
</p>
</div>
{/* Product Specifications */} {/* Product Specifications */}
<div className="bg-white rounded-lg shadow-md p-6">
<h2 className="text-xl font-semibold mb-4">Specifications</h2>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="border-b py-2">
<span className="font-medium">Manufacturer:</span> {product.specifications.manufacturer}
</div>
<div className="border-b py-2">
<span className="font-medium">Model:</span> {product.specifications.model}
</div>
<div className="border-b py-2">
<span className="font-medium">Weight:</span> {product.specifications.weight}
</div>
<div className="border-b py-2">
<span className="font-medium">Dimensions:</span> {product.specifications.dimensions}
</div>
<div className="border-b py-2">
<span className="font-medium">Material:</span> {product.specifications.material}
</div>
<div className="border-b py-2">
<span className="font-medium">Warranty:</span> {product.specifications.warranty}
</div>
</div>
</div>
</div> </div>
); );
} }