fix create job

This commit is contained in:
2025-04-09 16:12:09 +08:00
parent eb0421b3bc
commit a11f11d425
2 changed files with 175 additions and 179 deletions

View File

@@ -41,184 +41,20 @@ function Job_ComponentButtonSaveCreate({
const [isLoading, setIsLoading] = useState(false);
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
// async function onCreate() {
// try {
// setIsLoading(true);
// 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) {
// WibuRealtime.setData({
// type: "notification",
// pushNotificationTo: "ADMIN",
// });
// WibuRealtime.setData({
// type: "trigger",
// pushNotificationTo: "ADMIN",
// dataMessage: dataNotifikasi,
// });
// setHotMenu(2);
// router.replace(RouterJob.status({ id: "2" }));
// ComponentGlobal_NotifikasiBerhasil(createNoFile.message);
// }
// } else {
// setIsLoading(false);
// ComponentGlobal_NotifikasiGagal(createNoFile.message);
// }
// } else {
// const uploadFile = await funGlobal_UploadToStorage({
// file: file,
// dirId: DIRECTORY_ID.job_image,
// });
// if (!uploadFile.success) {
// setIsLoading(false);
// 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 {
// setIsLoading(false);
// ComponentGlobal_NotifikasiGagal(createWithFile.message);
// }
// }
// } catch (error) {
// setIsLoading(false);
// clientLogger.error("Error create job", error);
// }
// }
async function handleCreated() {
async function onCreate() {
try {
let fixData;
setIsLoading(true);
if (file === null) {
fixData = {
...value,
authorId: userLoginId,
};
const responseNoFile = await apiCreatedJob({
data: fixData,
const createNoFile = await job_funCreateNoFile({
data: value,
});
if (responseNoFile) {
if (createNoFile.status === 201) {
const dataNotifikasi: IRealtimeData = {
appId: responseNoFile.data?.id as any,
status: responseNoFile.data?.MasterStatus?.name as any,
userId: responseNoFile.data?.authorId as any,
pesan: responseNoFile.data?.title as any,
kategoriApp: "JOB",
title: "Job baru",
};
const responseNotification = await apiCreatedNotificationToAdmin({
data: dataNotifikasi,
});
if (responseNotification) {
WibuRealtime.setData({
type: "notification",
pushNotificationTo: "ADMIN",
});
WibuRealtime.setData({
type: "trigger",
pushNotificationTo: "ADMIN",
dataMessage: dataNotifikasi,
});
setHotMenu(2);
router.replace(RouterJob.status({ id: "2" }));
ComponentGlobal_NotifikasiBerhasil(responseNoFile.message);
}
}
// else {
// setIsLoading(false);
// ComponentGlobal_NotifikasiGagal(responseNoFile.message);
// }
} else {
const uploadFile = await funGlobal_UploadToStorage({
file: file,
dirId: DIRECTORY_ID.job_image,
});
if (!uploadFile.success) {
setIsLoading(false);
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
return;
}
fixData = {
...value,
authorId: userLoginId,
imageId: uploadFile.data.id,
};
const responseWithFile = await apiCreatedJob({
data: fixData,
});
if (responseWithFile.status === 201) {
const dataNotifikasi: IRealtimeData = {
appId: responseWithFile.data?.id as any,
status: responseWithFile.data?.MasterStatus?.name as any,
userId: responseWithFile.data?.authorId as any,
pesan: responseWithFile.data?.title as any,
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",
};
@@ -241,9 +77,64 @@ function Job_ComponentButtonSaveCreate({
setHotMenu(2);
router.replace(RouterJob.status({ id: "2" }));
ComponentGlobal_NotifikasiBerhasil(responseWithFile.message);
ComponentGlobal_NotifikasiBerhasil(createNoFile.message);
}
}
} else {
setIsLoading(false);
ComponentGlobal_NotifikasiGagal(createNoFile.message);
}
} else {
const uploadFile = await funGlobal_UploadToStorage({
file: file,
dirId: DIRECTORY_ID.job_image,
});
if (!uploadFile.success) {
setIsLoading(false);
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 {
setIsLoading(false);
ComponentGlobal_NotifikasiGagal(createWithFile.message);
}
}
} catch (error) {
setIsLoading(false);
@@ -251,6 +142,115 @@ function Job_ComponentButtonSaveCreate({
}
}
// async function handleCreated() {
// try {
// let fixData;
// setIsLoading(true);
// if (file === null) {
// fixData = {
// ...value,
// authorId: userLoginId,
// };
// const responseNoFile = await apiCreatedJob({
// data: fixData,
// });
// if (responseNoFile) {
// const dataNotifikasi: IRealtimeData = {
// appId: responseNoFile.data?.id as any,
// status: responseNoFile.data?.MasterStatus?.name as any,
// userId: responseNoFile.data?.authorId as any,
// pesan: responseNoFile.data?.title as any,
// kategoriApp: "JOB",
// title: "Job baru",
// };
// const responseNotification = await apiCreatedNotificationToAdmin({
// data: dataNotifikasi,
// });
// if (responseNotification) {
// WibuRealtime.setData({
// type: "notification",
// pushNotificationTo: "ADMIN",
// });
// WibuRealtime.setData({
// type: "trigger",
// pushNotificationTo: "ADMIN",
// dataMessage: dataNotifikasi,
// });
// setHotMenu(2);
// router.replace(RouterJob.status({ id: "2" }));
// ComponentGlobal_NotifikasiBerhasil(responseNoFile.message);
// }
// }
// // else {
// // setIsLoading(false);
// // ComponentGlobal_NotifikasiGagal(responseNoFile.message);
// // }
// } else {
// const uploadFile = await funGlobal_UploadToStorage({
// file: file,
// dirId: DIRECTORY_ID.job_image,
// });
// if (!uploadFile.success) {
// setIsLoading(false);
// ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
// return;
// }
// fixData = {
// ...value,
// authorId: userLoginId,
// imageId: uploadFile.data.id,
// };
// const responseWithFile = await apiCreatedJob({
// data: fixData,
// });
// if (responseWithFile.status === 201) {
// const dataNotifikasi: IRealtimeData = {
// appId: responseWithFile.data?.id as any,
// status: responseWithFile.data?.MasterStatus?.name as any,
// userId: responseWithFile.data?.authorId as any,
// pesan: responseWithFile.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(responseWithFile.message);
// }
// }
// }
// } catch (error) {
// setIsLoading(false);
// clientLogger.error("Error create job", error);
// }
// }
return (
<>
<Button
@@ -287,7 +287,7 @@ function Job_ComponentButtonSaveCreate({
loading={isLoading ? true : false}
w={"100%"}
radius={"xl"}
onClick={handleCreated}
onClick={onCreate}
>
Simpan
</Button>

View File

@@ -92,8 +92,6 @@ export const middleware = async (req: NextRequest) => {
const token = getToken(req, sessionKey);
const user = await verifyToken({ token, encodedKey });
console.log("Request URL v2 >>", req.url);
// Handle login page access
if (pathname === loginPath) {
if (user) {
@@ -128,8 +126,6 @@ export const middleware = async (req: NextRequest) => {
}
try {
const originURL = process.env.NEXT_PUBLIC_API_URL;
console.log("Origin URL >> ", originURL);
const apiBaseUrl =
process.env.NEXT_PUBLIC_API_URL || new URL(req.url).origin;