From 7eadadbd1df1b76adf628bb7cbed869265948c72 Mon Sep 17 00:00:00 2001 From: berkay Date: Mon, 7 Apr 2025 13:52:02 +0300 Subject: [PATCH] select employee tested --- .../AuthService/endpoints/auth/route.py | 4 +-- .../request/authentication/login_post.py | 2 +- .../src/apicalls/login/login.tsx | 24 +++++++------- .../src/app/(AuthLayout)/auth/select/page.tsx | 2 +- .../src/app/(AuthLayout)/dashboard/page.tsx | 14 ++++++++ .../src/components/auth/select.tsx | 32 ++++++++++++++++--- 6 files changed, 57 insertions(+), 21 deletions(-) create mode 100644 WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx diff --git a/ApiServices/AuthService/endpoints/auth/route.py b/ApiServices/AuthService/endpoints/auth/route.py index 4cdac00..067aa54 100644 --- a/ApiServices/AuthService/endpoints/auth/route.py +++ b/ApiServices/AuthService/endpoints/auth/route.py @@ -8,7 +8,7 @@ from ApiServices.AuthService.config import api_config from ApiServices.AuthService.validations.request.authentication.login_post import ( RequestLogin, RequestSelectLiving, - RequestSelectOccupant, + RequestSelectEmployee, RequestCreatePassword, RequestChangePassword, RequestForgotPasswordPhone, @@ -67,7 +67,7 @@ def authentication_login_post( ) def authentication_select_post( request: Request, - data: Union[RequestSelectOccupant, RequestSelectLiving], + data: Union[RequestSelectEmployee, RequestSelectLiving], language: str = Header(None, alias="language"), domain: str = Header(None, alias="domain"), tz: str = Header(None, alias="timezone"), diff --git a/ApiServices/AuthService/validations/request/authentication/login_post.py b/ApiServices/AuthService/validations/request/authentication/login_post.py index 838111c..fb74b9c 100644 --- a/ApiServices/AuthService/validations/request/authentication/login_post.py +++ b/ApiServices/AuthService/validations/request/authentication/login_post.py @@ -18,7 +18,7 @@ class RequestApplication(BaseModel): page: str # /building/create -class RequestSelectOccupant(BaseModel): +class RequestSelectEmployee(BaseModel): company_uu_id: str diff --git a/WebServices/client-frontend/src/apicalls/login/login.tsx b/WebServices/client-frontend/src/apicalls/login/login.tsx index 8a889c1..edd0364 100644 --- a/WebServices/client-frontend/src/apicalls/login/login.tsx +++ b/WebServices/client-frontend/src/apicalls/login/login.tsx @@ -24,9 +24,7 @@ interface LoginSelectEmployee { } interface LoginSelectOccupant { - selectedBuilding: any; - build_part_uu_id: string; - occupant_uu_id: string; + build_living_space_uu_id: any; } async function loginViaAccessKeys(payload: LoginViaAccessKeys) { @@ -51,7 +49,7 @@ async function loginViaAccessKeys(payload: LoginViaAccessKeys) { const accessObject = await nextCrypto.encrypt( JSON.stringify({ userType: loginRespone.user_type, - selectionList:loginRespone.selection_list + selectionList: loginRespone.selection_list, }) ); const userProfile = await nextCrypto.encrypt( @@ -122,7 +120,7 @@ async function loginSelectEmployee(payload: LoginSelectEmployee) { "POST", false ); - if (selectResponse.status === 200) { + if (selectResponse.status === 200 || selectResponse.status === 202) { const usersSelection = await nextCrypto.encrypt( JSON.stringify({ company_uu_id: payload.company_uu_id, @@ -139,14 +137,13 @@ async function loginSelectEmployee(payload: LoginSelectEmployee) { } async function loginSelectOccupant(payload: LoginSelectOccupant) { - const selectedBuilding = payload.selectedBuilding; + const build_living_space_uu_id = payload.build_living_space_uu_id; const cookieStore = await cookies(); const nextCrypto = new NextCrypto(tokenSecret); const selectResponse: any = await fetchDataWithToken( loginSelectEndpoint, { - build_part_uu_id: payload.build_part_uu_id, - occupant_uu_id: payload.occupant_uu_id, + build_living_space_uu_id: build_living_space_uu_id, }, "POST", false @@ -155,11 +152,12 @@ async function loginSelectOccupant(payload: LoginSelectOccupant) { if (selectResponse.status === 200) { const usersSelection = await nextCrypto.encrypt( JSON.stringify({ - company_uu_id: { - build_part_uu_id: payload.build_part_uu_id, - occupant_uu_id: payload.occupant_uu_id, - build_id: selectedBuilding, - }, + // company_uu_id: { + // build_part_uu_id: payload.build_part_uu_id, + // occupant_uu_id: payload.occupant_uu_id, + // build_id: selectedBuilding, + // }, + build_living_space_uu_id: build_living_space_uu_id, user_type: "occupant", }) ); diff --git a/WebServices/client-frontend/src/app/(AuthLayout)/auth/select/page.tsx b/WebServices/client-frontend/src/app/(AuthLayout)/auth/select/page.tsx index 34c6dd2..ddc4c78 100644 --- a/WebServices/client-frontend/src/app/(AuthLayout)/auth/select/page.tsx +++ b/WebServices/client-frontend/src/app/(AuthLayout)/auth/select/page.tsx @@ -16,7 +16,7 @@ async function SelectPage() { const selectionList = selection?.selectionList; if (!selectionList || !token_is_valid) { - redirect("/login/email"); + redirect("/auth/login"); } return ( <> diff --git a/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx b/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx new file mode 100644 index 0000000..64c2af0 --- /dev/null +++ b/WebServices/client-frontend/src/app/(AuthLayout)/dashboard/page.tsx @@ -0,0 +1,14 @@ +import React from "react"; +import { checkAccessTokenIsValid } from "@/apicalls/cookies/token"; +import { redirect } from "next/navigation"; + +async function DashboardPage() { + const token_is_valid = await checkAccessTokenIsValid(); + + if (!token_is_valid) { + redirect("/auth/login"); + } + return
You have arrived to Dashboard Page
; +} + +export default DashboardPage; diff --git a/WebServices/client-frontend/src/components/auth/select.tsx b/WebServices/client-frontend/src/components/auth/select.tsx index 6f61a79..0b6b91e 100644 --- a/WebServices/client-frontend/src/components/auth/select.tsx +++ b/WebServices/client-frontend/src/components/auth/select.tsx @@ -1,7 +1,12 @@ "use client"; - import React from "react"; +import { + loginSelectEmployee, + loginSelectOccupant, +} from "@/apicalls/login/login"; +import { useRouter } from "next/navigation"; + function SelectList({ selectionList, isEmployee, @@ -16,11 +21,31 @@ function SelectList({ isEmployee: boolean; isOccupant: boolean; }) { - const handleClick = (uu_id: string) => { + const router = useRouter(); + + const setSelectionHandler = (uu_id: string) => { if (isEmployee) { console.log("Selected isEmployee uu_id:", uu_id); + loginSelectEmployee({ company_uu_id: uu_id }) + .then((responseData: any) => { + if (responseData?.status === 200 || responseData?.status === 202) { + router.push("/dashboard"); + } + }) + .catch((error) => { + console.error(error); + }); } else if (isOccupant) { console.log("Selected isOccupant uu_id:", uu_id); + loginSelectOccupant({ build_living_space_uu_id: uu_id }) + .then((responseData: any) => { + if (responseData?.status === 200 || responseData?.status === 202) { + router.push("/dashboard"); + } + }) + .catch((error) => { + console.error(error); + }); } }; @@ -30,12 +55,11 @@ function SelectList({
handleClick(item.uu_id)} + onClick={() => setSelectionHandler(item.uu_id)} >
{item.public_name} - {""} {item.company_type}