Merge pull request #247 from bipproduction/bagas/17-jan-25
Fix notifikasi donasi & event new fiture
This commit is contained in:
@@ -68,18 +68,3 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function main({ id }: { id: string }) {
|
||||
const fixData = await prisma.beritaInvestasi.findMany({
|
||||
take: 10,
|
||||
skip: 0,
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
where: {
|
||||
investasiId: id.trim(),
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
console.log("data sebelum disconnect>>", fixData);
|
||||
}
|
||||
|
||||
46
src/app/api/user/all/route.ts
Normal file
46
src/app/api/user/all/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (request.method === "GET") {
|
||||
try {
|
||||
let fixData;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const except_id = searchParams.get("except-id");
|
||||
|
||||
if (!except_id) {
|
||||
fixData = await prisma.user.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
fixData = await prisma.user.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
masterUserRoleId: "1",
|
||||
id: {
|
||||
not: except_id,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data",
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { Donasi_CreateKabar } from "@/app_modules/donasi";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const donasiId = params.id;
|
||||
export default async function Page() {
|
||||
return (
|
||||
<>
|
||||
<Donasi_CreateKabar donasiId={donasiId} />
|
||||
<Donasi_CreateKabar />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Notifikasi_UiMain } from "@/app_modules/notifikasi/_ui";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Notifikasi_UiMain />
|
||||
<Notifikasi_UiMain userLoginId={userLoginId} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
import { Notifikasi_UiMain } from "@/app_modules/notifikasi/_ui";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
return (
|
||||
<>
|
||||
<Notifikasi_UiMain />
|
||||
<Notifikasi_UiMain userLoginId={userLoginId} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,4 @@ process.on("SIGINT", async () => {
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
// console.log("==> Test prisma");
|
||||
|
||||
export default prisma;
|
||||
|
||||
@@ -11,7 +11,7 @@ export const apiGetUserId = async () => {
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Ini di pemanggilan API",await response.json());
|
||||
console.log("Ini di pemanggilan API", await response.json());
|
||||
|
||||
if (!response.ok) return null;
|
||||
const data: Record<string, any> = await response.json();
|
||||
@@ -37,3 +37,24 @@ export const apiGetACtivationUser = async () => {
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
export const apiGetAllUserWithExceptId = async ({
|
||||
exceptId,
|
||||
}: {
|
||||
exceptId?: string;
|
||||
}) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const isExceptId = exceptId ? `?except-id=${exceptId}` : "";
|
||||
|
||||
const response = await fetch(`/api/user/all${isExceptId}`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -18,17 +18,16 @@ import {
|
||||
Title,
|
||||
Tooltip,
|
||||
} from "@mantine/core";
|
||||
import { IconCirclePlus, IconEdit } from "@tabler/icons-react";
|
||||
import { IconEdit } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useState } from "react";
|
||||
import { ComponentAdminGlobal_NotifikasiBerhasil } from "../../_admin_global/admin_notifikasi/notifikasi_berhasil";
|
||||
import { ComponentAdminGlobal_NotifikasiGagal } from "../../_admin_global/admin_notifikasi/notifikasi_gagal";
|
||||
import { AdminAppInformation_ComponentTitlePageBank } from "../component";
|
||||
import adminAppInformation_createBank from "../fun/create/fun_create_new_bank";
|
||||
import adminAppInformation_getMasterBank from "../fun/master/get_list_bank";
|
||||
import adminAppInformation_updateStatusBankById from "../fun/update/fun_udpate_status_bank";
|
||||
import adminAppInformation_updateDataBankById from "../fun/update/fun_update_data_bank";
|
||||
import { ComponentAdminGlobal_TitlePage } from "../../_admin_global/_component";
|
||||
import { AdminAppInformation_ComponentTitlePageBank } from "../component";
|
||||
|
||||
export default function AdminAppInformation_ViewInfoBank({
|
||||
listBank,
|
||||
|
||||
@@ -21,6 +21,9 @@ import { AdminDonasi_funUpdateStatusPublish } from "../fun/update/fun_status_pub
|
||||
import { AdminDonasi_funUpdateStatusReject } from "../fun/update/fun_status_reject";
|
||||
import { donasi_checkStatus } from "@/app_modules/donasi/fun";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import adminNotifikasi_funCreateToAllUser from "../../notifikasi/fun/create/fun_create_notif_to_all_user";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { apiGetAllUserWithExceptId } from "@/app_modules/_global/lib/api_user";
|
||||
|
||||
export default function AdminDonasi_DetailReview({
|
||||
dataReview,
|
||||
@@ -66,51 +69,88 @@ function ButtonOnHeader({
|
||||
const [catatan, setCatatan] = useState("");
|
||||
|
||||
async function onPulish() {
|
||||
const checkStatus = await donasi_checkStatus({ id: donasi.id });
|
||||
try {
|
||||
setLoadingPublish(true);
|
||||
const checkStatus = await donasi_checkStatus({ id: donasi.id });
|
||||
|
||||
if (checkStatus) {
|
||||
const res = await AdminDonasi_funUpdateStatusPublish(donasi.id, "1");
|
||||
if (res.status === 200) {
|
||||
const dataNotifikasi: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "DONASI",
|
||||
title: "Donasi publish",
|
||||
};
|
||||
if (checkStatus) {
|
||||
const res = await AdminDonasi_funUpdateStatusPublish(donasi.id, "1");
|
||||
if (res.status === 200) {
|
||||
// ===== TO CREATEOR ====== //
|
||||
const notifikasiToCreator: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: res.data?.authorId as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "DONASI",
|
||||
title: "Donasi publish",
|
||||
};
|
||||
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: dataNotifikasi as any,
|
||||
});
|
||||
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
const notif = await adminNotifikasi_funCreateToUser({
|
||||
data: notifikasiToCreator as any,
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasi,
|
||||
if (notif.status === 201) {
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: notifikasiToCreator,
|
||||
});
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "trigger",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: notifikasiToCreator,
|
||||
});
|
||||
}
|
||||
|
||||
// ===== TO CREATEOR ====== //
|
||||
|
||||
// TO ALL USER
|
||||
const notificationToAll = await adminNotifikasi_funCreateToAllUser({
|
||||
data: res.data as any,
|
||||
authorId: donasi.authorId,
|
||||
});
|
||||
|
||||
if (notificationToAll.status === 201) {
|
||||
const dataUser = notificationToAll.data;
|
||||
for (let i of dataUser as any) {
|
||||
const dataNotifikasiToAll: IRealtimeData = {
|
||||
appId: res.data?.id as string,
|
||||
status: res.data?.DonasiMaster_Status?.name as any,
|
||||
userId: i.id as any,
|
||||
pesan: res.data?.title as any,
|
||||
kategoriApp: "DONASI",
|
||||
title: "Donasi baru terpublish",
|
||||
};
|
||||
|
||||
|
||||
WibuRealtime.setData({
|
||||
type: "notification",
|
||||
pushNotificationTo: "USER",
|
||||
dataMessage: dataNotifikasiToAll,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const newData = await AdminDonasi_getOneById(donasi?.id);
|
||||
setData(newData);
|
||||
ComponentAdminGlobal_NotifikasiBerhasil(
|
||||
"Berhasil Mengubah Status Donasi"
|
||||
);
|
||||
setLoadingPublish(true);
|
||||
} else {
|
||||
setLoadingPublish(false);
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Gagal Mengubah Status Donasi"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
ComponentAdminGlobal_NotifikasiPeringatan(
|
||||
"Gagal Mengubah Status Donasi"
|
||||
);
|
||||
setLoadingPublish(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Status donasi telah diubah user");
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan("Status donasi telah diubah user");
|
||||
} catch (error) {
|
||||
setLoadingPublish(false);
|
||||
clientLogger.error("Error to published donasi", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,6 +210,8 @@ function ButtonOnHeader({
|
||||
{donasi.donasiMaster_StatusDonasiId === "2" ? (
|
||||
<Group>
|
||||
<Button
|
||||
loading={isLoadingPublish}
|
||||
loaderPosition="center"
|
||||
radius={"xl"}
|
||||
bg={"green"}
|
||||
color="green"
|
||||
|
||||
@@ -36,5 +36,7 @@ export async function AdminDonasi_getOneById(id: string) {
|
||||
imageId: true,
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -32,8 +32,14 @@ export async function AdminDonasi_funUpdateStatusPublish(
|
||||
},
|
||||
});
|
||||
|
||||
if (!data) return { status: 400, message: "Data tidak ditemukan" };
|
||||
if (!data) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Data tidak ditemukan" };
|
||||
}
|
||||
|
||||
revalidatePath(RouterAdminDonasi.table_review);
|
||||
await prisma.$disconnect();
|
||||
|
||||
return {
|
||||
data: data,
|
||||
status: 200,
|
||||
|
||||
@@ -113,7 +113,7 @@ export function Admin_NewLayout({
|
||||
<Grid>
|
||||
<Grid.Col span={7}>
|
||||
<Title order={3} lineClamp={1}>
|
||||
{userRoleId == "2" ? "Admin" : "Developer"}
|
||||
{userRoleId == "2" ? "Admin" : "SuperAdmin"}
|
||||
</Title>
|
||||
</Grid.Col>
|
||||
|
||||
@@ -130,7 +130,8 @@ export function Admin_NewLayout({
|
||||
onLoadListNotifikasi();
|
||||
}}
|
||||
>
|
||||
{countNtf == 0 ? (
|
||||
{countNtf == 0 ||
|
||||
dataUser.masterUserRoleId == "3" ? (
|
||||
<IconBell color="white" />
|
||||
) : (
|
||||
<Indicator
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||
|
||||
export default async function adminNotifikasi_funCreateToAllUser({
|
||||
data,
|
||||
authorId,
|
||||
}: {
|
||||
data: any;
|
||||
authorId: string;
|
||||
}) {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
const dataUser = await prisma.user.findMany({
|
||||
where: {
|
||||
NOT: {
|
||||
id: authorId,
|
||||
},
|
||||
active: true,
|
||||
masterUserRoleId: "1",
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of dataUser) {
|
||||
const create = await prisma.notifikasi.create({
|
||||
data: {
|
||||
adminId: userLoginId,
|
||||
userId: i.id,
|
||||
appId: data.id,
|
||||
status: data.DonasiMaster_Status.name,
|
||||
title: "Donasi baru terpublish",
|
||||
pesan: data.title,
|
||||
kategoriApp: "DONASI",
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
if (!create) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return {
|
||||
status: 201,
|
||||
message: "Berhasil mengirim notifikasi",
|
||||
data: dataUser,
|
||||
};
|
||||
}
|
||||
@@ -23,7 +23,12 @@ export default async function adminNotifikasi_funCreateToUser({
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
|
||||
if (!create) {
|
||||
await prisma.$disconnect();
|
||||
return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
}
|
||||
|
||||
await prisma.$disconnect();
|
||||
return { status: 201, message: "Berhasil mengirim notifikasi" };
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { MainColor } from "@/app_modules/_global/color";
|
||||
import {
|
||||
ComponentGlobal_BoxInformation,
|
||||
ComponentGlobal_BoxUploadImage,
|
||||
ComponentGlobal_ButtonUploadFileImage,
|
||||
ComponentGlobal_InputCountDown,
|
||||
ComponentGlobal_LoadImageCustom,
|
||||
} from "@/app_modules/_global/component";
|
||||
import {
|
||||
AspectRatio,
|
||||
Button,
|
||||
FileButton,
|
||||
Group,
|
||||
Image,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import { IconCamera, IconUpload } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { MODEL_DONASI_KABAR } from "../../model/interface";
|
||||
funGlobal_DeleteFileById,
|
||||
funGlobal_UploadToStorage,
|
||||
} from "@/app_modules/_global/fun";
|
||||
import {
|
||||
ComponentGlobal_NotifikasiBerhasil,
|
||||
ComponentGlobal_NotifikasiGagal,
|
||||
ComponentGlobal_NotifikasiPeringatan,
|
||||
} from "@/app_modules/_global/notif_global";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import {
|
||||
funGlobal_DeleteFileById,
|
||||
funGlobal_UploadToStorage,
|
||||
} from "@/app_modules/_global/fun";
|
||||
AspectRatio,
|
||||
Button,
|
||||
Center,
|
||||
Image,
|
||||
Stack,
|
||||
TextInput,
|
||||
Textarea,
|
||||
} from "@mantine/core";
|
||||
import { IconPhoto } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { donasi_funUpdateKabar } from "../../fun";
|
||||
import { MODEL_DONASI_KABAR } from "../../model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export function Donasi_ViewEditKabar({
|
||||
dataKabar,
|
||||
@@ -59,9 +59,8 @@ export function Donasi_ViewEditKabar({
|
||||
|
||||
if (!uploadImage.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload file gambar"
|
||||
);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await donasi_funUpdateKabar({
|
||||
@@ -72,12 +71,15 @@ export function Donasi_ViewEditKabar({
|
||||
if (res.status === 200) {
|
||||
setLoading(false);
|
||||
|
||||
const deleteImage = await funGlobal_DeleteFileById({
|
||||
fileId: data.imageId,
|
||||
});
|
||||
if (!deleteImage.success) {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal hapus gambar lama");
|
||||
if (dataKabar.imageId !== null) {
|
||||
const deleteImage = await funGlobal_DeleteFileById({
|
||||
fileId: data.imageId,
|
||||
});
|
||||
|
||||
if (!deleteImage.success) {
|
||||
setLoading(false);
|
||||
clientLogger.error("Gagal hapus gambar lama");
|
||||
}
|
||||
}
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
@@ -92,7 +94,6 @@ export function Donasi_ViewEditKabar({
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
setLoading(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
} else {
|
||||
@@ -101,7 +102,8 @@ export function Donasi_ViewEditKabar({
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setLoading(false);
|
||||
clientLogger.error("Error update donasi", error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +131,7 @@ export function Donasi_ViewEditKabar({
|
||||
}}
|
||||
/>
|
||||
<Textarea
|
||||
maxLength={500}
|
||||
maxLength={1000}
|
||||
styles={{
|
||||
label: {
|
||||
color: "white",
|
||||
@@ -139,7 +141,7 @@ export function Donasi_ViewEditKabar({
|
||||
withAsterisk
|
||||
placeholder="Masukan deskripsi kabar"
|
||||
autosize
|
||||
maxRows={4}
|
||||
maxRows={10}
|
||||
minRows={2}
|
||||
value={data.deskripsi}
|
||||
onChange={(val) => {
|
||||
@@ -151,7 +153,7 @@ export function Donasi_ViewEditKabar({
|
||||
/>
|
||||
<ComponentGlobal_InputCountDown
|
||||
lengthInput={data.deskripsi.length}
|
||||
maxInput={500}
|
||||
maxInput={1000}
|
||||
/>
|
||||
|
||||
<Stack spacing={5}>
|
||||
@@ -167,10 +169,7 @@ export function Donasi_ViewEditKabar({
|
||||
</AspectRatio>
|
||||
) : data.imageId === null ? (
|
||||
<Stack justify="center" align="center" h={"100%"}>
|
||||
<IconUpload color="white" />
|
||||
<Text fz={10} fs={"italic"} c={"white"} fw={"bold"}>
|
||||
Upload Gambar
|
||||
</Text>
|
||||
<IconPhoto size={100} />
|
||||
</Stack>
|
||||
) : (
|
||||
<Stack justify="center" align="center" h={"100%"} p={"sm"}>
|
||||
@@ -183,35 +182,12 @@ export function Donasi_ViewEditKabar({
|
||||
</ComponentGlobal_BoxUploadImage>
|
||||
|
||||
{/* Upload Foto */}
|
||||
<Group position="center">
|
||||
<FileButton
|
||||
onChange={async (files: any) => {
|
||||
try {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
setImg(buffer);
|
||||
setFile(files);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}}
|
||||
accept="image/png,image/jpeg"
|
||||
>
|
||||
{(props) => (
|
||||
<Button
|
||||
{...props}
|
||||
leftIcon={<IconCamera color="black" />}
|
||||
radius={50}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
>
|
||||
Upload Gambar
|
||||
</Button>
|
||||
)}
|
||||
</FileButton>
|
||||
</Group>
|
||||
<Center>
|
||||
<ComponentGlobal_ButtonUploadFileImage
|
||||
onSetFile={setFile}
|
||||
onSetImage={setImg}
|
||||
/>
|
||||
</Center>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -1,33 +1,38 @@
|
||||
"use client";
|
||||
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
import { MainColor } from "@/app_modules/_global/color/color_pallet";
|
||||
import { ComponentGlobal_BoxUploadImage } from "@/app_modules/_global/component";
|
||||
import {
|
||||
ComponentGlobal_BoxUploadImage,
|
||||
ComponentGlobal_ButtonUploadFileImage,
|
||||
} from "@/app_modules/_global/component";
|
||||
import ComponentGlobal_BoxInformation from "@/app_modules/_global/component/box_information";
|
||||
import ComponentGlobal_InputCountDown from "@/app_modules/_global/component/input_countdown";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global/notifikasi_berhasil";
|
||||
import { ComponentGlobal_NotifikasiGagal } from "@/app_modules/_global/notif_global/notifikasi_gagal";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
|
||||
import { notifikasiToUser_CreateKabarDonasi } from "@/app_modules/notifikasi/fun/create/create_notif_to_user_kabar_donasi";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import {
|
||||
AspectRatio,
|
||||
Button,
|
||||
FileButton,
|
||||
Group,
|
||||
Center,
|
||||
Image,
|
||||
Stack,
|
||||
Text,
|
||||
TextInput,
|
||||
Textarea,
|
||||
Textarea
|
||||
} from "@mantine/core";
|
||||
import { IconCamera, IconUpload } from "@tabler/icons-react";
|
||||
import { IconPhoto } from "@tabler/icons-react";
|
||||
import _ from "lodash";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { Donasi_funCreateKabar } from "../../fun/create/fun_create_kabar";
|
||||
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
|
||||
import { DIRECTORY_ID } from "@/app/lib";
|
||||
|
||||
export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
export default function Donasi_CreateKabar() {
|
||||
const params = useParams<{ id: string }>();
|
||||
const donasiId = params.id;
|
||||
|
||||
const router = useRouter();
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [img, setImg] = useState<any | null>();
|
||||
@@ -58,9 +63,8 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
|
||||
if (!uploadImage.success) {
|
||||
setLoading(false);
|
||||
return ComponentGlobal_NotifikasiPeringatan(
|
||||
"Gagal upload file gambar"
|
||||
);
|
||||
ComponentGlobal_NotifikasiPeringatan("Gagal upload file gambar");
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await Donasi_funCreateKabar({
|
||||
@@ -76,7 +80,6 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
setLoading(false);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
setLoading(false);
|
||||
@@ -94,21 +97,21 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
router.back();
|
||||
setLoading(false);
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
setLoading(false);
|
||||
clientLogger.error("Error upload berita", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack px={"lg"} pb={"lg"}>
|
||||
<ComponentGlobal_BoxInformation informasi="Gambar tidak wajib di isi ! Hanya upload jika di butuhkan." />
|
||||
<ComponentGlobal_BoxInformation informasi="Upload gambar bersifat opsional untuk melengkapi kabar terkait donasi Anda." />
|
||||
|
||||
<TextInput
|
||||
maxLength={100}
|
||||
@@ -128,7 +131,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
}}
|
||||
/>
|
||||
<Textarea
|
||||
maxLength={500}
|
||||
maxLength={1000}
|
||||
styles={{
|
||||
label: {
|
||||
color: "white",
|
||||
@@ -138,7 +141,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
withAsterisk
|
||||
placeholder="Masukan deskripsi kabar"
|
||||
autosize
|
||||
maxRows={4}
|
||||
maxRows={10}
|
||||
minRows={2}
|
||||
onChange={(val) => {
|
||||
setKabar({
|
||||
@@ -149,7 +152,7 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
/>
|
||||
<ComponentGlobal_InputCountDown
|
||||
lengthInput={kabar.deskripsi.length}
|
||||
maxInput={500}
|
||||
maxInput={1000}
|
||||
/>
|
||||
|
||||
<Stack spacing={5}>
|
||||
@@ -165,44 +168,18 @@ export default function Donasi_CreateKabar({ donasiId }: { donasiId: string }) {
|
||||
</AspectRatio>
|
||||
) : (
|
||||
<Stack justify="center" align="center" h={"100%"}>
|
||||
<IconUpload color="white" />
|
||||
<Text fz={10} fs={"italic"} c={"white"} fw={"bold"}>
|
||||
Upload Gambar
|
||||
</Text>
|
||||
<IconPhoto size={100} />
|
||||
</Stack>
|
||||
)}
|
||||
</ComponentGlobal_BoxUploadImage>
|
||||
|
||||
{/* Upload Foto */}
|
||||
<Group position="center">
|
||||
<FileButton
|
||||
onChange={async (files: any) => {
|
||||
try {
|
||||
const buffer = URL.createObjectURL(
|
||||
new Blob([new Uint8Array(await files.arrayBuffer())])
|
||||
);
|
||||
setImg(buffer);
|
||||
setFile(files);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}}
|
||||
accept="image/png,image/jpeg"
|
||||
>
|
||||
{(props) => (
|
||||
<Button
|
||||
{...props}
|
||||
leftIcon={<IconCamera color="black" />}
|
||||
radius={50}
|
||||
bg={MainColor.yellow}
|
||||
color="yellow"
|
||||
c={"black"}
|
||||
>
|
||||
Upload Gambar
|
||||
</Button>
|
||||
)}
|
||||
</FileButton>
|
||||
</Group>
|
||||
<Center>
|
||||
<ComponentGlobal_ButtonUploadFileImage
|
||||
onSetFile={setFile}
|
||||
onSetImage={setImg}
|
||||
/>
|
||||
</Center>
|
||||
</Stack>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -9,6 +9,8 @@ export async function donasi_checkStatus({ id }: { id: string }) {
|
||||
},
|
||||
});
|
||||
|
||||
await prisma.$disconnect();
|
||||
|
||||
|
||||
if (checkStatus?.donasiMaster_StatusDonasiId == "2") return true;
|
||||
return false;
|
||||
|
||||
@@ -18,7 +18,11 @@ import { gs_notifikasi_kategori_app } from "../lib";
|
||||
import { apiGetAllNotifikasiByCategory } from "../lib/api_notifikasi";
|
||||
import { MODEL_NOTIFIKASI } from "../model/interface";
|
||||
|
||||
export default function Notifikasi_UiMain() {
|
||||
export default function Notifikasi_UiMain({
|
||||
userLoginId,
|
||||
}: {
|
||||
userLoginId?: string;
|
||||
}) {
|
||||
const [data, setData] = useState<MODEL_NOTIFIKASI[] | null>(null);
|
||||
const [activePage, setActivePage] = useState(1);
|
||||
const [categoryPage, setCategoryPage] = useAtom(gs_notifikasi_kategori_app);
|
||||
@@ -80,6 +84,7 @@ export default function Notifikasi_UiMain() {
|
||||
data={item}
|
||||
onLoadData={setData}
|
||||
categoryPage={categoryPage as any}
|
||||
userLoginId={userLoginId}
|
||||
/>
|
||||
)}
|
||||
</ScrollOnly>
|
||||
|
||||
@@ -24,15 +24,18 @@ import { notifikasi_eventCheckStatus } from "./path/event";
|
||||
import { redirectInvestasiPage } from "./path/investasi";
|
||||
import { notifikasi_jobCheckStatus } from "./path/job";
|
||||
import { notifikasi_votingCheckStatus } from "./path/voting";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export function ComponentNotifiaksi_CardView({
|
||||
data,
|
||||
onLoadData,
|
||||
categoryPage,
|
||||
userLoginId,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
onLoadData: (val: any) => void;
|
||||
categoryPage: string;
|
||||
userLoginId?: string
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [visible, setVisible] = useState(false);
|
||||
@@ -59,134 +62,146 @@ export function ComponentNotifiaksi_CardView({
|
||||
}}
|
||||
my={"xs"}
|
||||
onClick={async () => {
|
||||
// JOB
|
||||
if (data?.kategoriApp === "JOB") {
|
||||
await notifikasi_jobCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataJob(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetJobMenuId(val) {
|
||||
setJobMenuId(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
try {
|
||||
setVisible(true);
|
||||
|
||||
return;
|
||||
// JOB
|
||||
if (data?.kategoriApp === "JOB") {
|
||||
await notifikasi_jobCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataJob(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetJobMenuId(val) {
|
||||
setJobMenuId(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// EVENT
|
||||
if (data?.kategoriApp === "EVENT") {
|
||||
await notifikasi_eventCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetEventMenuId(val) {
|
||||
setEventMenuId(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// VOTING
|
||||
if (data?.kategoriApp === "VOTING") {
|
||||
await notifikasi_votingCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setVotingMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// DONASI
|
||||
if (data?.kategoriApp === "DONASI") {
|
||||
redirectDonasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
userId: data.userId,
|
||||
userLoginId: userLoginId as any,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setDonasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// INVESTASI
|
||||
if (data?.kategoriApp === "INVESTASI") {
|
||||
redirectInvestasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setInvestasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// data?.kategoriApp === "FORUM" &&
|
||||
// redirectDetailForumPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
|
||||
// data?.kategoriApp === "COLLABORATION" &&
|
||||
// redirectDetailCollaborationPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
} catch (error) {
|
||||
setVisible(false);
|
||||
clientLogger.error("Error redirect notification page", error);
|
||||
}
|
||||
|
||||
// EVENT
|
||||
if (data?.kategoriApp === "EVENT") {
|
||||
await notifikasi_eventCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetEventMenuId(val) {
|
||||
setEventMenuId(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "VOTING") {
|
||||
await notifikasi_votingCheckStatus({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setVotingMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "DONASI") {
|
||||
redirectDonasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setDonasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (data?.kategoriApp === "INVESTASI") {
|
||||
redirectInvestasiPage({
|
||||
appId: data.appId,
|
||||
dataId: data.id,
|
||||
categoryPage: categoryPage,
|
||||
router: router,
|
||||
onLoadDataEvent(val) {
|
||||
onLoadData(val);
|
||||
},
|
||||
onSetVisible(val) {
|
||||
setVisible(val);
|
||||
},
|
||||
onSetMenuId(val) {
|
||||
setInvestasiMenu(val);
|
||||
},
|
||||
onLoadCountNtf(val) {
|
||||
setLoadCountNtf(val);
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// data?.kategoriApp === "FORUM" &&
|
||||
// redirectDetailForumPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
|
||||
// data?.kategoriApp === "COLLABORATION" &&
|
||||
// redirectDetailCollaborationPage({
|
||||
// data: data,
|
||||
// router: router,
|
||||
// });
|
||||
}}
|
||||
>
|
||||
{/* <pre>{JSON.stringify(e, null, 2)}</pre> */}
|
||||
|
||||
@@ -7,11 +7,14 @@ import notifikasi_getByUserId from "../../fun/get/get_notifiaksi_by_id";
|
||||
import notifikasi_countUserNotifikasi from "../../fun/count/fun_count_by_id";
|
||||
import notifikasi_funUpdateIsReadById from "../../fun/update/fun_update_is_read_by_user_id";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import { notifikasi_checkAuthorDonasiById } from "../../fun/check/fun_check_author_donasi_by_id";
|
||||
|
||||
export async function redirectDonasiPage({
|
||||
appId,
|
||||
dataId,
|
||||
categoryPage,
|
||||
userId,
|
||||
userLoginId,
|
||||
router,
|
||||
onLoadDataEvent,
|
||||
onSetMenuId,
|
||||
@@ -21,6 +24,8 @@ export async function redirectDonasiPage({
|
||||
appId: string;
|
||||
dataId: string;
|
||||
categoryPage: string;
|
||||
userId: string;
|
||||
userLoginId: string;
|
||||
router: AppRouterInstance;
|
||||
onLoadDataEvent: (val: any) => void;
|
||||
onSetMenuId(val: number): void;
|
||||
@@ -28,29 +33,38 @@ export async function redirectDonasiPage({
|
||||
onLoadCountNtf(val: number): void;
|
||||
}) {
|
||||
const check = await notifikasi_funDonasiCheckStatus({ id: appId });
|
||||
const checkAuthor = await notifikasi_checkAuthorDonasiById({
|
||||
donasiId: appId,
|
||||
userId: userId,
|
||||
});
|
||||
|
||||
if (check.status == 200) {
|
||||
const loadListNotifikasi = await notifikasi_getByUserId({
|
||||
page: 1,
|
||||
kategoriApp: categoryPage as any,
|
||||
});
|
||||
onLoadDataEvent(loadListNotifikasi);
|
||||
// const loadListNotifikasi = await notifikasi_getByUserId({
|
||||
// page: 1,
|
||||
// kategoriApp: categoryPage as any,
|
||||
// });
|
||||
// onLoadDataEvent(loadListNotifikasi);
|
||||
|
||||
const loadCountNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
onLoadCountNtf(loadCountNotifikasi);
|
||||
// const loadCountNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
// onLoadCountNtf(loadCountNotifikasi);
|
||||
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
});
|
||||
|
||||
if (updateReadNotifikasi.status == 200) {
|
||||
onSetVisible(true);
|
||||
const pathToCreator = `/dev/donasi/detail/${check.statusName}/${appId}`;
|
||||
const pathToAllUser = `/dev/donasi/detail/main/${appId}`;
|
||||
|
||||
const path = `/dev/donasi/detail/${check.statusName}/${appId}`;
|
||||
onSetMenuId(1);
|
||||
router.push(path, { scroll: false });
|
||||
if (checkAuthor) {
|
||||
router.push(pathToCreator, { scroll: false });
|
||||
} else {
|
||||
router.push(pathToAllUser, { scroll: false });
|
||||
onSetMenuId(1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
onSetVisible(false);
|
||||
ComponentGlobal_NotifikasiPeringatan("Status tidak ditemukan");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,9 +37,6 @@ export async function redirectInvestasiPage({
|
||||
id: appId,
|
||||
});
|
||||
|
||||
console.log("check", check);
|
||||
console.log("check investor:", checkInvestor);
|
||||
|
||||
if (check.status == 200) {
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
|
||||
export async function notifikasi_checkAuthorDonasiById({
|
||||
userId,
|
||||
donasiId,
|
||||
}: {
|
||||
userId: string;
|
||||
donasiId: string;
|
||||
}) {
|
||||
const check = await prisma.donasi.findFirst({
|
||||
where: {
|
||||
authorId: userId,
|
||||
id: donasiId,
|
||||
},
|
||||
});
|
||||
|
||||
if (check) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,6 @@ export async function notifikasiToUser_CreateKabarDonasi({
|
||||
const dataFix = Array.from(data);
|
||||
|
||||
for (let authorId of dataFix) {
|
||||
console.log(authorId);
|
||||
const createNotifikasi = await prisma.notifikasi.create({
|
||||
data: {
|
||||
userRoleId: "1",
|
||||
|
||||
@@ -33,8 +33,8 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
"/api/origin-url",
|
||||
"/api/event/*",
|
||||
// "/api/image/*",
|
||||
// "/api/user",
|
||||
"/api/new/*",
|
||||
// "/api/user/*",
|
||||
// "/api/new/*",
|
||||
// Akses awal
|
||||
"/api/get-cookie",
|
||||
"/api/user/activation",
|
||||
|
||||
Reference in New Issue
Block a user