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 WaitingRoom_View from "@/app_modules/waiting_room/view";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function Page() {
|
||||
const userLoginId = await funGetUserIdByToken();
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import { WibuRealtime } from "wibu-pkg";
|
||||
import { apiGetUserAccess } from "../_lib/api_fetch_user_access";
|
||||
import adminUserAccess_funEditAccess from "../fun/edit/fun_edit_access";
|
||||
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() {
|
||||
const [data, setData] = useState<MODEL_USER[] | null>(null);
|
||||
@@ -38,6 +39,8 @@ export default function AdminUserAccess_View() {
|
||||
const [isLoadingAccess, setIsLoadingAccess] = useState(false);
|
||||
const [isLoadingDelete, setIsLoadingDelete] = useState(false);
|
||||
const [userId, setUserId] = useState("");
|
||||
const [openedModal, setOpenedModal] = useState(false);
|
||||
const [dataUser, setDataUser] = useState<MODEL_USER | null>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
handleLoadData();
|
||||
@@ -90,8 +93,10 @@ export default function AdminUserAccess_View() {
|
||||
dataMessage: dataNotifikasi,
|
||||
});
|
||||
|
||||
setOpenedModal(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
setOpenedModal(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
@@ -111,8 +116,10 @@ export default function AdminUserAccess_View() {
|
||||
if (res.status === 200) {
|
||||
handleLoadData();
|
||||
|
||||
setOpenedModal(false);
|
||||
ComponentGlobal_NotifikasiBerhasil(res.message);
|
||||
} else {
|
||||
setOpenedModal(false);
|
||||
ComponentGlobal_NotifikasiGagal(res.message);
|
||||
}
|
||||
});
|
||||
@@ -153,12 +160,12 @@ export default function AdminUserAccess_View() {
|
||||
{e.active === false ? (
|
||||
<Center>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoadingAccess && userId === e.id}
|
||||
radius={"xl"}
|
||||
color="Green"
|
||||
onClick={() => {
|
||||
onAccess(e.id, e.nomor);
|
||||
setOpenedModal(true);
|
||||
setDataUser(e);
|
||||
// onAccess(e.id, e.nomor);
|
||||
}}
|
||||
>
|
||||
Grand Access
|
||||
@@ -167,12 +174,12 @@ export default function AdminUserAccess_View() {
|
||||
) : (
|
||||
<Center>
|
||||
<Button
|
||||
loaderPosition="center"
|
||||
loading={isLoadingDelete && userId === e.id}
|
||||
radius={"xl"}
|
||||
color="red"
|
||||
onClick={() => {
|
||||
onDelete(e.id);
|
||||
setOpenedModal(true);
|
||||
setDataUser(e);
|
||||
// onDelete(e.id);
|
||||
}}
|
||||
>
|
||||
Delete Access
|
||||
@@ -237,6 +244,49 @@ export default function AdminUserAccess_View() {
|
||||
</Paper>
|
||||
)}
|
||||
</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>
|
||||
<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.
|
||||
</Title>
|
||||
<Button
|
||||
|
||||
@@ -98,10 +98,12 @@ export default function WaitingRoom_View({
|
||||
try {
|
||||
setIsLoadingHome(true);
|
||||
router.replace("/", { scroll: false });
|
||||
setTimeout(() => {
|
||||
setIsLoadingHome(false);
|
||||
}, 1000);
|
||||
} catch (error) {
|
||||
clientLogger.error("Error button to home", error);
|
||||
} finally {
|
||||
setIsLoadingHome(false);
|
||||
clientLogger.error("Error button to home", error);
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
||||
@@ -137,7 +137,7 @@ export const middleware = async (req: NextRequest) => {
|
||||
"User validation failed:",
|
||||
userValidateResponse.statusText
|
||||
);
|
||||
return setCorsHeaders(unauthorizedResponseAPIUserValidate());
|
||||
return setCorsHeaders(unauthorizedResponseAPIUserValidate(req));
|
||||
}
|
||||
|
||||
const userValidateJson = await userValidateResponse.json();
|
||||
@@ -305,14 +305,17 @@ function unauthorizedResponseValidationAPIRequest() {
|
||||
);
|
||||
}
|
||||
|
||||
function unauthorizedResponseAPIUserValidate() {
|
||||
return new NextResponse(
|
||||
JSON.stringify({ error: "Unauthorized api user validate" }),
|
||||
{
|
||||
status: 401,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
}
|
||||
function unauthorizedResponseAPIUserValidate(req: NextRequest) {
|
||||
return setCorsHeaders(
|
||||
NextResponse.redirect(new URL("/waiting-room", req.url))
|
||||
);
|
||||
// return new NextResponse(
|
||||
// JSON.stringify({ error: "Unauthorized api user validate" }),
|
||||
// {
|
||||
// status: 401,
|
||||
// headers: { "Content-Type": "application/json" },
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
function unauthorizedResponseDataUserNotFound(req: NextRequest) {
|
||||
|
||||
Reference in New Issue
Block a user