Merge pull request #232 from bipproduction/fix/bug/upload

fix ( user access )
This commit is contained in:
Bagasbanuna02
2025-01-10 08:52:19 +08:00
committed by GitHub
22 changed files with 744 additions and 218 deletions

View File

@@ -256,6 +256,10 @@ function NewTableAdmin({
search: isSearch,
page: isChoosePage,
});
setDataAdmin(loadData.data);
setNPage(loadData.nPage);
const loadDataUser = await adminDeveloper_funGetListAllUser({ page: 1 });

View File

@@ -1,11 +1,14 @@
"use server";
import prisma from "@/app/lib/prisma";
import backendLogger from "@/util/backendLogger";
import { revalidatePath } from "next/cache";
import { headers } from "next/headers";
export default async function adminUserAccess_funEditAccess(
userId: string,
value: boolean
value: boolean,
nomor?: string
) {
const updt = await prisma.user.update({
where: {
@@ -16,6 +19,31 @@ export default async function adminUserAccess_funEditAccess(
},
});
const headersList = headers();
const host = headersList.get("host");
const protocol = headersList.get("x-forwarded-proto") || "http";
const path = headersList.get("x-invoke-path");
const baseUrl = `${protocol}://${host}`;
// const fullUrl = `${protocol}://${host}${path}`;
if (value === true) {
const message = `Hallo rekan HIPMI, Anda telah diberikan akses ke HIPMI Apps. Silakan mulai jelajahi fitur-fitur yang tersedia melalui link berikut: ${baseUrl}`;
const encodedMessage = encodeURIComponent(message);
const res = await fetch(
`https://wa.wibudev.com/code?nom=${nomor}&text=${encodedMessage}
`
);
if (!res.ok) {
backendLogger.error("Error send message", res);
}
const result = await res.json();
backendLogger.info("Success send message", result);
}
if (!updt) return { status: 400, message: "Update gagal" };
revalidatePath("/dev/admin/user-access");
return { status: 200, message: "Update berhasil" };

View File

@@ -20,6 +20,9 @@ import { IconSearch } from "@tabler/icons-react";
import { useState } from "react";
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
import adminUserAccess_getListUser from "../fun/get/get_list_all_user";
import { WibuRealtime } from "wibu-pkg";
import { gs_access_user, IRealtimeData } from "@/app/lib/global_state";
import { useAtom } from "jotai";
export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
const [data, setData] = useState<MODEL_USER[]>(listUser.data);
@@ -30,11 +33,11 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
const [userId, setUserId] = useState("");
async function onAccess(id: string) {
async function onAccess(id: string, nomor: string) {
try {
setUserId(id);
setIsLoadingAccess(true);
await adminUserAccess_funEditAccess(id, true).then(async (res) => {
await adminUserAccess_funEditAccess(id, true, nomor).then(async (res) => {
if (res.status === 200) {
const value = await adminUserAccess_getListUser({
page: 1,
@@ -42,6 +45,19 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
});
setData(value.data as any);
setNPage(value.nPage);
const dataNotifikasi: IRealtimeData = {
status: true as any,
userId: id,
kategoriApp: "ACCESS",
};
WibuRealtime.setData({
type: "trigger",
pushNotificationTo: "USER",
dataMessage: dataNotifikasi,
});
ComponentGlobal_NotifikasiBerhasil(res.message);
} else {
ComponentGlobal_NotifikasiGagal(res.message);
@@ -118,7 +134,7 @@ export default function AdminUserAccess_View({ listUser }: { listUser: any }) {
radius={"xl"}
color="Green"
onClick={() => {
onAccess(e.id);
onAccess(e.id, e.nomor);
}}
>
Grand Access

View File

@@ -69,7 +69,7 @@ export default function Login({ version }: { version: string }) {
<Title order={3} c={MainColor.yellow}>
WELCOME TO
</Title>
<Title c={MainColor.yellow}>HIPMI APPS</Title>
<Title order={2} c={MainColor.yellow}>HIPMI BADUNG APPS</Title>
</Stack>
<Stack w={300}>

View File

@@ -13,6 +13,7 @@ import { useRouter } from "next/navigation";
import { useState } from "react";
import { auth_funDeleteAktivasiKodeOtpByNomor } from "../fun/fun_edit_aktivasi_kode_otp_by_id";
import Register_SkeletonView from "./skeleton";
import { clientLogger } from "@/util/clientLogger";
export default function Register() {
const router = useRouter();
@@ -70,28 +71,31 @@ export default function Register() {
await auth_funDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
});
router.push("/dev/home", { scroll: false });
router.push("/waiting-room", { scroll: false });
return;
}
if (res.status === 400) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
if (res.status === 405) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
if (res.status === 500) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
} catch (error) {
console.log(error);
} finally {
setLoading(false);
clientLogger.error("Error registrasi", error);
}
}

View File

@@ -87,9 +87,6 @@ export default function Validasi() {
body: JSON.stringify({
nomor: data.nomor,
}),
headers: {
"Content-Type": "application/json",
},
});
const result = await res.json();
@@ -100,6 +97,7 @@ export default function Validasi() {
await auth_funDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
});
router.push(RouterHome.main_home, { scroll: false });
return;
}
@@ -110,30 +108,33 @@ export default function Validasi() {
await auth_funDeleteAktivasiKodeOtpByNomor({
nomor: data.nomor,
});
router.push(RouterAdminDashboard.splash_admin, { scroll: false });
return;
}
if (res.status === 404) {
setLoading(false);
router.push("/register", { scroll: false });
ComponentGlobal_NotifikasiBerhasil(result.message);
return;
}
if (res.status === 400) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan(result.message);
return;
}
if (res.status == 500) {
setLoading(false);
ComponentGlobal_NotifikasiGagal(result.message);
return;
}
} catch (error) {
clientLogger.error("Error validasi:", error);
} finally {
setLoading(false);
}
clientLogger.error("Error validasi:", error);
}
}
async function onBack() {

View File

@@ -26,8 +26,8 @@ import { clientLogger } from "@/util/clientLogger";
export default function BodyHome() {
const router = useRouter();
const [dataUser, setDataUser] = useState<any>({});
const [dataJob, setDataJob] = useState<any[]>([]);
const [dataUser, setDataUser] = useState<any | null>(null);
const [dataJob, setDataJob] = useState<any[] | null>(null);
const [loadingJob, setLoadingJob] = useState(true);
const [loading, setLoading] = useState(true);
@@ -46,10 +46,12 @@ export default function BodyHome() {
setDataUser(response.data);
}
} catch (error) {
clientLogger.error("Error get data user", error);
}
clientLogger.error("Error get data profile", error);
}
}
async function getHomeJob() {
try {
setLoadingJob(true);
@@ -70,19 +72,6 @@ export default function BodyHome() {
return (
<Box>
{/* <Paper
radius={"xl"}
h={150}
mb={"xs"}
style={{
borderRadius: "10px 10px 10px 10px",
border: `2px solid ${AccentColor.blue}`,
position: "relative",
}}
>
</Paper> */}
<Image
height={140}
fit={"cover"}
@@ -112,16 +101,11 @@ export default function BodyHome() {
border: `2px solid ${AccentColor.blue}`,
}}
onClick={() => {
if (
dataUser.profile == undefined ||
dataUser?.profile == null ||
dataJob.length == undefined ||
dataJob.length == null
) {
if (dataUser == null) {
return null;
} else if (
dataUser.profile == undefined ||
dataUser?.profile == null
Object.keys(dataUser).length == 0 ||
dataJob?.length == null
) {
router.push(RouterProfile.create, { scroll: false });
} else {
@@ -163,16 +147,11 @@ export default function BodyHome() {
>
<Stack
onClick={() => {
if (
dataUser.profile == undefined ||
dataUser?.profile == null ||
dataJob.length == undefined ||
dataJob.length == null
) {
if (dataUser == null) {
return null;
} else if (
dataUser.profile == undefined ||
dataUser?.profile == null
Object.keys(dataUser).length == 0 ||
dataJob?.length == null
) {
router.push(RouterProfile.create, { scroll: false });
} else {
@@ -229,7 +208,7 @@ export default function BodyHome() {
<ComponentGlobal_IsEmptyData text="Tidak ada data" height={10} />
) : (
<SimpleGrid cols={2} spacing="md">
{dataJob.map((e, i) => (
{dataJob?.map((e, i) => (
<Stack key={e.id}>
<Group spacing={"xs"}>
<Stack h={"100%"} align="center" justify="flex-start">

View File

@@ -51,7 +51,7 @@ export default function FooterHome() {
bottom={0}
h={"9vh"}
>
{dataUser?.profile === undefined || dataUser?.profile === null ? (
{dataUser == null ? (
<SimpleGrid cols={4}>
{Array.from(new Array(4)).map((_, i) => (
<Center h={"9vh"} key={i}>
@@ -69,15 +69,9 @@ export default function FooterHome() {
align="center"
spacing={0}
onClick={() => {
if (
dataUser.profile === undefined ||
dataUser?.profile === null
) {
if (dataUser == null) {
return null;
} else if (
dataUser.profile === undefined ||
dataUser?.profile === null
) {
} else if (Object.keys(dataUser).length === 0) {
router.push(RouterProfile.create, { scroll: false });
} else {
if (e.link == "") {

View File

@@ -1,3 +1,4 @@
import { atomWithStorage } from "jotai/utils";
import { atom } from "jotai";
export const gs_token = atomWithStorage<any | null>("gs_token", null);

View File

@@ -68,7 +68,7 @@ export default function HomeViewNew() {
<UIGlobal_LayoutHeaderTamplate
title="HIPMI"
customButtonLeft={
dataUser?.profile == null ? (
dataUser == null ? (
<CustomSkeleton width={20} height={20} circle />
) : (
<ActionIcon
@@ -91,7 +91,7 @@ export default function HomeViewNew() {
)
}
customButtonRight={
dataUser?.profile == null ? (
dataUser == null ? (
<CustomSkeleton width={20} height={20} circle />
) : (
<ActionIcon

View File

@@ -3,13 +3,17 @@
import { ComponentGlobal_NotifikasiBerhasil } from "@/app_modules/_global/notif_global";
import { UIGlobal_LayoutDefault } from "@/app_modules/_global/ui";
import { clientLogger } from "@/util/clientLogger";
import { Skeleton, Stack, Text } from "@mantine/core";
import { Button, Skeleton, Stack, Text } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks";
import _ from "lodash";
import { useRouter } from "next/navigation";
import { useState } from "react";
import { ComponentGlobal_CardStyles } from "../_global/component";
import { apiGetACtivationUser } from "../_global/lib/api_user";
import { gs_access_user } from "@/app/lib/global_state";
import { useAtom } from "jotai";
import { MainColor } from "../_global/color";
import CustomSkeleton from "../components/CustomSkeleton";
export default function WaitingRoom_View({
userLoginId,
@@ -18,6 +22,8 @@ export default function WaitingRoom_View({
}) {
const router = useRouter();
const [loading, setLoading] = useState(false);
const [isLoadingHome, setIsLoadingHome] = useState(false);
async function onClickLogout() {
setLoading(true);
const res = await fetch(`/api/auth/logout?id=${userLoginId}`, {
@@ -31,7 +37,15 @@ export default function WaitingRoom_View({
}
}
const [data, setData] = useState<boolean | null>(null);
const [isAccess, setIsAccess] = useState<boolean | null>(null);
const [isAccessUser, setIsAccessUser] = useAtom(gs_access_user);
useShallowEffect(() => {
if (isAccessUser) {
setIsAccess(true);
setIsAccessUser(false);
}
}, [isAccessUser]);
useShallowEffect(() => {
onLoadData();
@@ -41,7 +55,7 @@ export default function WaitingRoom_View({
try {
const respone = await apiGetACtivationUser();
if (respone) {
setData(respone.data);
setIsAccess(respone.data);
}
} catch (error) {
clientLogger.error("Error get cookies user", error);
@@ -53,11 +67,12 @@ export default function WaitingRoom_View({
<UIGlobal_LayoutDefault>
<Stack justify="cneter" h={"90vh"} mt={"xl"}>
<ComponentGlobal_CardStyles>
{_.isNull(data) ? (
<Stack>
{Array.from(new Array(4)).map((e, i) => (
<Skeleton key={i} h={20} w={"100%"} />
))}
{_.isNull(isAccess) ? (
<Stack align="center">
<CustomSkeleton height={20} width={"100%"} />
<CustomSkeleton height={20} width={"70%"} />
<CustomSkeleton height={20} width={"100%"} />
<CustomSkeleton height={20} width={"70%"} />
</Stack>
) : (
<Stack align="center">
@@ -71,16 +86,28 @@ export default function WaitingRoom_View({
Whatsapp setelah disetujui.
</Text>
</Stack>
{/* <Button
color="red"
loaderPosition="center"
loading={loading}
radius={"xl"}
onClick={() => onClickLogout()}
>
Keluar
</Button> */}
{isAccess && (
<Button
color="yellow"
bg={MainColor.yellow}
c={MainColor.darkblue}
loaderPosition="center"
loading={isLoadingHome}
radius={"xl"}
onClick={() => {
try {
setIsLoadingHome(true);
router.replace("/", { scroll: false });
} catch (error) {
clientLogger.error("Error button to home", error);
} finally {
setIsLoadingHome(false);
}
}}
>
Home
</Button>
)}
</Stack>
)}
</ComponentGlobal_CardStyles>