From ac432d1eb7b975d621889b0d2e13e366e806cf56 Mon Sep 17 00:00:00 2001 From: amel Date: Thu, 23 May 2024 16:36:48 +0800 Subject: [PATCH 1/3] fix: dashboard admin Deskripsi: - page list user dan list admin - search list user dan list admin No Issues --- src/app/dev/admin/developer/page.tsx | 6 +- .../fun/get/fun_get_list_all_admin.ts | 45 ++- .../fun/get/fun_get_list_all_user.ts | 30 +- src/app_modules/admin/developer/index.tsx | 280 +++++++++++++++++- 4 files changed, 334 insertions(+), 27 deletions(-) diff --git a/src/app/dev/admin/developer/page.tsx b/src/app/dev/admin/developer/page.tsx index c69ae063..609d4b10 100644 --- a/src/app/dev/admin/developer/page.tsx +++ b/src/app/dev/admin/developer/page.tsx @@ -4,12 +4,12 @@ import adminDeveloper_funGetListAllUser from "@/app_modules/admin/developer/fun/ import _ from "lodash"; export default async function Page() { - const listUser = await adminDeveloper_funGetListAllUser(); - const listAdmin = await adminDeveloper_funGetListAllAdmin(); + const listUser = await adminDeveloper_funGetListAllUser({ page: 1 }); + const listAdmin = await adminDeveloper_funGetListAllAdmin({ page: 1 }); return ( <> - + ); } diff --git a/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts b/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts index 7cf6d885..94eb2c64 100644 --- a/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts +++ b/src/app_modules/admin/developer/fun/get/fun_get_list_all_admin.ts @@ -1,15 +1,38 @@ "use server" - import prisma from "@/app/lib/prisma" +import _, { ceil } from "lodash"; -export default async function adminDeveloper_funGetListAllAdmin() { - const data = await prisma.user.findMany({ - orderBy: { - updatedAt: "asc", - }, - where: { - masterUserRoleId: "2", - }, - }); - return data; +export default async function adminDeveloper_funGetListAllAdmin({ search, page }: { search?: any, page: any }) { + const dataSkip = _.toNumber(page) * 9 - 9 + const data = await prisma.user.findMany({ + skip: dataSkip, + take: 9, + orderBy: { + updatedAt: "asc", + }, + where: { + masterUserRoleId: "2", + username: { + contains: search, + mode: 'insensitive' + } + }, + }); + + const nCount = await prisma.user.count({ + where: { + masterUserRoleId: "2", + username: { + contains: search, + mode: 'insensitive' + } + } + }) + + const allData = { + data: data, + nPage: ceil(nCount / 9) + } + + return allData; } \ No newline at end of file diff --git a/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts b/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts index 3de50a19..e4de3b79 100644 --- a/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts +++ b/src/app_modules/admin/developer/fun/get/fun_get_list_all_user.ts @@ -1,15 +1,39 @@ "use server"; - import prisma from "@/app/lib/prisma"; +import _, { ceil } from "lodash"; + +export default async function adminDeveloper_funGetListAllUser({ search, page }: { search?: any, page: any }) { + const dataSkip = _.toNumber(page) * 9 - 9 -export default async function adminDeveloper_funGetListAllUser() { const data = await prisma.user.findMany({ + skip: dataSkip, + take: 9, orderBy: { updatedAt: "asc", }, where: { masterUserRoleId: "1", + username: { + contains: search, + mode: 'insensitive' + } }, }); - return data; + + const nCount = await prisma.user.count({ + where: { + masterUserRoleId: "1", + username: { + contains: search, + mode: 'insensitive' + } + } + }) + + const allData = { + data: data, + nPage: ceil(nCount / 9) + } + + return allData; } diff --git a/src/app_modules/admin/developer/index.tsx b/src/app_modules/admin/developer/index.tsx index c2d49ac5..2da4a14a 100644 --- a/src/app_modules/admin/developer/index.tsx +++ b/src/app_modules/admin/developer/index.tsx @@ -5,6 +5,7 @@ import { Button, Center, Group, + Pagination, Paper, ScrollArea, SimpleGrid, @@ -17,7 +18,7 @@ import ComponentAdminGlobal_HeaderTamplate from "../component/header_tamplate"; import { MODEL_USER } from "@/app_modules/home/model/interface"; import _ from "lodash"; import { IconSearch } from "@tabler/icons-react"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import adminDeveloper_funEditUserAksesById from "./fun/edit/fun_edit_user_akses_by_id"; import adminDeveloper_funGetListAllAdmin from "./fun/get/fun_get_list_all_admin"; import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/component_global/notif_global/notifikasi_berhasil"; @@ -27,27 +28,45 @@ import adminDeveloper_funGetListAllUser from "./fun/get/fun_get_list_all_user"; export default function AdminDeveloper({ listUser, listAdmin, + pUser, + pAdmin }: { listUser: MODEL_USER[]; listAdmin: MODEL_USER[]; + pUser: any, + pAdmin: any }) { const [dataUser, setDataUser] = useState(listUser); const [dataAdmin, setDataAdmin] = useState(listAdmin); + const [pageUser, setPageUser] = useState(pUser); + const [pageAdmin, setPageAdmin] = useState(pAdmin); return ( <> - - */} + {/* */} + { + setDataUser(val.data) + setPageUser(val.nPage) + }} + /> + { + setDataAdmin(val.data) + setPageAdmin(val.nPage) + }} /> @@ -55,6 +74,247 @@ export default function AdminDeveloper({ ); } +function NewTableUser({ data, nPage, onUpdated }: { data: any, nPage: any, onUpdated: (val: any) => void }) { + const [isChoosePage, setChoosePage] = useState(1) + const [dataUser, setDataUser] = useState(data) + const [isNPage, setNPage] = useState(nPage) + const [isSearch, setSearch] = useState('') + + async function onPageClick(p: any) { + setChoosePage(p) + const loadData = await adminDeveloper_funGetListAllUser({ search: isSearch, page: p }) + setDataUser(loadData.data) + setNPage(loadData.nPage) + } + + async function onSearch(s: any) { + setSearch(s) + setChoosePage(1) + const loadData = await adminDeveloper_funGetListAllUser({ search: s, page: 1 }) + setDataUser(loadData.data) + setNPage(loadData.nPage) + } + + async function onAccess(id: string) { + const upd = await adminDeveloper_funEditUserAksesById(id, "2") + if (upd.status == 200) { + const loadData = await adminDeveloper_funGetListAllUser({ search: isSearch, page: isChoosePage }) + setDataUser(loadData.data) + setNPage(loadData.nPage) + const loadDataAdmin = await adminDeveloper_funGetListAllAdmin({ page: 1 }) + onUpdated(loadDataAdmin) + ComponentGlobal_NotifikasiBerhasil(upd.message) + } else { + ComponentGlobal_NotifikasiGagal(upd.message) + } + } + + useEffect(() => { + setDataUser(data) + setNPage(nPage) + setSearch('') + setChoosePage(1) + }, [data, nPage]) + + + return ( + <> + + + Table User NEW + } + radius={"xl"} + placeholder="Masukan username" + onChange={(val) => { + onSearch(val.currentTarget.value) + }} + /> + + + + + + + + + + + + {dataUser.map((v: any, i: any) => ( + + + + + + ))} + +
+
Username
+
+
Nomor
+
+
Aksi
+
+
{v.username}
+
+
{v.nomor}
+
+
+ +
+
+ + { + onPageClick(val) + }} + total={isNPage} + /> + +
+
+ + ) +} + +function NewTableAdmin({ data, nPage, onUpdated }: { data: any, nPage: any, onUpdated: (val: any) => void }) { + const [isChoosePage, setChoosePage] = useState(1) + const [dataAdmin, setDataAdmin] = useState(data) + const [isNPage, setNPage] = useState(nPage) + const [isSearch, setSearch] = useState('') + + async function onPageClick(p: any) { + setChoosePage(p) + const loadData = await adminDeveloper_funGetListAllAdmin({ search: isSearch, page: p }) + setDataAdmin(loadData.data) + setNPage(loadData.nPage) + } + + async function onSearch(s: any) { + setSearch(s) + setChoosePage(1) + const loadData = await adminDeveloper_funGetListAllAdmin({ search: s, page: 1 }) + setDataAdmin(loadData.data) + setNPage(loadData.nPage) + } + + async function onAccess(id: string) { + const upd = await adminDeveloper_funEditUserAksesById(id, "1") + if (upd.status == 200) { + const loadData = await adminDeveloper_funGetListAllAdmin({ search: isSearch, page: isChoosePage }) + setDataAdmin(loadData.data) + setNPage(loadData.nPage) + const loadDataUser = await adminDeveloper_funGetListAllUser({ page: 1 }) + onUpdated(loadDataUser) + ComponentGlobal_NotifikasiBerhasil(upd.message) + } else { + ComponentGlobal_NotifikasiGagal(upd.message) + } + } + + useEffect(() => { + setDataAdmin(data) + setNPage(nPage) + setSearch('') + setChoosePage(1) + }, [data, nPage]) + + return ( + <> + + + Table Admin + } + radius={"xl"} + placeholder="Masukan username" + onChange={(val) => { + onSearch(val.currentTarget.value) + }} + /> + + + + + + + + + + + + {dataAdmin.map((v: any, i: any) => ( + + + + + + ))} + +
+
Username
+
+
Nomor
+
+
Aksi
+
+
{v.username}
+
+
{v.nomor}
+
+
+ +
+
+ + { + onPageClick(val) + }} + total={isNPage} + /> + +
+
+ + ) +} + + + function TableAdmin({ dataAdmin, setDataAdmin, @@ -67,10 +327,10 @@ function TableAdmin({ async function onAccess(id: string) { await adminDeveloper_funEditUserAksesById(id, "1").then(async (res) => { if (res.status === 200) { - await adminDeveloper_funGetListAllUser().then((val) => { + await adminDeveloper_funGetListAllUser({ page: 1 }).then((val) => { setDataUser(val); }); - await adminDeveloper_funGetListAllAdmin().then((val) => { + await adminDeveloper_funGetListAllAdmin({ page: 1 }).then((val) => { setDataAdmin(val); }); ComponentGlobal_NotifikasiBerhasil(res.message); @@ -155,10 +415,10 @@ function TableUser({ async function onAccess(id: string) { await adminDeveloper_funEditUserAksesById(id, "2").then(async (res) => { if (res.status === 200) { - await adminDeveloper_funGetListAllUser().then((val) => { - setDataUser(val); + await adminDeveloper_funGetListAllUser({ page: 1 }).then((val) => { + setDataUser(val.data); }); - await adminDeveloper_funGetListAllAdmin().then((val) => { + await adminDeveloper_funGetListAllAdmin({ page: 1 }).then((val) => { setDataAdmin(val); }); ComponentGlobal_NotifikasiBerhasil(res.message); From 166b1349f5b63309d575f767122d68c7b18ff9ab Mon Sep 17 00:00:00 2001 From: Bagasbanuna02 Date: Thu, 23 May 2024 17:17:40 +0800 Subject: [PATCH 2/3] QC Event # Fix - Loading card - Create : saat memilih jam sesuai dengan batas jam di hari itu ## No isuuee --- src/app/dev/event/main/status_page/page.tsx | 10 +- src/app_modules/admin/event/child/riwayat.tsx | 48 +++---- src/app_modules/admin/event/main/index.tsx | 14 +-- .../event/table_status/table_publish.tsx | 61 +++++---- .../admin/event/table_status/table_reject.tsx | 1 - .../admin/event/table_status/table_review.tsx | 10 +- .../event/component/box_list_status.tsx | 22 +++- .../event/component/detail/detail_main.tsx | 117 +++++++++--------- src/app_modules/event/create/create.tsx | 86 ++++++------- src/app_modules/event/detail/draft/index.tsx | 55 +++++++- .../event/detail/main_detail/index.tsx | 65 +++------- src/app_modules/event/edit/index.tsx | 106 +++++++++++----- .../event/fun/delete/fun_delete.ts | 12 +- ...s_id.ts => get_list_event_by_status_id.ts} | 5 +- src/app_modules/event/main/beranda.tsx | 87 +++++++------ .../event/main/kontribusi/index.tsx | 66 +++------- src/app_modules/event/main/layout.tsx | 2 +- .../event/main/status_page/draft.tsx | 23 ++-- .../event/main/status_page/publish.tsx | 32 +++-- .../event/main/status_page/reject.tsx | 8 +- .../event/main/status_page/review.tsx | 11 +- src/util/mqtt_loader.tsx | 43 ++++++- 22 files changed, 484 insertions(+), 400 deletions(-) rename src/app_modules/event/fun/get/{get_event_by_status_id.ts => get_list_event_by_status_id.ts} (94%) diff --git a/src/app/dev/event/main/status_page/page.tsx b/src/app/dev/event/main/status_page/page.tsx index 1aade7b4..792bfdbc 100644 --- a/src/app/dev/event/main/status_page/page.tsx +++ b/src/app/dev/event/main/status_page/page.tsx @@ -1,13 +1,13 @@ import { Event_StatusPage } from "@/app_modules/event"; -import { Event_getByStatusId } from "@/app_modules/event/fun/get/get_event_by_status_id"; +import { Event_getListByStatusId } from "@/app_modules/event/fun/get/get_list_event_by_status_id"; import { user_getOneUserId } from "@/app_modules/fun_global/get_user_token"; export default async function Page() { const authorId = await user_getOneUserId(); - const listPublish = await Event_getByStatusId("1", authorId); - const listReview = await Event_getByStatusId("2", authorId); - const listDraft = await Event_getByStatusId("3", authorId); - const listReject = await Event_getByStatusId("4", authorId); + const listPublish = await Event_getListByStatusId("1", authorId); + const listReview = await Event_getListByStatusId("2", authorId); + const listDraft = await Event_getListByStatusId("3", authorId); + const listReject = await Event_getListByStatusId("4", authorId); return ( - {e.title} - {e.lokasi} - {e.EventMaster_TipeAcara.name} - {e.tanggal.toLocaleString("id-ID", { dateStyle: "full" })} + {e?.Author?.Profile?.name} + {e?.title} + {e?.lokasi} + {e?.EventMaster_TipeAcara?.name} + {e?.tanggal.toLocaleString("id-ID", { dateStyle: "full" })} {e.tanggal.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", - hour12: false, })} @@ -121,23 +121,24 @@ function DetailRiwayat({ listRiwayat }: { listRiwayat: MODEL_EVENT[] }) { {peserta?.map((e) => ( - - - - - - - {e?.User?.Profile?.name} - - - - + + + + + + + {e?.User?.Profile?.name} + + + + ))} @@ -164,6 +165,9 @@ function DetailRiwayat({ listRiwayat }: { listRiwayat: MODEL_EVENT[] }) {
Aksi
+ +
Author
+
Judul
diff --git a/src/app_modules/admin/event/main/index.tsx b/src/app_modules/admin/event/main/index.tsx index e58afff2..680a3e74 100644 --- a/src/app_modules/admin/event/main/index.tsx +++ b/src/app_modules/admin/event/main/index.tsx @@ -50,13 +50,13 @@ export default function AdminEvent_Main({ path: RouterAdminEvent.table_review, color: "orange", }, - { - id: 3, - name: "Draft", - jumlah: countDraft, - path: "", - color: "yellow", - }, + // { + // id: 3, + // name: "Draft", + // jumlah: countDraft, + // path: "", + // color: "yellow", + // }, { id: 4, name: "Reject", diff --git a/src/app_modules/admin/event/table_status/table_publish.tsx b/src/app_modules/admin/event/table_status/table_publish.tsx index 3e6985b5..646bbae7 100644 --- a/src/app_modules/admin/event/table_status/table_publish.tsx +++ b/src/app_modules/admin/event/table_status/table_publish.tsx @@ -72,15 +72,15 @@ function TableStatus({ listPublish }: { listPublish: MODEL_EVENT[] }) { const TableRows = data.map((e, i) => ( - {e.title} - {e.lokasi} - {e.EventMaster_TipeAcara.name} - {e.tanggal.toLocaleString("id-ID", { dateStyle: "full" })} + {e?.Author?.Profile?.name} + {e?.title} + {e?.lokasi} + {e?.EventMaster_TipeAcara?.name} + {e?.tanggal.toLocaleString("id-ID", { dateStyle: "full" })} {e.tanggal.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", - hour12: false, })} @@ -121,28 +121,34 @@ function TableStatus({ listPublish }: { listPublish: MODEL_EVENT[] }) { Daftar Peserta - {peserta?.map((e) => ( - - - - - - - - {e?.User?.Profile?.name} - - - - - - ))} + {_.isEmpty(peserta) ? ( +
+ Tidak ada peserta +
+ ) : ( + peserta?.map((e) => ( + + + + + + + + {e?.User?.Profile?.name} + + + + + + )) + )}
@@ -163,6 +169,7 @@ function TableStatus({ listPublish }: { listPublish: MODEL_EVENT[] }) { > + Author Judul Lokasi Tipe Acara diff --git a/src/app_modules/admin/event/table_status/table_reject.tsx b/src/app_modules/admin/event/table_status/table_reject.tsx index e9920a7c..99471bc8 100644 --- a/src/app_modules/admin/event/table_status/table_reject.tsx +++ b/src/app_modules/admin/event/table_status/table_reject.tsx @@ -90,7 +90,6 @@ function TableStatus({ listReject }: { listReject: MODEL_EVENT[] }) { {e.tanggal.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", - hour12: false, })} diff --git a/src/app_modules/admin/event/table_status/table_review.tsx b/src/app_modules/admin/event/table_status/table_review.tsx index fe4430bf..a3fe6ebc 100644 --- a/src/app_modules/admin/event/table_status/table_review.tsx +++ b/src/app_modules/admin/event/table_status/table_review.tsx @@ -75,7 +75,6 @@ function TableStatus({ listReview }: { listReview: MODEL_EVENT[] }) { {e.tanggal.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", - hour12: false, })} @@ -90,7 +89,7 @@ function TableStatus({ listReview }: { listReview: MODEL_EVENT[] }) { color={"green"} leftIcon={} radius={"xl"} - onClick={() => onPublish(e.id, setData)} + onClick={() => onPublish(e.id, setData, e.tanggal)} > Publish @@ -194,7 +193,12 @@ function TableStatus({ listReview }: { listReview: MODEL_EVENT[] }) { ); } -async function onPublish(eventId: string, setData: any) { +async function onPublish(eventId: string, setData: any, tanggal: Date) { + if (moment(tanggal).diff(Date.now(), "minutes") < 0) + return ComponentGlobal_NotifikasiPeringatan( + "Waktu acara telah lewat, Report untuk memberitahu user !" + ); + await AdminEvent_funEditStatusPublishById(eventId, "1").then(async (res) => { if (res.status === 200) { await AdminEvent_getListTableByStatusId("2").then((res) => { diff --git a/src/app_modules/event/component/box_list_status.tsx b/src/app_modules/event/component/box_list_status.tsx index a53c04d7..a3266584 100644 --- a/src/app_modules/event/component/box_list_status.tsx +++ b/src/app_modules/event/component/box_list_status.tsx @@ -1,10 +1,12 @@ "use client"; import { RouterEvent } from "@/app/lib/router_hipmi/router_event"; -import { Paper, Stack, Group, Title, Text, Grid } from "@mantine/core"; +import { Paper, Stack, Group, Title, Text, Grid, Card } from "@mantine/core"; import moment from "moment"; import { MODEL_EVENT } from "../model/interface"; import { useRouter } from "next/navigation"; +import { useState } from "react"; +import ComponentGlobal_CardLoadingOverlay from "@/app_modules/component_global/loading_card"; export default function ComponentEvent_BoxListStatus({ data, @@ -14,15 +16,22 @@ export default function ComponentEvent_BoxListStatus({ path: string; }) { const router = useRouter(); + const [eventId, setEventId] = useState(""); + const [visible, setVisible] = useState(false); + return ( <> - router.push(path + data.id)} + onClick={() => { + setEventId(data?.id); + setVisible(true); + router.push(path + data.id); + }} > @@ -42,7 +51,12 @@ export default function ComponentEvent_BoxListStatus({ {data.deskripsi} - + {visible && eventId !== "" ? ( + + ) : ( + "" + )} + ); } diff --git a/src/app_modules/event/component/detail/detail_main.tsx b/src/app_modules/event/component/detail/detail_main.tsx index 08d49828..004c8ac9 100644 --- a/src/app_modules/event/component/detail/detail_main.tsx +++ b/src/app_modules/event/component/detail/detail_main.tsx @@ -16,74 +16,73 @@ export default function ComponentEvent_DetailMainData({ const jam = tgl.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", - hour12: false, }); return ( <> - - - - {data ? data.title : null} - - + + + + {data ? data.title : null} + + + + Lokasi + + + : + + {data ? data.lokasi : null} + + + + + + Tipe Acara + + + : + + {data ? data.EventMaster_TipeAcara.name : null} + + + + + + Tanggal + + + : + {hari} + + + + + Jam + + + : + {jam} + + - Lokasi + Deskripsi - - : - - {data ? data.lokasi : null} - - - - - - Tipe Acara - - - : - - {data ? data.EventMaster_TipeAcara.name : null} - - - - - - Tanggal - - - : - {hari} - - - - - Jam - - - : - {jam} - - - - Deskripsi - - - {data ? data.deskripsi : null} - + + {data ? data.deskripsi : null} + + - ); diff --git a/src/app_modules/event/create/create.tsx b/src/app_modules/event/create/create.tsx index 13d82d53..aa1008c5 100644 --- a/src/app_modules/event/create/create.tsx +++ b/src/app_modules/event/create/create.tsx @@ -36,6 +36,7 @@ import toast from "react-simple-toasts"; import moment from "moment"; import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/component_global/notif_global/notifikasi_peringatan"; import ComponentEvent_ErrorMaximalInput from "../component/error_maksimal_input"; +import ComponentGlobal_InputCountDown from "@/app_modules/component_global/input_countdown"; export default function Event_Create({ listTipeAcara, @@ -69,13 +70,6 @@ export default function Event_Create({ placeholder="Masukan judul" withAsterisk maxLength={100} - error={ - value.title.length >= 100 ? ( - - ) : ( - "" - ) - } onChange={(val) => { setValue({ ...value, @@ -104,13 +98,6 @@ export default function Event_Create({ placeholder="Masukan lokasi acara" withAsterisk maxLength={100} - error={ - value.lokasi.length >= 100 ? ( - - ) : ( - "" - ) - } onChange={(val) => { setValue({ ...value, @@ -146,33 +133,38 @@ export default function Event_Create({ }); }} /> -