diff --git a/src/actions/userActions.ts b/src/actions/userActions.ts index 188c284..296d5bd 100644 --- a/src/actions/userActions.ts +++ b/src/actions/userActions.ts @@ -1,4 +1,4 @@ -"use server"; +'use server'; import { eq, not , asc} from "drizzle-orm"; import { revalidatePath } from "next/cache"; import { db } from "@db/index"; @@ -8,15 +8,18 @@ export const getData = async () => { const data = await db.select().from(users).orderBy(asc(users.last_name)); return data; }; - -export const getUserByEmail = async (email:string) => { - const data = await db.select().from(users).where(eq(users.email, email)); +export const getAllUsers = async () => { + const data = await db.select().from(users).orderBy(asc(users.last_name)); return data; }; +export const getUserByEmail = async (email:string) => { + return getData(); +}; + export const getUserByUUID = async (uuid:string) => { const data = await db.select().from(users).where(eq(users.uuid, uuid)); - return data; + return data[0]; }; export const addUser = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => { diff --git a/src/app/userProfile/[uuid].tsx b/src/app/[uuid].tsx similarity index 73% rename from src/app/userProfile/[uuid].tsx rename to src/app/[uuid].tsx index ccde328..f6cad02 100644 --- a/src/app/userProfile/[uuid].tsx +++ b/src/app/[uuid].tsx @@ -1,30 +1,32 @@ import { getUserByUUID } from "@actions/userActions"; import { NextPage } from "next"; import { Herr_Von_Muellerhoff } from "next/font/google"; -import { useRouter } from "next/router"; + import { useEffect, useState } from "react"; import {db} from "@db/index"; +import router from "next/router"; -export default function UserProfilePage() { - const router = useRouter(); - // const { uuid } = router.query; - const uuid = "8ad8da5e-1ecd-402b-8211-bc93f2c3331a"; -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(() => { - if (uuid) { - getUserByUUID(uuid as string) - .then((user) => setUser(user)) - .catch((error) => console.error("Error fetching user data:", error)); - } -}, [uuid]); +export default function UserProfilePage(params: any) { + const { uuid } = router.query; +// const uuid = "8ad8da5e-1ecd-402b-8211-bc93f2c3331a"; + // 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); +let user:any = null; +//useEffect(() => { +// if (uuid) { +// getUserByUUID(uuid as string) +// .then((user) => setUser(user)) +// .catch((error) => console.error("Error fetching user data:", error)); + // } +//}, [uuid]); +user = getUserByUUID(uuid as string) if (!user) { return
| - {item.email} + {item.email} | {item.first_name} |