Fix: Job
Deskripsi: - Fix notifikasi admi to user - Fix count notifikasi di admin dan user ## No Issue
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterJob } from "@/app/lib/router_hipmi/router_job";
|
||||
import { AccentColor, MainColor } from "@/app_modules/_global/color";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
@@ -10,13 +11,13 @@ import {
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { notifikasiToAdmin_funCreate } from "@/app_modules/notifikasi/fun";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Button } from "@mantine/core";
|
||||
import { useAtom } from "jotai";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { job_funCreateNoFile, job_funCreateWithFile } from "../../fun";
|
||||
import { gs_job_hot_menu, gs_job_status } from "../../global_state";
|
||||
import { gs_job_hot_menu } from "../../global_state";
|
||||
import { MODEL_JOB } from "../../model/interface";
|
||||
|
||||
function Job_ComponentButtonSaveCreate({
|
||||
@@ -28,9 +29,7 @@ function Job_ComponentButtonSaveCreate({
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
|
||||
const [status, setStatus] = useAtom(gs_job_status);
|
||||
|
||||
async function onCreate() {
|
||||
if (file === null) {
|
||||
@@ -39,7 +38,8 @@ function Job_ComponentButtonSaveCreate({
|
||||
});
|
||||
|
||||
if (createNoFile.status === 201) {
|
||||
const dataNotif: any = {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
userRole: "ADMIN",
|
||||
appId: createNoFile.data?.id as any,
|
||||
status: createNoFile.data?.MasterStatus?.name as any,
|
||||
userId: createNoFile.data?.authorId as any,
|
||||
@@ -49,18 +49,16 @@ function Job_ComponentButtonSaveCreate({
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
setHotMenu(2);
|
||||
setStatus("Review");
|
||||
router.replace(RouterJob.status({ id: "2" }));
|
||||
setIsLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(createNoFile.message);
|
||||
@@ -83,9 +81,10 @@ function Job_ComponentButtonSaveCreate({
|
||||
});
|
||||
|
||||
if (createWithFile.status === 201) {
|
||||
const dataNotif: any = {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
userRole: "ADMIN",
|
||||
appId: createWithFile.data?.id as any,
|
||||
status: createWithFile.data?.MasterStatus?.name as any,
|
||||
status: "Review",
|
||||
userId: createWithFile.data?.authorId as any,
|
||||
pesan: createWithFile.data?.title as any,
|
||||
kategoriApp: "JOB",
|
||||
@@ -93,18 +92,16 @@ function Job_ComponentButtonSaveCreate({
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "ADMIN",
|
||||
});
|
||||
|
||||
setHotMenu(2);
|
||||
setStatus("Review");
|
||||
router.replace(RouterJob.status({ id: "2" }));
|
||||
setIsLoading(true);
|
||||
ComponentGlobal_NotifikasiBerhasil(createWithFile.message);
|
||||
|
||||
@@ -41,7 +41,6 @@ export default function Job_Create() {
|
||||
content: "",
|
||||
deskripsi: "",
|
||||
});
|
||||
const [reload, setReload] = useState(false);
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [img, setImg] = useState<any | null>();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { useAtom } from "jotai";
|
||||
import { Job_funEditArsipById } from "../../fun/edit/fun_edit_arsip_by_id";
|
||||
import { gs_job_status, gs_job_hot_menu } from "../../global_state";
|
||||
import { gs_job_hot_menu } from "../../global_state";
|
||||
import { useState } from "react";
|
||||
import { useDisclosure } from "@mantine/hooks";
|
||||
import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal";
|
||||
@@ -28,14 +28,12 @@ export default function Job_DetailArsip({ dataJob }: { dataJob: MODEL_JOB }) {
|
||||
function ButtonAction({ jobId }: { jobId: string }) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
const [status, setStatus] = useAtom(gs_job_status);
|
||||
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
|
||||
const [opened, { open, close }] = useDisclosure();
|
||||
|
||||
async function onPublish() {
|
||||
await Job_funEditArsipById(jobId, false).then((res) => {
|
||||
if (res.status === 200) {
|
||||
setStatus("Publish");
|
||||
setHotMenu(1);
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil Dipublish");
|
||||
setLoading(true);
|
||||
|
||||
@@ -14,7 +14,7 @@ import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import ComponentJob_DetailData from "../../component/detail/detail_data";
|
||||
import { Job_funEditArsipById } from "../../fun/edit/fun_edit_arsip_by_id";
|
||||
import { gs_job_hot_menu, gs_job_status } from "../../global_state";
|
||||
import { gs_job_hot_menu, } from "../../global_state";
|
||||
import { MODEL_JOB } from "../../model/interface";
|
||||
import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal";
|
||||
|
||||
@@ -34,13 +34,13 @@ function ButtonAction({ jobId }: { jobId: string }) {
|
||||
const [isLoading, setLoading] = useState(false);
|
||||
const [opened, { open, close }] = useDisclosure();
|
||||
|
||||
const [status, setStatus] = useAtom(gs_job_status);
|
||||
|
||||
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
|
||||
|
||||
async function onArsipkan() {
|
||||
await Job_funEditArsipById(jobId, true).then((res) => {
|
||||
if (res.status === 200) {
|
||||
setStatus("Publish");
|
||||
|
||||
setHotMenu(3);
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil Diarsipkan");
|
||||
setLoading(true);
|
||||
|
||||
@@ -35,90 +35,10 @@ export async function job_funCreateWithFile({
|
||||
});
|
||||
|
||||
if (!createDataWithoutImg) return { status: 400, message: "Gagal Disimpan" };
|
||||
revalidatePath("/dev/job/main/status");
|
||||
revalidatePath("/dev/job/main/status/2");
|
||||
return {
|
||||
data: createDataWithoutImg,
|
||||
status: 201,
|
||||
message: "Berhasil Disimpan",
|
||||
};
|
||||
|
||||
// const dataImage: any = file.get("file");
|
||||
// if (dataImage !== "null") {
|
||||
// const fileName = dataImage.name;
|
||||
// const fileExtension = _.lowerCase(dataImage.name.split(".").pop());
|
||||
// const fRandomName = v4(fileName) + "." + fileExtension;
|
||||
|
||||
// const upload = await prisma.images.create({
|
||||
// data: {
|
||||
// url: fRandomName,
|
||||
// label: "JOB",
|
||||
// },
|
||||
// select: {
|
||||
// id: true,
|
||||
// url: true,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!upload) return { status: 400, message: "Gagal upload gambar" };
|
||||
// const uploadFolder = Buffer.from(await dataImage.arrayBuffer());
|
||||
// fs.writeFileSync(
|
||||
// path.join(root, `public/job/${upload.url}`),
|
||||
// uploadFolder
|
||||
// );
|
||||
// const createDataWithImg = await prisma.job.create({
|
||||
// data: {
|
||||
// title: req.title,
|
||||
// content: req.content,
|
||||
// deskripsi: req.deskripsi,
|
||||
// authorId: authorId,
|
||||
// imagesId: upload.id,
|
||||
// },
|
||||
// select: {
|
||||
// id: true,
|
||||
// authorId: true,
|
||||
// MasterStatus: {
|
||||
// select: {
|
||||
// name: true,
|
||||
// },
|
||||
// },
|
||||
// title: true,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!createDataWithImg) return { status: 400, message: "Gagal Disimpan" };
|
||||
// revalidatePath("/dev/job/main/status");
|
||||
// return {
|
||||
// data: createDataWithImg,
|
||||
// status: 201,
|
||||
// message: "Berhasil Disimpan",
|
||||
// };
|
||||
// } else {
|
||||
// const createDataWithoutImg = await prisma.job.create({
|
||||
// data: {
|
||||
// title: req.title,
|
||||
// content: req.content,
|
||||
// deskripsi: req.deskripsi,
|
||||
// authorId: authorId,
|
||||
// },
|
||||
// select: {
|
||||
// id: true,
|
||||
// authorId: true,
|
||||
// MasterStatus: {
|
||||
// select: {
|
||||
// name: true,
|
||||
// },
|
||||
// },
|
||||
// title: true,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!createDataWithoutImg)
|
||||
// return { status: 400, message: "Gagal Disimpan" };
|
||||
// revalidatePath("/dev/job/main/status");
|
||||
// return {
|
||||
// data: createDataWithoutImg,
|
||||
// status: 201,
|
||||
// message: "Berhasil Disimpan",
|
||||
// };
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -5,5 +5,3 @@ import { atomWithStorage } from "jotai/utils";
|
||||
* @returns halaman pada layout
|
||||
*/
|
||||
export const gs_job_hot_menu = atomWithStorage("gs_jobs_hot_menu", 1);
|
||||
|
||||
export const gs_job_status = atomWithStorage<any>("gs_job_status", "Publish");
|
||||
|
||||
@@ -5,19 +5,18 @@ import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconBriefcase } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
|
||||
import { gs_job_hot_menu, gs_job_status } from "../global_state";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { RouterJob } from "@/app/lib/router_hipmi/router_job";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { gs_job_hot_menu } from "../global_state";
|
||||
|
||||
export function Job_UiSplash() {
|
||||
const router = useRouter();
|
||||
const [hotMenu, setHotMenu] = useAtom(gs_job_hot_menu);
|
||||
const [status, setStatus] = useAtom(gs_job_status);
|
||||
|
||||
|
||||
useShallowEffect(() => {
|
||||
setTimeout(() => {
|
||||
setHotMenu(1);
|
||||
setStatus("Publish");
|
||||
router.replace(RouterJob.beranda, { scroll: false });
|
||||
}, 1000);
|
||||
}, []);
|
||||
|
||||
Reference in New Issue
Block a user