Mostly Front End & UI fixes
This commit is contained in:
@ -1,18 +0,0 @@
|
||||
"use server";
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getEmployees } from '~/server/functions';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === 'GET') {
|
||||
try {
|
||||
const employees = await getEmployees();
|
||||
res.status(200).json(employees);
|
||||
} catch (error) {
|
||||
console.error('Error fetching employees:', error);
|
||||
res.status(500).json({ message: 'Internal server error' });
|
||||
}
|
||||
} else {
|
||||
res.setHeader('Allow', ['GET']);
|
||||
res.status(405).json({ message: `Method ${req.method} Not Allowed` });
|
||||
}
|
||||
}
|
18
src/app/api/get_employees/route.ts
Normal file
18
src/app/api/get_employees/route.ts
Normal file
@ -0,0 +1,18 @@
|
||||
"use server";
|
||||
|
||||
import { NextResponse } from 'next/server';
|
||||
import { getEmployees } from '~/server/functions';
|
||||
import { auth } from '~/auth';
|
||||
|
||||
export const GET = async () => {
|
||||
try {
|
||||
const session = await auth();
|
||||
if (!session)
|
||||
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
|
||||
const employees = await getEmployees();
|
||||
return NextResponse.json(employees, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error('Error fetching employees:', error);
|
||||
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
};
|
@ -1,29 +0,0 @@
|
||||
"use server";
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { updateEmployeeStatus } from '~/server/functions';
|
||||
|
||||
type UpdateStatusBody = {
|
||||
employeeIds: number[];
|
||||
newStatus: string;
|
||||
};
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (req.method === 'POST') {
|
||||
const { employeeIds, newStatus } = req.body as UpdateStatusBody;
|
||||
|
||||
if (!Array.isArray(employeeIds) || typeof newStatus !== 'string') {
|
||||
return res.status(400).json({ message: 'Invalid input' });
|
||||
}
|
||||
|
||||
try {
|
||||
await updateEmployeeStatus(employeeIds, newStatus);
|
||||
return res.status(200).json({ message: 'Status updated successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error updating status:', error);
|
||||
return res.status(500).json({ message: 'Internal server error' });
|
||||
}
|
||||
} else {
|
||||
res.setHeader('Allow', ['POST']);
|
||||
return res.status(405).json({ message: `Method ${req.method} Not Allowed` });
|
||||
}
|
||||
}
|
30
src/app/api/update_status/route.ts
Normal file
30
src/app/api/update_status/route.ts
Normal file
@ -0,0 +1,30 @@
|
||||
"use server";
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { updateEmployeeStatus } from '~/server/functions';
|
||||
import { auth } from '~/auth';
|
||||
|
||||
type UpdateStatusBody = {
|
||||
employeeIds: string[];
|
||||
newStatus: string;
|
||||
};
|
||||
|
||||
export const POST = async (req: NextRequest) => {
|
||||
const session = await auth();
|
||||
if (!session)
|
||||
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
|
||||
|
||||
const { employeeIds, newStatus } = await req.json() as UpdateStatusBody;
|
||||
|
||||
if (!Array.isArray(employeeIds) || typeof newStatus !== 'string') {
|
||||
return NextResponse.json({ message: 'Invalid input' }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
await updateEmployeeStatus(employeeIds, newStatus);
|
||||
return NextResponse.json({ message: 'Status updated successfully' }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error('Error updating status:', error);
|
||||
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
};
|
@ -1,7 +1,7 @@
|
||||
import { auth } from "~/auth";
|
||||
import No_Session from "~/components/auth/No_Session";
|
||||
import TT_Header from "~/components/ui/TT_Header";
|
||||
import Techs_Table from "~/components/ui/Techs_Table";
|
||||
import Techs from "~/components/ui/Techs";
|
||||
|
||||
export default async function HomePage() {
|
||||
const session = await auth();
|
||||
@ -12,7 +12,7 @@ export default async function HomePage() {
|
||||
<main className="min-h-screen bg-gradient-to-b
|
||||
from-[#111111] to-[#111325]">
|
||||
<TT_Header />
|
||||
<Techs_Table />
|
||||
<Techs />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user