Fix: Voting
Deskripsi: - Fix notifikasi admin to user - Fix notifikasi user to admin ## No Issue
This commit is contained in:
@@ -17,6 +17,11 @@ import ComponentVote_DetailDataSebelumPublish from "../../component/detail/detai
|
||||
import { Vote_funDeleteById } from "../../fun/delete/fun_delete_by_id";
|
||||
import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id";
|
||||
import { MODEL_VOTING } from "../../model/interface";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id";
|
||||
import _ from "lodash";
|
||||
|
||||
export default function Vote_DetailDraft({
|
||||
dataVote,
|
||||
@@ -24,13 +29,21 @@ export default function Vote_DetailDraft({
|
||||
dataVote: MODEL_VOTING;
|
||||
}) {
|
||||
const [data, setData] = useState(dataVote);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadData(setData);
|
||||
}, [setData]);
|
||||
|
||||
async function onLoadData(setData: any) {
|
||||
const loadData = await voting_funGetOneVotingbyId(dataVote.id);
|
||||
setData(loadData);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack spacing={"xl"}>
|
||||
{dataVote?.catatan ? (
|
||||
{dataVote?.catatan && (
|
||||
<ComponentGlobal_BoxInformation isReport informasi={data?.catatan} />
|
||||
) : (
|
||||
""
|
||||
)}
|
||||
<ComponentVote_DetailDataSebelumPublish data={data} />
|
||||
<ButtonAction voteId={data.id} awalVote={data.awalVote} />
|
||||
@@ -60,7 +73,7 @@ function ButtonAction({
|
||||
|
||||
const res = await Vote_funEditStatusByStatusId(voteId, "2");
|
||||
if (res.status === 200) {
|
||||
const dataNotif: any = {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
@@ -70,16 +83,20 @@ function ButtonAction({
|
||||
};
|
||||
|
||||
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",
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "ADMIN",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil Ajukan Review", 2000);
|
||||
setIsLoading(true);
|
||||
|
||||
@@ -4,7 +4,10 @@ import {
|
||||
AccentColor,
|
||||
MainColor,
|
||||
} from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentGlobal_AvatarAndUsername, ComponentGlobal_CardStyles } from "@/app_modules/_global/component";
|
||||
import {
|
||||
ComponentGlobal_AvatarAndUsername,
|
||||
ComponentGlobal_CardStyles,
|
||||
} from "@/app_modules/_global/component";
|
||||
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
@@ -19,7 +22,7 @@ import {
|
||||
Radio,
|
||||
Stack,
|
||||
Text,
|
||||
Title
|
||||
Title,
|
||||
} from "@mantine/core";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
@@ -28,6 +31,8 @@ import ComponentVote_HasilVoting from "../../component/detail/detail_hasil_votin
|
||||
import { Vote_funCreateHasil } from "../../fun/create/create_hasil";
|
||||
import { voting_funGetOneVotingbyId } from "../../fun/get/fun_get_one_by_id";
|
||||
import { MODEL_VOTING } from "../../model/interface";
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
|
||||
export default function Vote_MainDetail({
|
||||
dataVote,
|
||||
@@ -88,7 +93,9 @@ function TampilanDataVoting({
|
||||
<>
|
||||
<ComponentGlobal_CardStyles>
|
||||
<Stack>
|
||||
<ComponentGlobal_AvatarAndUsername profile={dataVote?.Author?.Profile as any}/>
|
||||
<ComponentGlobal_AvatarAndUsername
|
||||
profile={dataVote?.Author?.Profile as any}
|
||||
/>
|
||||
{/* <ComponentGlobal_AuthorNameOnHeader
|
||||
authorName={dataVote?.Author.Profile.name}
|
||||
imagesId={dataVote?.Author.Profile.imagesId}
|
||||
@@ -218,7 +225,6 @@ function TampilanDataVoting({
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
</ComponentGlobal_CardStyles>
|
||||
</>
|
||||
);
|
||||
@@ -238,27 +244,25 @@ async function onVote(
|
||||
});
|
||||
|
||||
if (userLoginId !== res?.data?.Voting?.authorId) {
|
||||
const dataNotif = {
|
||||
appId: res?.data?.Voting?.id,
|
||||
userId: res?.data?.Voting?.authorId,
|
||||
pesan: res?.pilihan,
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res?.data?.Voting?.id as string,
|
||||
userId: res?.data?.Voting?.authorId as string,
|
||||
pesan: res?.pilihan as string,
|
||||
status: "Voting Masuk",
|
||||
kategoriApp: "VOTING",
|
||||
title: "User lain telah melakukan voting !",
|
||||
};
|
||||
|
||||
const createNotifikasi = await notifikasiToUser_funCreate({
|
||||
data: dataNotif as any,
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (createNotifikasi.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"USER",
|
||||
JSON.stringify({
|
||||
userId: dataNotif.userId,
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import UIGlobal_Modal from "@/app_modules/_global/ui/ui_modal";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import { Button, Stack } from "@mantine/core";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import ComponentVote_DetailDataSebelumPublish from "../../component/detail/detail_data_sebelum_publish";
|
||||
import { Vote_funEditStatusByStatusId } from "../../fun/edit/fun_edit_status_by_id";
|
||||
import { MODEL_VOTING } from "../../model/interface";
|
||||
import { voting_checkStatus } from "../../fun";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
|
||||
export default function Vote_DetailReview({
|
||||
dataVote,
|
||||
@@ -22,47 +25,65 @@ export default function Vote_DetailReview({
|
||||
<>
|
||||
<Stack spacing={"xl"}>
|
||||
<ComponentVote_DetailDataSebelumPublish data={dataVote as any} />
|
||||
<ButtonAction voteId={dataVote.id} />
|
||||
<ButtonAction
|
||||
voteId={dataVote.id}
|
||||
statusId={dataVote.voting_StatusId}
|
||||
/>
|
||||
</Stack>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function ButtonAction({ voteId }: { voteId: string }) {
|
||||
function ButtonAction({
|
||||
voteId,
|
||||
statusId,
|
||||
}: {
|
||||
voteId: string;
|
||||
statusId: string;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [openModal, setOpenModal] = useState(false);
|
||||
|
||||
async function onUpdate() {
|
||||
const res = await Vote_funEditStatusByStatusId(voteId, "3");
|
||||
if (res.status === 200) {
|
||||
const dataNotif: any = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Membatalkan review",
|
||||
};
|
||||
const check = await voting_checkStatus({ id: voteId });
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
if (check) {
|
||||
const res = await Vote_funEditStatusByStatusId(voteId, "3");
|
||||
if (res.status === 200) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as any,
|
||||
status: res.data?.Voting_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "VOTING",
|
||||
title: "Membatalkan review",
|
||||
};
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
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,
|
||||
});
|
||||
}
|
||||
ComponentGlobal_NotifikasiBerhasil("Berhasil Batalkan Review", 2000);
|
||||
router.replace(RouterVote.status({ id: "3" }));
|
||||
setIsLoading(true);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
ComponentGlobal_NotifikasiPeringatan("Voting telah di terima admin");
|
||||
}
|
||||
}
|
||||
return (
|
||||
@@ -92,7 +113,10 @@ function ButtonAction({ voteId }: { voteId: string }) {
|
||||
loading={isLoading ? true : false}
|
||||
radius={"xl"}
|
||||
color="green"
|
||||
onClick={() => onUpdate()}
|
||||
onClick={() => {
|
||||
onUpdate();
|
||||
console.log(statusId);
|
||||
}}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user