Move db calls to server file

This commit is contained in:
2024-07-19 15:58:24 -05:00
parent bf7f6a466a
commit 76977427e0
6 changed files with 79 additions and 41 deletions

View File

@ -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 (
<table className="w-5/6 m-auto text-center border-collapse text-[42px]">
<thead className="bg-gradient-to-br from-[#212121] to-[#333333]">
<tr>
<th className="p-5 border border-[#3e4446] text-[48px]"/>
<th className="p-2 border border-[#3e4446] text-[48px]">
Name
</th>
<th className="p-2 border border-[#3e4446] text-[48px]">
Status
</th>
<th className="p-2 border border-[#3e4446] text-[48px]">
Updated At
</th>
</tr>
</thead>
<tbody>
{employees.map((employee) => (
<tr className="even:bg-gradient-to-bl from-[#222222] to-[#232323]" key={employee.id}>
<td className="p-1 border border-[#3e4446]">
<input type="checkbox"/>
</td>
<td className="p-1 border border-[#3e4446]">{employee.name}</td>
<td className="p-1 border border-[#3e4446]">{employee.status}</td>
<td className="p-1 border border-[#3e4446]">{formatTime(employee.updatedAt)}</td>
</tr>
))}
</tbody>
</table>
<div>
<table className="w-5/6 m-auto text-center border-collapse text-[42px]">
<thead className="bg-gradient-to-br from-[#212121] to-[#333333]">
<tr>
<th className="p-5 border border-[#3e4446] text-[48px]"/>
<th className="p-2 border border-[#3e4446] text-[48px]">
Name
</th>
<th className="p-2 border border-[#3e4446] text-[48px]">
Status
</th>
<th className="p-2 border border-[#3e4446] text-[48px]">
Updated At
</th>
</tr>
</thead>
<tbody>
{employees.map((employee) => (
<tr className="even:bg-gradient-to-bl from-[#222222] to-[#232323]" key={employee.id}>
<td className="p-1 border border-[#3e4446]">
<input type="checkbox"
className="m-0 cursor-pointer transform scale-150"
//checked={}
/>
</td>
<td className="p-1 border border-[#3e4446]">{employee.name}</td>
<td className="p-1 border border-[#3e4446]">{employee.status}</td>
<td className="p-1 border border-[#3e4446]">{formatTime(employee.updatedAt)}</td>
</tr>
))}
</tbody>
</table>
<div className="m-auto flex flex-row items-center justify-center">
<input type="text" placeholder="New Status"
className="w-1/5 p-2 border-none rounded-md"
//value={}
/>
<button type="submit"
className="m-2 px-2 py-5 border-none rounded-md text-center bg-gradient-to-br from-[#484848] to-[#333333]"
>
Update
</button>
</div>
</div>
);
};