diff --git a/package.json b/package.json index 0becbeb..1fb52cb 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "next-auth": "5.0.0-beta.19", "react": "^18.3.1", "react-dom": "^18.3.1", + "server-only": "^0.0.1", "tailwind-merge": "^2.4.0", "tailwindcss-animate": "^1.0.7", "zod": "^3.23.3" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43b12dd..eddb4d2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,6 +41,9 @@ importers: react-dom: specifier: ^18.3.1 version: 18.3.1(react@18.3.1) + server-only: + specifier: ^0.0.1 + version: 0.0.1 tailwind-merge: specifier: ^2.4.0 version: 2.4.0 @@ -2066,6 +2069,9 @@ packages: seq-queue@0.0.5: resolution: {integrity: sha512-hr3Wtp/GZIc/6DAGPDcV4/9WoZhjrkXsi5B/07QgX8tsdc6ilr7BFM6PM6rbdAX1kFSDYeZGLipIZZKyQP0O5Q==} + server-only@0.0.1: + resolution: {integrity: sha512-qepMx2JxAa5jjfzxG79yPPq+8BuFToHd1hm7kI+Z4zAq1ftQiP7HcxMhDDItrbtwVeLg/cY2JnKnrcFkmiswNA==} + set-function-length@1.2.2: resolution: {integrity: sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==} engines: {node: '>= 0.4'} @@ -4326,6 +4332,8 @@ snapshots: seq-queue@0.0.5: {} + server-only@0.0.1: {} + set-function-length@1.2.2: dependencies: define-data-property: 1.1.4 diff --git a/src/app/page.tsx b/src/app/page.tsx index 513de90..151f500 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -4,14 +4,13 @@ import TT_Header from "~/components/ui/TT_Header"; import Techs_Table from "~/components/ui/Techs_Table"; export default async function HomePage() { - const user = await auth(); - if (!user) { - return ( - - ); + const session = await auth(); + if (!session) { + return } else { return ( -
+
diff --git a/src/components/ui/Techs_Table.tsx b/src/components/ui/Techs_Table.tsx index 9d51d48..69da0cb 100644 --- a/src/components/ui/Techs_Table.tsx +++ b/src/components/ui/Techs_Table.tsx @@ -1,10 +1,11 @@ -import { db } from '~/server/db'; +//import { auth } from "~/auth"; +import { getEmployees } from "~/server/functions"; + +export const dynamic = "force-dynamic"; export default async function Techs_Table() { - const employees = await db.query.users.findMany({ - orderBy: (model, {desc}) => desc(model.id), - }); + const employees = await getEmployees(); const formatTime = (timestamp: Date) => { const date = new Date(timestamp); @@ -14,35 +15,53 @@ export default async function Techs_Table() { const month = date.toLocaleString("default", { month: "long" }); return `${time} - ${month} ${day}`; } + //const session = await auth(); + //const users_name = session?.user?.name; return ( - - - - - - - - - - {employees.map((employee) => ( - - - - - - - ))} - -
- - Name - - Status - - Updated At -
- - {employee.name}{employee.status}{formatTime(employee.updatedAt)}
+
+ + + + + + + + + + {employees.map((employee) => ( + + + + + + + ))} + +
+ + Name + + Status + + Updated At +
+ + {employee.name}{employee.status}{formatTime(employee.updatedAt)}
+
+ + +
+
); }; diff --git a/src/server/db/schema.ts b/src/server/db/schema.ts index 5357f8b..f289d63 100644 --- a/src/server/db/schema.ts +++ b/src/server/db/schema.ts @@ -13,8 +13,8 @@ export const users = createTable( "users", { id: bigint("id", {mode: "number"}).primaryKey().autoincrement(), - name: varchar("name", { length: 256 }), - status: varchar("status", { length: 256 }), + name: varchar("name", { length: 256 }).notNull(), + status: varchar("status", { length: 256 }).notNull(), updatedAt: timestamp("updated_at") .default(sql`CURRENT_TIMESTAMP`) .notNull(), @@ -26,7 +26,7 @@ export const history = createTable( { id: bigint("id", {mode: "number"}).primaryKey().autoincrement(), user_id: bigint("user_id", {mode: "number"}).references(() => users.id), - status: varchar("status", { length: 256 }), + status: varchar("status", { length: 256 }).notNull(), updatedAt: timestamp("updated_at").notNull(), }, ); diff --git a/src/server/functions.ts b/src/server/functions.ts new file mode 100644 index 0000000..82b79d2 --- /dev/null +++ b/src/server/functions.ts @@ -0,0 +1,11 @@ +import "server-only"; +import { db } from "~/server/db"; +//import * as schema from "~/server/db/schema"; + +export const getEmployees = async () => { + return await db.query.users.findMany({ + orderBy: (model, { desc }) => desc(model.id), + }); +}; + +