select employee tested

This commit is contained in:
berkay 2025-04-07 13:52:02 +03:00
parent e4d50306ac
commit 7eadadbd1d
6 changed files with 57 additions and 21 deletions

View File

@ -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"),

View File

@ -18,7 +18,7 @@ class RequestApplication(BaseModel):
page: str # /building/create
class RequestSelectOccupant(BaseModel):
class RequestSelectEmployee(BaseModel):
company_uu_id: str

View File

@ -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",
})
);

View File

@ -16,7 +16,7 @@ async function SelectPage() {
const selectionList = selection?.selectionList;
if (!selectionList || !token_is_valid) {
redirect("/login/email");
redirect("/auth/login");
}
return (
<>

View File

@ -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 <div>You have arrived to Dashboard Page</div>;
}
export default DashboardPage;

View File

@ -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({
<div
key={index}
className="w-full p-4 m-2 bg-emerald-300 hover:bg-emerald-500 rounded-lg transition-colors duration-200 cursor-pointer"
onClick={() => handleClick(item.uu_id)}
onClick={() => setSelectionHandler(item.uu_id)}
>
<div className="flex flex-col items-center md:items-start">
<div>
<span className="text-2xl font-medium">{item.public_name}</span>
{""}
<span className="font-medium text-sky-500">
{item.company_type}
</span>