Fix Job
Deskripsi: - Di beranda diganti menggunakan API - Skeleton beranda - V 1.2.25
This commit is contained in:
16
src/app/api/job/get-all/route.ts
Normal file
16
src/app/api/job/get-all/route.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { job_getAllListPublish } from "@/app_modules/job/fun/get/get_all_publish";
|
||||||
|
import _ from "lodash";
|
||||||
|
import { NextResponse } from "next/server";
|
||||||
|
|
||||||
|
export async function GET(params: Request) {
|
||||||
|
const { searchParams } = new URL(params.url);
|
||||||
|
const page = searchParams.get("page");
|
||||||
|
const search = searchParams.get("search");
|
||||||
|
|
||||||
|
const data = await job_getAllListPublish({
|
||||||
|
page: _.toNumber(page),
|
||||||
|
search: search as string,
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json({ data });
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
import { Job_ViewBeranda } from "@/app_modules/job";
|
import { Job_ViewBeranda } from "@/app_modules/job";
|
||||||
import { job_getAllListPublish } from "@/app_modules/job/fun/get/get_all_publish";
|
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const listJob = await job_getAllListPublish({ page: 1 });
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Job_ViewBeranda listJob={listJob as any} />
|
<Job_ViewBeranda />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/app/lib/api_user_router/route_api_job.ts
Normal file
4
src/app/lib/api_user_router/route_api_job.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export const API_RouteJob = {
|
||||||
|
get_all: ({ page, search }: { page: number; search?: string }) =>
|
||||||
|
`/api/job/get-all?page=${page}&search=${search || ""}`,
|
||||||
|
};
|
||||||
@@ -23,4 +23,6 @@ process.on('SIGINT', async () => {
|
|||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// console.log('==> Test prisma');
|
||||||
|
|
||||||
export default prisma;
|
export default prisma;
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
import { ServerEnv } from "@/app/lib/server_env";
|
|
||||||
import { TokenStorage } from "@/app/lib/token";
|
import { TokenStorage } from "@/app/lib/token";
|
||||||
import { envs } from "@/lib/envs";
|
|
||||||
|
|
||||||
export async function funGlobal_UploadToStorage({
|
export async function funGlobal_UploadToStorage({
|
||||||
file,
|
file,
|
||||||
@@ -24,9 +22,19 @@ export async function funGlobal_UploadToStorage({
|
|||||||
"text/plain",
|
"text/plain",
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!allowedMimeTypes.includes(file.type)) console.log("File tidak sesuai");
|
// if (!allowedMimeTypes.includes(file.type)) console.log("File tidak sesuai");
|
||||||
|
if (!allowedMimeTypes.includes(file.type)) {
|
||||||
|
console.error("File tidak sesuai");
|
||||||
|
return { success: false, message: "File type not allowed" };
|
||||||
|
}
|
||||||
|
|
||||||
if (file.size > 100 * 1024 * 1024) console.log("File terlalu besar");
|
if (file.size > 100 * 1024 * 1024) {
|
||||||
|
console.error("File terlalu besar");
|
||||||
|
return { success: false, message: "File size exceeds limit" };
|
||||||
|
}
|
||||||
|
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 30000); // Timeout 30 detik
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
@@ -39,19 +47,23 @@ export async function funGlobal_UploadToStorage({
|
|||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${Env_WS_APIKEY}`,
|
Authorization: `Bearer ${Env_WS_APIKEY}`,
|
||||||
},
|
},
|
||||||
|
signal: controller.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
const dataRes = await res.json();
|
clearTimeout(timeoutId); // Bersihkan timeout jika selesai tepat waktu
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
|
const dataRes = await res.json();
|
||||||
return { success: true, data: dataRes.data };
|
return { success: true, data: dataRes.data };
|
||||||
} else {
|
} else {
|
||||||
const errorText = await res.text();
|
const errorText = await res.text();
|
||||||
console.error("Error:", errorText);
|
console.error("Error:", errorText);
|
||||||
return { success: false, data: {} };
|
return { success: false, message: errorText };
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearTimeout(timeoutId); //
|
||||||
|
|
||||||
console.error("Error:", error);
|
console.error("Error:", error);
|
||||||
return { success: false, data: {} };
|
return { success: false, message: "An unexpected error occurred" };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ export async function donasi_checkStatus({ id }: { id: string }) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(checkStatus?.donasiMaster_StatusDonasiId, "ini status nya")
|
|
||||||
|
|
||||||
if (checkStatus?.donasiMaster_StatusDonasiId == "2") return true;
|
if (checkStatus?.donasiMaster_StatusDonasiId == "2") return true;
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -33,92 +33,101 @@ function Job_ComponentButtonSaveCreate({
|
|||||||
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
|
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
|
||||||
|
|
||||||
async function onCreate() {
|
async function onCreate() {
|
||||||
if (file === null) {
|
try {
|
||||||
const createNoFile = await job_funCreateNoFile({
|
setIsLoading(true);
|
||||||
data: value,
|
if (file === null) {
|
||||||
});
|
const createNoFile = await job_funCreateNoFile({
|
||||||
|
data: value,
|
||||||
if (createNoFile.status === 201) {
|
|
||||||
const dataNotifikasi: IRealtimeData = {
|
|
||||||
appId: createNoFile.data?.id as any,
|
|
||||||
status: createNoFile.data?.MasterStatus?.name as any,
|
|
||||||
userId: createNoFile.data?.authorId as any,
|
|
||||||
pesan: createNoFile.data?.title as any,
|
|
||||||
kategoriApp: "JOB",
|
|
||||||
title: "Job baru",
|
|
||||||
};
|
|
||||||
|
|
||||||
const notif = await notifikasiToAdmin_funCreate({
|
|
||||||
data: dataNotifikasi as any,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (notif.status === 201) {
|
if (createNoFile.status === 201) {
|
||||||
WibuRealtime.setData({
|
const dataNotifikasi: IRealtimeData = {
|
||||||
type: "notification",
|
appId: createNoFile.data?.id as any,
|
||||||
pushNotificationTo: "ADMIN",
|
status: createNoFile.data?.MasterStatus?.name as any,
|
||||||
|
userId: createNoFile.data?.authorId as any,
|
||||||
|
pesan: createNoFile.data?.title as any,
|
||||||
|
kategoriApp: "JOB",
|
||||||
|
title: "Job baru",
|
||||||
|
};
|
||||||
|
|
||||||
|
const notif = await notifikasiToAdmin_funCreate({
|
||||||
|
data: dataNotifikasi as any,
|
||||||
});
|
});
|
||||||
|
|
||||||
WibuRealtime.setData({
|
if (notif.status === 201) {
|
||||||
type: "trigger",
|
WibuRealtime.setData({
|
||||||
pushNotificationTo: "ADMIN",
|
type: "notification",
|
||||||
dataMessage: dataNotifikasi,
|
pushNotificationTo: "ADMIN",
|
||||||
});
|
});
|
||||||
|
|
||||||
setHotMenu(2);
|
WibuRealtime.setData({
|
||||||
router.replace(RouterJob.status({ id: "2" }));
|
type: "trigger",
|
||||||
setIsLoading(true);
|
pushNotificationTo: "ADMIN",
|
||||||
ComponentGlobal_NotifikasiBerhasil(createNoFile.message);
|
dataMessage: dataNotifikasi,
|
||||||
|
});
|
||||||
|
|
||||||
|
setHotMenu(2);
|
||||||
|
router.replace(RouterJob.status({ id: "2" }));
|
||||||
|
ComponentGlobal_NotifikasiBerhasil(createNoFile.message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ComponentGlobal_NotifikasiGagal(createNoFile.message);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ComponentGlobal_NotifikasiGagal(createNoFile.message);
|
const uploadFile = await funGlobal_UploadToStorage({
|
||||||
|
file: file,
|
||||||
|
dirId: DIRECTORY_ID.job_image,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!uploadFile.success) {
|
||||||
|
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const createWithFile = await job_funCreateWithFile({
|
||||||
|
data: value,
|
||||||
|
fileId: uploadFile.data.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (createWithFile.status === 201) {
|
||||||
|
const dataNotifikasi: IRealtimeData = {
|
||||||
|
appId: createWithFile.data?.id as any,
|
||||||
|
status: createWithFile.data?.MasterStatus?.name as any,
|
||||||
|
userId: createWithFile.data?.authorId as any,
|
||||||
|
pesan: createWithFile.data?.title as any,
|
||||||
|
kategoriApp: "JOB",
|
||||||
|
title: "Job baru",
|
||||||
|
};
|
||||||
|
|
||||||
|
const notif = await notifikasiToAdmin_funCreate({
|
||||||
|
data: dataNotifikasi as any,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (notif.status === 201) {
|
||||||
|
WibuRealtime.setData({
|
||||||
|
type: "notification",
|
||||||
|
pushNotificationTo: "ADMIN",
|
||||||
|
});
|
||||||
|
|
||||||
|
WibuRealtime.setData({
|
||||||
|
type: "trigger",
|
||||||
|
pushNotificationTo: "ADMIN",
|
||||||
|
dataMessage: dataNotifikasi,
|
||||||
|
});
|
||||||
|
|
||||||
|
setHotMenu(2);
|
||||||
|
router.replace(RouterJob.status({ id: "2" }));
|
||||||
|
ComponentGlobal_NotifikasiBerhasil(createWithFile.message);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ComponentGlobal_NotifikasiGagal(createWithFile.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} catch (error) {
|
||||||
const uploadFile = await funGlobal_UploadToStorage({
|
console.log(error);
|
||||||
file: file,
|
} finally {
|
||||||
dirId: DIRECTORY_ID.job_image,
|
if (window.location.pathname !== RouterJob.status({ id: "2" })) {
|
||||||
});
|
setIsLoading(false);
|
||||||
|
|
||||||
if (!uploadFile.success)
|
|
||||||
return ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
|
|
||||||
|
|
||||||
const createWithFile = await job_funCreateWithFile({
|
|
||||||
data: value,
|
|
||||||
fileId: uploadFile.data.id,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (createWithFile.status === 201) {
|
|
||||||
const dataNotifikasi: IRealtimeData = {
|
|
||||||
appId: createWithFile.data?.id as any,
|
|
||||||
status: createWithFile.data?.MasterStatus?.name as any,
|
|
||||||
userId: createWithFile.data?.authorId as any,
|
|
||||||
pesan: createWithFile.data?.title as any,
|
|
||||||
kategoriApp: "JOB",
|
|
||||||
title: "Job baru",
|
|
||||||
};
|
|
||||||
|
|
||||||
const notif = await notifikasiToAdmin_funCreate({
|
|
||||||
data: dataNotifikasi as any,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (notif.status === 201) {
|
|
||||||
WibuRealtime.setData({
|
|
||||||
type: "notification",
|
|
||||||
pushNotificationTo: "ADMIN",
|
|
||||||
});
|
|
||||||
|
|
||||||
WibuRealtime.setData({
|
|
||||||
type: "trigger",
|
|
||||||
pushNotificationTo: "ADMIN",
|
|
||||||
dataMessage: dataNotifikasi,
|
|
||||||
});
|
|
||||||
|
|
||||||
setHotMenu(2);
|
|
||||||
router.replace(RouterJob.status({ id: "2" }));
|
|
||||||
setIsLoading(true);
|
|
||||||
ComponentGlobal_NotifikasiBerhasil(createWithFile.message);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ComponentGlobal_NotifikasiGagal(createWithFile.message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,10 @@ import Job_ComponentButtonSaveCreate from "./button/comp_button_save_create";
|
|||||||
import { Job_ComponentButtonUpdateBeranda } from "./button/comp_button_update_beranda";
|
import { Job_ComponentButtonUpdateBeranda } from "./button/comp_button_update_beranda";
|
||||||
import { Job_ComponentButtonUpdateData } from "./button/comp_button_update_data";
|
import { Job_ComponentButtonUpdateData } from "./button/comp_button_update_data";
|
||||||
import { Job_ComponentBoxUploadImage } from "./detail/comp_box_upload_image";
|
import { Job_ComponentBoxUploadImage } from "./detail/comp_box_upload_image";
|
||||||
|
import Job_ComponentSkeletonBeranda from "./skeleton/comp_skeleton_beranda";
|
||||||
|
|
||||||
export { Job_ComponentButtonSaveCreate };
|
export { Job_ComponentButtonSaveCreate };
|
||||||
export { Job_ComponentBoxUploadImage };
|
export { Job_ComponentBoxUploadImage };
|
||||||
export { Job_ComponentButtonUpdateData as Job_ComponentButtonUpdate };
|
export { Job_ComponentButtonUpdateData as Job_ComponentButtonUpdate };
|
||||||
export { Job_ComponentButtonUpdateBeranda };
|
export { Job_ComponentButtonUpdateBeranda };
|
||||||
|
export { Job_ComponentSkeletonBeranda };
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
||||||
|
import { Box, Center, Group, Skeleton, Stack } from "@mantine/core";
|
||||||
|
|
||||||
|
export default function Job_ComponentSkeletonBeranda() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Box>
|
||||||
|
{Array.from(new Array(10)).map((e, i) => (
|
||||||
|
<ComponentGlobal_CardStyles key={i} marginBottom={"15px"}>
|
||||||
|
<Stack>
|
||||||
|
<Group position="left">
|
||||||
|
<Skeleton height={40} width={40} circle />
|
||||||
|
<Skeleton height={20} width={200} />
|
||||||
|
</Group>
|
||||||
|
|
||||||
|
<Center my={"md"}>
|
||||||
|
<Skeleton height={20} width={300} />
|
||||||
|
</Center>
|
||||||
|
</Stack>
|
||||||
|
</ComponentGlobal_CardStyles>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -24,19 +24,10 @@ function ButtonAction({ jobId }: { jobId: string }) {
|
|||||||
const [origin, setOrigin] = useState("");
|
const [origin, setOrigin] = useState("");
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
onLoadOrigin(setOrigin);
|
if (typeof window !== "undefined") {
|
||||||
// if (typeof window !== "undefined") {
|
setOrigin(window.location.origin);
|
||||||
// setOrigin(window.location.origin);
|
}
|
||||||
// }
|
}, []);
|
||||||
|
|
||||||
}, [setOrigin]);
|
|
||||||
|
|
||||||
async function onLoadOrigin(setOrigin: any) {
|
|
||||||
const res = await fetch("/api/origin-url");
|
|
||||||
const result = await res.json();
|
|
||||||
console.log(result);
|
|
||||||
setOrigin(result.origin);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|||||||
@@ -4,20 +4,24 @@ import { gs_jobTiggerBeranda } from "@/app/lib/global_state";
|
|||||||
import { RouterJob } from "@/app/lib/router_hipmi/router_job";
|
import { RouterJob } from "@/app/lib/router_hipmi/router_job";
|
||||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||||
import { Center, Loader, Stack, TextInput } from "@mantine/core";
|
import { Box, Center, Loader, Stack, TextInput } from "@mantine/core";
|
||||||
import { useShallowEffect } from "@mantine/hooks";
|
import { useShallowEffect } from "@mantine/hooks";
|
||||||
import { IconSearch } from "@tabler/icons-react";
|
import { IconSearch } from "@tabler/icons-react";
|
||||||
import { useAtom } from "jotai";
|
import { useAtom } from "jotai";
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { ScrollOnly } from "next-scroll-loader";
|
import { ScrollOnly } from "next-scroll-loader";
|
||||||
import { useEffect, useState } from "react";
|
import { useState } from "react";
|
||||||
|
import {
|
||||||
|
Job_ComponentButtonUpdateBeranda,
|
||||||
|
Job_ComponentSkeletonBeranda,
|
||||||
|
} from "../../component";
|
||||||
import ComponentJob_BerandaCardView from "../../component/beranda/card_view";
|
import ComponentJob_BerandaCardView from "../../component/beranda/card_view";
|
||||||
import { job_getAllListPublish } from "../../fun/get/get_all_publish";
|
import { job_getAllListPublish } from "../../fun/get/get_all_publish";
|
||||||
import { MODEL_JOB } from "../../model/interface";
|
import { MODEL_JOB } from "../../model/interface";
|
||||||
import { Job_ComponentButtonUpdateBeranda } from "../../component";
|
import { API_RouteJob } from "@/app/lib/api_user_router/route_api_job";
|
||||||
|
|
||||||
export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
export function Job_UiBeranda() {
|
||||||
const [data, setData] = useState(listData);
|
const [data, setData] = useState<MODEL_JOB[] | null>(null);
|
||||||
const [activePage, setActivePage] = useState(1);
|
const [activePage, setActivePage] = useState(1);
|
||||||
const [isSearch, setIsSearch] = useState("");
|
const [isSearch, setIsSearch] = useState("");
|
||||||
|
|
||||||
@@ -26,19 +30,16 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
|||||||
const [isTriggerJob, setIsTriggerJob] = useAtom(gs_jobTiggerBeranda);
|
const [isTriggerJob, setIsTriggerJob] = useAtom(gs_jobTiggerBeranda);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
onLoadNewData({
|
if (isTriggerJob == true) {
|
||||||
onLoad(val) {
|
setIsShowUpdate(true);
|
||||||
setData(val);
|
}
|
||||||
},
|
}, [isTriggerJob]);
|
||||||
});
|
|
||||||
}, [setData]);
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
if (isTriggerJob) {
|
setIsTriggerJob(false);
|
||||||
setIsShowUpdate(true);
|
setIsShowUpdate(false);
|
||||||
// setIsTriggerJob(false);
|
onLoadNewData();
|
||||||
}
|
}, []);
|
||||||
}, [isTriggerJob, setIsShowUpdate]);
|
|
||||||
|
|
||||||
async function onSearch(text: string) {
|
async function onSearch(text: string) {
|
||||||
setIsSearch(text);
|
setIsSearch(text);
|
||||||
@@ -50,9 +51,11 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
|||||||
setActivePage(1);
|
setActivePage(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function onLoadNewData({ onLoad }: { onLoad: (val: any) => void }) {
|
async function onLoadNewData() {
|
||||||
const loadData = await job_getAllListPublish({ page: 1 });
|
const loadData = await fetch(API_RouteJob.get_all({ page: activePage }));
|
||||||
onLoad(loadData);
|
const res = await loadData.json();
|
||||||
|
|
||||||
|
setData(res.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -62,6 +65,7 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
|||||||
<Job_ComponentButtonUpdateBeranda
|
<Job_ComponentButtonUpdateBeranda
|
||||||
onSetIsNewPost={(val) => {
|
onSetIsNewPost={(val) => {
|
||||||
setIsShowUpdate(val);
|
setIsShowUpdate(val);
|
||||||
|
setIsTriggerJob(val);
|
||||||
}}
|
}}
|
||||||
onSetData={(val: any[]) => {
|
onSetData={(val: any[]) => {
|
||||||
setData(val);
|
setData(val);
|
||||||
@@ -85,7 +89,9 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{_.isEmpty(data) ? (
|
{_.isNull(data) ? (
|
||||||
|
<Job_ComponentSkeletonBeranda />
|
||||||
|
) : _.isEmpty(data) ? (
|
||||||
<ComponentGlobal_IsEmptyData />
|
<ComponentGlobal_IsEmptyData />
|
||||||
) : (
|
) : (
|
||||||
// --- Main component --- //
|
// --- Main component --- //
|
||||||
@@ -97,7 +103,7 @@ export function Job_UiBeranda({ listData }: { listData: MODEL_JOB[] }) {
|
|||||||
</Center>
|
</Center>
|
||||||
)}
|
)}
|
||||||
data={data}
|
data={data}
|
||||||
setData={setData}
|
setData={setData as any}
|
||||||
moreData={async () => {
|
moreData={async () => {
|
||||||
const loadData = await job_getAllListPublish({
|
const loadData = await job_getAllListPublish({
|
||||||
page: activePage + 1,
|
page: activePage + 1,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { MODEL_JOB } from "../../model/interface";
|
import { MODEL_JOB } from "../../model/interface";
|
||||||
import { Job_UiBeranda } from "./ui_beranda";
|
import { Job_UiBeranda } from "./ui_beranda";
|
||||||
|
|
||||||
export default function Job_ViewBeranda({ listJob }: { listJob: MODEL_JOB[] }) {
|
export default function Job_ViewBeranda() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Job_UiBeranda listData={listJob} />
|
<Job_UiBeranda />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,10 +56,8 @@ export function Profile_ComponentCreateNewProfile({
|
|||||||
dirId: DIRECTORY_ID.profile_foto,
|
dirId: DIRECTORY_ID.profile_foto,
|
||||||
});
|
});
|
||||||
if (!uploadPhoto.success) {
|
if (!uploadPhoto.success) {
|
||||||
setLoading(false);
|
ComponentGlobal_NotifikasiPeringatan("Gagal upload foto profile");
|
||||||
return ComponentGlobal_NotifikasiPeringatan(
|
return;
|
||||||
"Gagal upload foto profile"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uploadBackground = await funGlobal_UploadToStorage({
|
const uploadBackground = await funGlobal_UploadToStorage({
|
||||||
@@ -67,10 +65,8 @@ export function Profile_ComponentCreateNewProfile({
|
|||||||
dirId: DIRECTORY_ID.profile_background,
|
dirId: DIRECTORY_ID.profile_background,
|
||||||
});
|
});
|
||||||
if (!uploadBackground.success) {
|
if (!uploadBackground.success) {
|
||||||
setLoading(false);
|
ComponentGlobal_NotifikasiPeringatan("Gagal upload background profile");
|
||||||
return ComponentGlobal_NotifikasiPeringatan(
|
return;
|
||||||
"Gagal upload background profile"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = await funCreateNewProfile({
|
const create = await funCreateNewProfile({
|
||||||
@@ -78,15 +74,24 @@ export function Profile_ComponentCreateNewProfile({
|
|||||||
imageId: uploadPhoto.data.id,
|
imageId: uploadPhoto.data.id,
|
||||||
imageBackgroundId: uploadBackground.data.id,
|
imageBackgroundId: uploadBackground.data.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (create.status === 201) {
|
if (create.status === 201) {
|
||||||
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
|
ComponentGlobal_NotifikasiBerhasil("Berhasil membuat profile", 3000);
|
||||||
router.push(RouterHome.main_home, { scroll: false });
|
router.push(RouterHome.main_home, { scroll: false });
|
||||||
} else {
|
|
||||||
ComponentGlobal_NotifikasiGagal(create.message);
|
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (create.status === 400) {
|
||||||
|
ComponentGlobal_NotifikasiGagal(create.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (create.status === 500) {
|
||||||
|
ComponentGlobal_NotifikasiGagal(create.message);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log("Terjadi kesalahan", error);
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
"use server";
|
"use server";
|
||||||
|
|
||||||
import prisma from "@/app/lib/prisma";
|
import prisma from "@/app/lib/prisma";
|
||||||
import { MODEL_PROFILE } from "../model/interface";
|
|
||||||
import _ from "lodash";
|
|
||||||
import { v4 } from "uuid";
|
|
||||||
import fs from "fs";
|
|
||||||
import { revalidatePath } from "next/cache";
|
|
||||||
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
import { RouterHome } from "@/app/lib/router_hipmi/router_home";
|
||||||
import { Prisma } from "@prisma/client";
|
|
||||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||||
|
import { Prisma } from "@prisma/client";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
|
||||||
export default async function funCreateNewProfile({
|
export default async function funCreateNewProfile({
|
||||||
data,
|
data,
|
||||||
@@ -19,33 +15,53 @@ export default async function funCreateNewProfile({
|
|||||||
imageId: string;
|
imageId: string;
|
||||||
imageBackgroundId: string;
|
imageBackgroundId: string;
|
||||||
}) {
|
}) {
|
||||||
const userLoginId = await funGetUserIdByToken();
|
try {
|
||||||
|
const userLoginId = await funGetUserIdByToken();
|
||||||
|
|
||||||
const findEmail = await prisma.profile.findUnique({
|
if (!userLoginId) {
|
||||||
where: {
|
return { status: 400, message: "User tidak terautentikasi" }; // Validasi user login
|
||||||
email: data.email,
|
}
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (findEmail) return { status: 400, message: "Email telah digunakan" };
|
const findEmail = await prisma.profile.findUnique({
|
||||||
|
where: {
|
||||||
|
email: data.email,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const createProfile = await prisma.profile.create({
|
if (findEmail) {
|
||||||
data: {
|
return { status: 400, message: "Email telah digunakan" };
|
||||||
userId: userLoginId,
|
}
|
||||||
name: data.name,
|
|
||||||
email: data.email,
|
|
||||||
alamat: data.alamat,
|
|
||||||
jenisKelamin: data.jenisKelamin,
|
|
||||||
imageId: imageId,
|
|
||||||
imageBackgroundId: imageBackgroundId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!createProfile) return { status: 400, message: "Gagal membuat profile" };
|
const createProfile = await prisma.profile.create({
|
||||||
revalidatePath(RouterHome.main_home);
|
data: {
|
||||||
|
userId: userLoginId,
|
||||||
|
name: data.name,
|
||||||
|
email: data.email,
|
||||||
|
alamat: data.alamat,
|
||||||
|
jenisKelamin: data.jenisKelamin,
|
||||||
|
imageId: imageId,
|
||||||
|
imageBackgroundId: imageBackgroundId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
if (!createProfile) {
|
||||||
status: 201,
|
return { status: 400, message: "Gagal membuat profile" };
|
||||||
message: "Berhasil",
|
}
|
||||||
};
|
|
||||||
|
// Revalidate cache halaman home
|
||||||
|
try {
|
||||||
|
revalidatePath(RouterHome.main_home);
|
||||||
|
} catch (cacheError) {
|
||||||
|
console.error("Cache revalidation failed:", cacheError);
|
||||||
|
// Tidak membuat fungsi gagal, cukup log error cache
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
status: 201,
|
||||||
|
message: "Berhasil",
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error creating profile:", error);
|
||||||
|
return { status: 500, message: "Terjadi kesalahan pada server" };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const middlewareConfig: MiddlewareConfig = {
|
|||||||
publicRoutes: [
|
publicRoutes: [
|
||||||
"/",
|
"/",
|
||||||
"/api/upload",
|
"/api/upload",
|
||||||
|
"/api/job/*",
|
||||||
"/api/validation",
|
"/api/validation",
|
||||||
"/api/auth/*",
|
"/api/auth/*",
|
||||||
"/api/origin-url",
|
"/api/origin-url",
|
||||||
|
|||||||
Reference in New Issue
Block a user