fix : job
deskripsi: - page: job-vacancy untuk non user sudah bisa di akses kembali - tidak menggunakan use server lagi melainkan API
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import { Job_UiNotUserView } from "@/app_modules/job/_ui";
|
||||
import { job_getOneById } from "@/app_modules/job/fun/get/get_one_by_id";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const jobId = params.id;
|
||||
const dataJob = await job_getOneById(jobId);
|
||||
export default async function Page() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Job_UiNotUserView data={dataJob} />
|
||||
<Job_UiNotUserView />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
25
src/app/api/not-user/job/[id]/route.ts
Normal file
25
src/app/api/not-user/job/[id]/route.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const { id } = params;
|
||||
|
||||
const data = await prisma.job.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching job data:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch job data" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
16
src/app_modules/_global/lib/api_fetch_not_user.tsx
Normal file
16
src/app_modules/_global/lib/api_fetch_not_user.tsx
Normal file
@@ -0,0 +1,16 @@
|
||||
export async function apiGetNotUserForJob({ id }: { id: string }) {
|
||||
try {
|
||||
const response = await fetch(`/api/not-user/job/${id}`);
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => null);
|
||||
console.error("Failed to get job", response.statusText, errorData);
|
||||
throw new Error(errorData?.message || "Failed to get job");
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("Error get job:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -7,23 +7,16 @@ import UI_NewLayoutTamplate, {
|
||||
} from "@/app_modules/_global/ui/V2_layout_tamplate";
|
||||
import { Job_ViewNotUserJobVacany } from "../_view";
|
||||
|
||||
export function Job_UiNotUserView({ data }: { data: any }) {
|
||||
export function Job_UiNotUserView() {
|
||||
return (
|
||||
<>
|
||||
{/* <UIGlobal_LayoutTamplate
|
||||
header={
|
||||
<UIGlobal_LayoutHeaderTamplate title="Job Vacancy" hideButtonLeft />
|
||||
}
|
||||
>
|
||||
<Job_ViewNotUserJobVacany data={data} />
|
||||
</UIGlobal_LayoutTamplate> */}
|
||||
|
||||
<UI_NewLayoutTamplate>
|
||||
<UI_NewHeader>
|
||||
<Component_Header title="Job Vacancy" hideButtonLeft />
|
||||
</UI_NewHeader>
|
||||
<UI_NewChildren>
|
||||
<Job_ViewNotUserJobVacany data={data} />
|
||||
<Job_ViewNotUserJobVacany/>
|
||||
</UI_NewChildren>
|
||||
</UI_NewLayoutTamplate>
|
||||
</>
|
||||
|
||||
@@ -2,9 +2,29 @@ import {
|
||||
ComponentGlobal_CardStyles,
|
||||
ComponentGlobal_NotUserLoadImage,
|
||||
} from "@/app_modules/_global/component";
|
||||
import { Center, Stack, Text, Title } from "@mantine/core";
|
||||
import { apiGetNotUserForJob } from "@/app_modules/_global/lib/api_fetch_not_user";
|
||||
import CustomSkeleton from "@/app_modules/components/CustomSkeleton";
|
||||
import { Center, Stack, Text } from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
|
||||
export function Job_ViewNotUserJobVacany() {
|
||||
const { id } = useParams();
|
||||
const [data, setData] = useState<any>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const data = await apiGetNotUserForJob({ id: id as string });
|
||||
setData(data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching job data:", error);
|
||||
}
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
|
||||
export function Job_ViewNotUserJobVacany({ data }: { data: any }) {
|
||||
return (
|
||||
<>
|
||||
{data ? (
|
||||
@@ -32,13 +52,7 @@ export function Job_ViewNotUserJobVacany({ data }: { data: any }) {
|
||||
</Stack>
|
||||
</ComponentGlobal_CardStyles>
|
||||
) : (
|
||||
<ComponentGlobal_CardStyles>
|
||||
<Stack spacing={"xl"}>
|
||||
<Title order={3} align="center">
|
||||
Data Not Found
|
||||
</Title>
|
||||
</Stack>
|
||||
</ComponentGlobal_CardStyles>
|
||||
<CustomSkeleton height={400} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -44,13 +44,13 @@ export default function Job_MainDetail() {
|
||||
<Stack>
|
||||
<ComponentJob_DetailData data={data as any} />
|
||||
|
||||
{/* {!data ? (
|
||||
{!data ? (
|
||||
<Center>
|
||||
<CustomSkeleton height={40} width={"50%"} radius={"xl"} />
|
||||
</Center>
|
||||
) : (
|
||||
<ButtonAction jobId={param.id} />
|
||||
)} */}
|
||||
)}
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -18,6 +18,7 @@ const CONFIG: MiddlewareConfig = {
|
||||
userPath: "/dev/home",
|
||||
publicRoutes: [
|
||||
"/",
|
||||
"/api/not-user/*",
|
||||
"/api/voting/*",
|
||||
"/api/collaboration/*",
|
||||
"/api/notifikasi/*",
|
||||
@@ -36,7 +37,7 @@ const CONFIG: MiddlewareConfig = {
|
||||
"/validasi",
|
||||
"/splash",
|
||||
"/invalid-user",
|
||||
"/job-vacancy",
|
||||
"/job-vacancy/*",
|
||||
"/preview-image",
|
||||
"/auth/login",
|
||||
"/auth/api/login",
|
||||
|
||||
Reference in New Issue
Block a user