Fix: Voting
Deskripsi: - Fix notifikasi admin to user - Fix notifikasi user to admin ## No Issue
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { IRealtimeData } from "@/app/lib/global_state";
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||
@@ -7,7 +8,6 @@ import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import notifikasiToAdmin_funCreate from "@/app_modules/notifikasi/fun/create/create_notif_to_admin";
|
||||
import mqtt_client from "@/util/mqtt_client";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -23,12 +23,11 @@ import { IconMinus, IconPlus } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { WibuRealtime } from "wibu-pkg";
|
||||
import { Vote_funCreate } from "../fun/create/create_vote";
|
||||
import { gs_vote_hotMenu } from "../global_state";
|
||||
import { MODEL_VOTING } from "../model/interface";
|
||||
|
||||
export default function Vote_Create() {
|
||||
const router = useRouter();
|
||||
@@ -53,6 +52,60 @@ export default function Vote_Create() {
|
||||
},
|
||||
]);
|
||||
|
||||
async function onSave() {
|
||||
if (_.values(data).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
|
||||
const cekAwalVote = moment(data.awalVote).format();
|
||||
if (cekAwalVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
const cekAkhirVote = moment(data.akhirVote).format();
|
||||
if (cekAkhirVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
if (_.values(listVote.map((e) => e.value)).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Pilihan Voting");
|
||||
|
||||
// console.log("berhasil");
|
||||
|
||||
const res = await Vote_funCreate(data as any, listVote);
|
||||
if (res.status === 201) {
|
||||
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: "Voting 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(RouterVote.status({ id: "2" }));
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setIsLoading(true);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack px={"sm"} spacing={"xl"} mb={"xl"}>
|
||||
@@ -208,7 +261,7 @@ export default function Vote_Create() {
|
||||
mt={"lg"}
|
||||
radius={"xl"}
|
||||
onClick={() => {
|
||||
onSave(router, setHotMenu, data as any, listVote, setIsLoading);
|
||||
onSave();
|
||||
}}
|
||||
c={"black"}
|
||||
bg={MainColor.yellow}
|
||||
@@ -223,59 +276,3 @@ export default function Vote_Create() {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
async function onSave(
|
||||
router: AppRouterInstance,
|
||||
setHotMenu: any,
|
||||
data: MODEL_VOTING,
|
||||
listVote: any[],
|
||||
setIsLoading: any
|
||||
) {
|
||||
if (_.values(data).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
|
||||
const cekAwalVote = moment(data.awalVote).format();
|
||||
if (cekAwalVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
const cekAkhirVote = moment(data.akhirVote).format();
|
||||
if (cekAkhirVote === "Invalid date")
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Tanggal");
|
||||
|
||||
if (_.values(listVote.map((e) => e.value)).includes(""))
|
||||
return ComponentGlobal_NotifikasiPeringatan("Lengkapi Pilihan Voting");
|
||||
|
||||
// console.log("berhasil");
|
||||
|
||||
const res = await Vote_funCreate(data, listVote);
|
||||
if (res.status === 201) {
|
||||
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: "Voting baru",
|
||||
};
|
||||
|
||||
const notif = await notifikasiToAdmin_funCreate({
|
||||
data: dataNotif as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
mqtt_client.publish(
|
||||
"ADMIN",
|
||||
JSON.stringify({
|
||||
count: 1,
|
||||
})
|
||||
);
|
||||
|
||||
setHotMenu(2);
|
||||
router.replace(RouterVote.status({ id: "2" }));
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
setIsLoading(true);
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import ComponentGlobal_ErrorInput from "@/app_modules/_global/component/error_input";
|
||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
@@ -9,14 +10,14 @@ import {
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Grid,
|
||||
Group,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
Textarea
|
||||
} from "@mantine/core";
|
||||
import { DatePickerInput } from "@mantine/dates";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { IconPlus, IconTrash } from "@tabler/icons-react";
|
||||
import { useAtom } from "jotai";
|
||||
import _ from "lodash";
|
||||
@@ -24,14 +25,12 @@ import moment from "moment";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { Vote_funEditById } from "../fun/edit/fun_edit_by_id";
|
||||
import { Vote_getListDaftarNamaById } from "../fun/get/get_list_daftar_vote_by_id";
|
||||
import { gs_vote_hotMenu, gs_vote_status } from "../global_state";
|
||||
import {
|
||||
MODEL_VOTING,
|
||||
MODEL_VOTING_DAFTAR_NAMA_VOTE,
|
||||
} from "../model/interface";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { Vote_getListDaftarNamaById } from "../fun/get/get_list_daftar_vote_by_id";
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
|
||||
export default function Vote_Edit({
|
||||
dataVote,
|
||||
|
||||
@@ -7,6 +7,17 @@ export async function Vote_funEditStatusByStatusId(
|
||||
voteId: string,
|
||||
statusId: string
|
||||
) {
|
||||
// if (statusId !== "2") {
|
||||
// const checkStatus = await prisma.voting.findFirst({
|
||||
// where: {
|
||||
// id: voteId,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (checkStatus?.voting_StatusId != "2")
|
||||
// return { status: 400, message: "Status sudah diubah admin" };
|
||||
// }
|
||||
|
||||
const updt = await prisma.voting.update({
|
||||
where: {
|
||||
id: voteId,
|
||||
|
||||
21
src/app_modules/vote/fun/get/fun_check_status.ts
Normal file
21
src/app_modules/vote/fun/get/fun_check_status.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
|
||||
export async function voting_checkStatus({
|
||||
id,
|
||||
}: {
|
||||
id: string;
|
||||
}) {
|
||||
const checkStatus = await prisma.voting.findFirst({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
});
|
||||
|
||||
if(checkStatus?.voting_StatusId == "2") return true
|
||||
return false
|
||||
|
||||
// if (checkStatus?.voting_StatusId == "2") return true;
|
||||
// return false;
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { voting_funUpdateIsArsipById } from "./edit/fun_update_is_arsip_by_id";
|
||||
import { voting_checkStatus } from "./get/fun_check_status";
|
||||
import { voting_getMasterStatus } from "./get/get_list_status_voting";
|
||||
import { vote_funGetAllByStatusId } from "./get/status/get_all_by_status_id";
|
||||
|
||||
export { voting_funUpdateIsArsipById };
|
||||
export { vote_funGetAllByStatusId };
|
||||
export { voting_getMasterStatus };
|
||||
export { voting_checkStatus };
|
||||
|
||||
@@ -3,7 +3,16 @@
|
||||
import { RouterVote } from "@/app/lib/router_hipmi/router_vote";
|
||||
import ComponentGlobal_CreateButton from "@/app_modules/_global/component/button_create";
|
||||
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
|
||||
import { Box, Center, Loader, Stack, TextInput } from "@mantine/core";
|
||||
import {
|
||||
Affix,
|
||||
Box,
|
||||
Button,
|
||||
Center,
|
||||
Loader,
|
||||
rem,
|
||||
Stack,
|
||||
TextInput,
|
||||
} from "@mantine/core";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import _ from "lodash";
|
||||
import { ScrollOnly } from "next-scroll-loader";
|
||||
@@ -11,6 +20,9 @@ import { useState } from "react";
|
||||
import ComponentVote_CardViewPublish from "../component/card_view_publish";
|
||||
import { vote_getAllListPublish } from "../fun/get/get_all_list_publish";
|
||||
import { MODEL_VOTING } from "../model/interface";
|
||||
import { gs_votingTiggerBeranda } from "@/app/lib/global_state";
|
||||
import { useAtom } from "jotai";
|
||||
import { AccentColor } from "@/app_modules/_global/color";
|
||||
|
||||
export default function Vote_Beranda({
|
||||
dataVote,
|
||||
@@ -20,13 +32,27 @@ export default function Vote_Beranda({
|
||||
const [data, setData] = useState(dataVote);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
|
||||
// Realtime
|
||||
const [isTriggerVotingBeranda, setIsTriggerVotingBeranda] = useAtom(
|
||||
gs_votingTiggerBeranda
|
||||
);
|
||||
const [isShowUpdate, setIsShowUpdate] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useShallowEffect(() => {
|
||||
if (isTriggerVotingBeranda) {
|
||||
setIsShowUpdate(true);
|
||||
}
|
||||
}, [isTriggerVotingBeranda, setIsShowUpdate]);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoad({
|
||||
newData(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
}, [setData]);
|
||||
setIsTriggerVotingBeranda(false);
|
||||
}, [setData, setIsTriggerVotingBeranda]);
|
||||
|
||||
async function onLoad({ newData }: { newData: (val: any) => void }) {
|
||||
const loadData = await vote_getAllListPublish({ page: 1 });
|
||||
@@ -38,8 +64,45 @@ export default function Vote_Beranda({
|
||||
setData(loadSearch as any);
|
||||
}
|
||||
|
||||
async function onLoadData({ onPublish }: { onPublish: (val: any) => void }) {
|
||||
setIsLoading(true);
|
||||
const loadData = await vote_getAllListPublish({ page: 1 });
|
||||
onPublish(loadData);
|
||||
|
||||
setIsShowUpdate(false);
|
||||
setIsTriggerVotingBeranda(false);
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<Stack mt={"1vh"}>
|
||||
{isShowUpdate && (
|
||||
<Affix position={{ top: rem(100) }} w={"100%"}>
|
||||
<Center>
|
||||
<Button
|
||||
style={{
|
||||
transition: "0.5s",
|
||||
border: `1px solid ${AccentColor.skyblue}`,
|
||||
}}
|
||||
bg={AccentColor.blue}
|
||||
loaderPosition="center"
|
||||
loading={isLoading}
|
||||
radius={"xl"}
|
||||
opacity={0.8}
|
||||
onClick={() => {
|
||||
onLoadData({
|
||||
onPublish(val) {
|
||||
setData(val);
|
||||
},
|
||||
});
|
||||
}}
|
||||
>
|
||||
Update beranda
|
||||
</Button>
|
||||
</Center>
|
||||
</Affix>
|
||||
)}
|
||||
|
||||
<TextInput
|
||||
radius={"xl"}
|
||||
placeholder="Masukan judul voting"
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface MODEL_VOTING {
|
||||
Author: MODEL_USER;
|
||||
Voting_DaftarNamaVote: MODEL_VOTING_DAFTAR_NAMA_VOTE[];
|
||||
isArsip: boolean;
|
||||
voting_StatusId: string
|
||||
}
|
||||
|
||||
export interface MODEL_VOTING_DAFTAR_NAMA_VOTE {
|
||||
|
||||
Reference in New Issue
Block a user