fix : logic access user
deskripsi: - fix waiting room loading - fix user access modal - fix middleware No Issue
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
|
||||||
import WaitingRoom_View from "@/app_modules/waiting_room/view";
|
import WaitingRoom_View from "@/app_modules/waiting_room/view";
|
||||||
|
|
||||||
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
const userLoginId = await funGetUserIdByToken();
|
const userLoginId = await funGetUserIdByToken();
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { WibuRealtime } from "wibu-pkg";
|
|||||||
import { apiGetUserAccess } from "../_lib/api_fetch_user_access";
|
import { apiGetUserAccess } from "../_lib/api_fetch_user_access";
|
||||||
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
||||||
import { Admin_V3_ComponentPaginationBreakpoint } from "../../_components_v3/comp_pagination_breakpoint";
|
import { Admin_V3_ComponentPaginationBreakpoint } from "../../_components_v3/comp_pagination_breakpoint";
|
||||||
|
import { Admin_ComponentModal } from "../../_admin_global/_component/comp_admin_modal";
|
||||||
|
|
||||||
export default function AdminUserAccess_View() {
|
export default function AdminUserAccess_View() {
|
||||||
const [data, setData] = useState<MODEL_USER[] | null>(null);
|
const [data, setData] = useState<MODEL_USER[] | null>(null);
|
||||||
@@ -38,6 +39,8 @@ export default function AdminUserAccess_View() {
|
|||||||
const [isLoadingAccess, setIsLoadingAccess] = useState(false);
|
const [isLoadingAccess, setIsLoadingAccess] = useState(false);
|
||||||
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
|
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
|
||||||
const [userId, setUserId] = useState("");
|
const [userId, setUserId] = useState("");
|
||||||
|
const [openedModal, setOpenedModal] = useState(false);
|
||||||
|
const [dataUser, setDataUser] = useState<MODEL_USER | null>(null);
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
handleLoadData();
|
handleLoadData();
|
||||||
@@ -90,8 +93,10 @@ export default function AdminUserAccess_View() {
|
|||||||
dataMessage: dataNotifikasi,
|
dataMessage: dataNotifikasi,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setOpenedModal(false);
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
} else {
|
} else {
|
||||||
|
setOpenedModal(false);
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
ComponentGlobal_NotifikasiGagal(res.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -111,8 +116,10 @@ export default function AdminUserAccess_View() {
|
|||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
handleLoadData();
|
handleLoadData();
|
||||||
|
|
||||||
|
setOpenedModal(false);
|
||||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||||
} else {
|
} else {
|
||||||
|
setOpenedModal(false);
|
||||||
ComponentGlobal_NotifikasiGagal(res.message);
|
ComponentGlobal_NotifikasiGagal(res.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -153,12 +160,12 @@ export default function AdminUserAccess_View() {
|
|||||||
{e.active === false ? (
|
{e.active === false ? (
|
||||||
<Center>
|
<Center>
|
||||||
<Button
|
<Button
|
||||||
loaderPosition="center"
|
|
||||||
loading={isLoadingAccess && userId === e.id}
|
|
||||||
radius={"xl"}
|
radius={"xl"}
|
||||||
color="Green"
|
color="Green"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onAccess(e.id, e.nomor);
|
setOpenedModal(true);
|
||||||
|
setDataUser(e);
|
||||||
|
// onAccess(e.id, e.nomor);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Grand Access
|
Grand Access
|
||||||
@@ -167,12 +174,12 @@ export default function AdminUserAccess_View() {
|
|||||||
) : (
|
) : (
|
||||||
<Center>
|
<Center>
|
||||||
<Button
|
<Button
|
||||||
loaderPosition="center"
|
|
||||||
loading={isLoadingDelete && userId === e.id}
|
|
||||||
radius={"xl"}
|
radius={"xl"}
|
||||||
color="red"
|
color="red"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
onDelete(e.id);
|
setOpenedModal(true);
|
||||||
|
setDataUser(e);
|
||||||
|
// onDelete(e.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete Access
|
Delete Access
|
||||||
@@ -237,6 +244,49 @@ export default function AdminUserAccess_View() {
|
|||||||
</Paper>
|
</Paper>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
|
<Admin_ComponentModal
|
||||||
|
opened={openedModal}
|
||||||
|
onClose={() => {
|
||||||
|
setOpenedModal(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Stack>
|
||||||
|
<Title order={4} c={AdminColor.white}>
|
||||||
|
Apakah anda akan{" "}
|
||||||
|
{dataUser?.active === true ? "menghapus" : "memberikan"} akses ke{" "}
|
||||||
|
{dataUser?.username} ?
|
||||||
|
</Title>
|
||||||
|
<Group position="center">
|
||||||
|
<Button
|
||||||
|
radius={"xl"}
|
||||||
|
onClick={() => {
|
||||||
|
setOpenedModal(false);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Tidak
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
color="green"
|
||||||
|
loaderPosition="center"
|
||||||
|
loading={
|
||||||
|
(isLoadingAccess && userId === dataUser?.id) ||
|
||||||
|
(isLoadingDelete && userId === dataUser?.id)
|
||||||
|
}
|
||||||
|
radius={"xl"}
|
||||||
|
onClick={() => {
|
||||||
|
if (dataUser?.active === true) {
|
||||||
|
onDelete(dataUser?.id!);
|
||||||
|
} else {
|
||||||
|
onAccess(dataUser?.id!, dataUser?.nomor!);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Ya
|
||||||
|
</Button>
|
||||||
|
</Group>
|
||||||
|
</Stack>
|
||||||
|
</Admin_ComponentModal>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export default function InvalidUser() {
|
|||||||
<>
|
<>
|
||||||
<UIGlobal_LayoutDefault>
|
<UIGlobal_LayoutDefault>
|
||||||
<Stack align="center" justify="center" spacing="md" h={"100vh"}>
|
<Stack align="center" justify="center" spacing="md" h={"100vh"}>
|
||||||
<Title order={2} c={MainColor.white}>
|
<Title order={3} c={MainColor.white} align="center">
|
||||||
Maaf, Anda tidak memiliki izin untuk mengakses halaman ini. Silakan logout terlebih dahulu.
|
Maaf, Anda tidak memiliki izin untuk mengakses halaman ini. Silakan logout terlebih dahulu.
|
||||||
</Title>
|
</Title>
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -98,10 +98,12 @@ export default function WaitingRoom_View({
|
|||||||
try {
|
try {
|
||||||
setIsLoadingHome(true);
|
setIsLoadingHome(true);
|
||||||
router.replace("/", { scroll: false });
|
router.replace("/", { scroll: false });
|
||||||
|
setTimeout(() => {
|
||||||
|
setIsLoadingHome(false);
|
||||||
|
}, 1000);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
clientLogger.error("Error button to home", error);
|
|
||||||
} finally {
|
|
||||||
setIsLoadingHome(false);
|
setIsLoadingHome(false);
|
||||||
|
clientLogger.error("Error button to home", error);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
"User validation failed:",
|
"User validation failed:",
|
||||||
userValidateResponse.statusText
|
userValidateResponse.statusText
|
||||||
);
|
);
|
||||||
return setCorsHeaders(unauthorizedResponseAPIUserValidate());
|
return setCorsHeaders(unauthorizedResponseAPIUserValidate(req));
|
||||||
}
|
}
|
||||||
|
|
||||||
const userValidateJson = await userValidateResponse.json();
|
const userValidateJson = await userValidateResponse.json();
|
||||||
@@ -305,14 +305,17 @@ function unauthorizedResponseValidationAPIRequest() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unauthorizedResponseAPIUserValidate() {
|
function unauthorizedResponseAPIUserValidate(req: NextRequest) {
|
||||||
return new NextResponse(
|
return setCorsHeaders(
|
||||||
JSON.stringify({ error: "Unauthorized api user validate" }),
|
NextResponse.redirect(new URL("/waiting-room", req.url))
|
||||||
{
|
|
||||||
status: 401,
|
|
||||||
headers: { "Content-Type": "application/json" },
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
|
// return new NextResponse(
|
||||||
|
// JSON.stringify({ error: "Unauthorized api user validate" }),
|
||||||
|
// {
|
||||||
|
// status: 401,
|
||||||
|
// headers: { "Content-Type": "application/json" },
|
||||||
|
// }
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
function unauthorizedResponseDataUserNotFound(req: NextRequest) {
|
function unauthorizedResponseDataUserNotFound(req: NextRequest) {
|
||||||
|
|||||||
Reference in New Issue
Block a user