updated app page and site urls

This commit is contained in:
berkay 2025-04-09 13:00:48 +03:00
parent 7c2150a8b0
commit 9b02620d1d
9 changed files with 186 additions and 143 deletions

View File

@ -3,9 +3,11 @@ import { fetchDataWithToken, fetchData } from "../api-fetcher";
import { baseUrlAuth, tokenSecret } from "../basics";
import { cookies } from "next/headers";
import NextCrypto from "next-crypto";
import { console } from "inspector";
const checkToken = `${baseUrlAuth}/authentication/token/check`;
const pageValid = `${baseUrlAuth}/authentication/page/valid`;
const siteUrls = `${baseUrlAuth}/authentication/page/list`;
const nextCrypto = new NextCrypto(tokenSecret);
async function checkAccessTokenIsValid() {
@ -13,6 +15,27 @@ async function checkAccessTokenIsValid() {
return response?.status === 200 || response?.status === 202 ? true : false;
}
async function retrievePageList() {
const response = await fetchDataWithToken(siteUrls, {}, "GET", false);
return response?.status === 200 || response?.status === 202
? response.data?.site_urls
: null;
}
async function retrievePagebyUrl(pageUrl: string) {
const response = await fetchDataWithToken(
pageValid,
{
page_url: pageUrl,
},
"POST",
false
);
return response?.status === 200 || response?.status === 202
? response.data?.application
: null;
}
async function retrieveAccessToken() {
const cookieStore = await cookies();
const encrpytAccessToken = cookieStore.get("accessToken")?.value || "";
@ -112,5 +135,7 @@ export {
retrieveUserType,
retrieveAccessObjects,
retrieveUserSelection,
retrievePagebyUrl,
retrievePageList,
// retrieveavailablePages,
};

View File

@ -1,9 +1,12 @@
import React from "react";
import { checkAccessTokenIsValid } from "@/apicalls/cookies/token";
import {
checkAccessTokenIsValid,
retrievePageList,
retrievePagebyUrl,
} from "@/apicalls/cookies/token";
import { redirect } from "next/navigation";
import LeftMenu from "./leftMenu";
import MainPage from "./main";
import { retrievePage } from "@/components/NavigatePages";
import LeftMenu from "@/components/menu/leftMenu";
export default async function DashboardLayout({
searchParams,
@ -11,32 +14,27 @@ export default async function DashboardLayout({
searchParams: { [key: string]: string | undefined };
}) {
const token_is_valid = await checkAccessTokenIsValid();
const siteUrlsList = await retrievePageList();
if (!token_is_valid) {
redirect("/auth/login");
}
const pageUuidList = [
"6015129b-f665-479c-a440-04fb82ea6114",
"14a98ae7-c64e-403d-9b53-32e7ea867ab4",
"e368137d-d548-4ed4-90da-337bcc5d1559",
"d3d97973-41c6-4bad-881b-6bf77d837fa5",
]; // Mock data of pageUUID list []
const lang = "tr"; // Assuming you have a way to determine the current language
const queryParams = await searchParams;
const pageSelected = queryParams?.page || undefined;
const lang = "tr";
const pageToDirect = await retrievePagebyUrl("/dashboard");
const PageComponent = retrievePage(pageToDirect);
return (
<>
<div className="flex h-screen overflow-hidden">
{/* Sidebar */}
<aside className="w-1/4 border-r p-4 overflow-y-auto">
<LeftMenu
pageUuidList={pageUuidList}
pageUuidList={siteUrlsList}
lang={lang}
searchParams={queryParams}
searchParams={searchParams}
/>
</aside>
{/* Main Content Area */}
<div className="flex flex-col w-3/4">
{/* Sticky Header */}
<header className="sticky top-0 bg-white shadow-md z-10 p-4 flex justify-between items-center">
@ -50,8 +48,9 @@ export default async function DashboardLayout({
<div className="w-10 h-10 bg-gray-300 rounded-full"></div>
</div>
</header>
<MainPage pageSelected={pageSelected} lang={lang} />
<PageComponent lang={lang} queryParams={searchParams} />
</div>
</div>
</>
);
}

View File

@ -0,0 +1,29 @@
import React from "react";
import { PageProps } from "./interFaces";
function App000001({ lang, queryParams }: PageProps) {
return (
<>
<div className="flex flex-col w-3/4">
{/* Sticky Header */}
<header className="sticky top-0 bg-white shadow-md z-10 p-4 flex justify-between items-center">
<h1 className="text-2xl font-semibold">Dashboard</h1>
<div className="flex items-center space-x-4">
{JSON.stringify({
lang,
queryParams,
})}
<input
type="text"
placeholder="Search..."
className="border px-3 py-2 rounded-lg"
/>
<div className="w-10 h-10 bg-gray-300 rounded-full"></div>
</div>
</header>
</div>
</>
);
}
export default App000001;

View File

@ -1,8 +1,11 @@
import { PageProps } from "./interFaces";
import React from "react";
import App000001 from "./app000001";
import Page0001 from "./page0001";
import { PageProps } from "./interFaces";
const PageIndexs = {
export const PageIndexs = {
"6015129b-f665-479c-a440-04fb82ea6114": Page0001,
app000001: App000001,
};
function UnAuthorizedPage({ lang }: PageProps) {

View File

@ -1,3 +1,6 @@
import { LanguageTranslation } from "@/components/menu/runner";
export interface PageProps {
lang: string;
lang: keyof LanguageTranslation;
queryParams: { [key: string]: string | undefined };
}

View File

@ -72,10 +72,10 @@ async function LeftMenu({
<div className="ml-5">
{subItem.subList.map((subSubItem) => (
<Link
key={subSubItem.appUUID}
href={`/dashboard?page=${subSubItem.appUUID}&menu=${firstIndex}*${secondIndex}`}
key={subSubItem.name}
href={`/dashboard?page=${subSubItem.name}&menu=${firstIndex}*${secondIndex}`}
className={`flex flex-row text-xl py-4 my-4 w-full space-x-2 p-2 rounded ${
pageSelected === subSubItem.appUUID
pageSelected === subSubItem.name
? " bg-gray-100 cursor-not-allowed"
: "hover:bg-gray-200"
}`}

View File

@ -4,7 +4,7 @@
* @param {Array} menu - The original menu structure
* @returns {Array} - Filtered menu structure with only matching items
*/
import Menu from "@/menu/store"; // Assuming you have a menu structure imported
import Menu from "@/components/menu/store"; // Assuming you have a menu structure imported
// Define TypeScript interfaces for menu structure
interface LanguageTranslation {
@ -15,7 +15,7 @@ interface LanguageTranslation {
interface MenuThirdLevel {
name: string;
lg: LanguageTranslation;
appList: string[];
siteUrl: string;
}
interface MenuSecondLevel {
@ -34,7 +34,7 @@ interface MenuFirstLevel {
interface FilteredMenuThirdLevel {
name: string;
lg: LanguageTranslation;
appUUID: string;
siteUrl: string;
}
interface FilteredMenuSecondLevel {
@ -51,12 +51,7 @@ interface FilteredMenuFirstLevel {
export type { LanguageTranslation };
function transformMenu(uuids: string[]) {
// Helper function to check if arrays have at least one common element
const hasIntersection = (array1: string[], array2: string[]): boolean => {
return array1.some((item) => array2.includes(item));
};
function transformMenu(siteUrls: string[]) {
// Process the menu structure
const filteredMenu: FilteredMenuFirstLevel[] = Menu.reduce(
(acc: FilteredMenuFirstLevel[], firstLevel: MenuFirstLevel) => {
@ -78,29 +73,21 @@ function transformMenu(uuids: string[]) {
// Process third level items
secondLevel.subList.forEach((thirdLevel: MenuThirdLevel) => {
// Check if the third level's appList has an intersection with our UUIDs
// Check if the third level's siteUrl matches exactly
if (
thirdLevel.appList &&
hasIntersection(thirdLevel.appList, uuids)
thirdLevel.siteUrl &&
siteUrls.some((url) => url === thirdLevel.siteUrl)
) {
// Find the first matching UUID
const matchedUUID = thirdLevel.appList.find((uuid) =>
uuids.includes(uuid)
);
// Only proceed if we found a matching UUID (should always be true due to hasIntersection)
if (matchedUUID) {
// Create a modified third level item with the matched UUID
// Create a modified third level item
const newThirdLevel: FilteredMenuThirdLevel = {
name: thirdLevel.name,
lg: { ...thirdLevel.lg },
appUUID: matchedUUID,
siteUrl: thirdLevel.siteUrl,
};
// Add the modified third level to the second level's subList
newSecondLevel.subList.push(newThirdLevel);
}
}
});
// Only add the second level to the first level if it has any matching third level items

View File

@ -4,10 +4,7 @@ const Individual = {
tr: "Birey",
en: "Individual",
},
appList: [
"0362071d-90d9-48db-8fa0-3528aaf450bd",
"6015129b-f665-479c-a440-04fb82ea6114",
],
siteUrl: "/individual",
};
const User = {
@ -16,7 +13,7 @@ const User = {
tr: "Kullanıcı",
en: "User",
},
appList: ["14a98ae7-c64e-403d-9b53-32e7ea867ab4"],
siteUrl: "/user",
};
const Build = {
@ -25,7 +22,7 @@ const Build = {
tr: "Apartman",
en: "Build",
},
appList: ["e368137d-d548-4ed4-90da-337bcc5d1559"],
siteUrl: "/build",
};
const BuildParts = {
@ -34,7 +31,7 @@ const BuildParts = {
tr: "Daire",
en: "BuildParts",
},
appList: [],
siteUrl: "/build/parts",
};
const BuildArea = {
@ -43,7 +40,7 @@ const BuildArea = {
tr: "Daire",
en: "BuildArea",
},
appList: [],
siteUrl: "/build/area",
};
const ManagementAccounting = {
@ -52,7 +49,7 @@ const ManagementAccounting = {
tr: "Yönetim Cari Hareketler",
en: "ManagementAccounting",
},
appList: [],
siteUrl: "/management/accounting",
};
const ManagementBudget = {
@ -61,7 +58,7 @@ const ManagementBudget = {
tr: "Yönetim Bütçe İşlemleri",
en: "Management Budget",
},
appList: [],
siteUrl: "/management/budget",
};
const BuildPartsAccounting = {
@ -70,7 +67,7 @@ const BuildPartsAccounting = {
tr: "Daire Cari Hareketler",
en: "Build Parts Accounting",
},
appList: [],
siteUrl: "/build/parts/accounting",
};
const AnnualMeeting = {
@ -79,7 +76,7 @@ const AnnualMeeting = {
tr: "Yıllık Olağan Toplantı Tanımlama ve Davet",
en: "Annual Meetings and Invitations",
},
appList: ["d3d97973-41c6-4bad-881b-6bf77d837fa5"],
siteUrl: "/annual/meeting",
};
const AnnualMeetingClose = {
@ -88,7 +85,7 @@ const AnnualMeetingClose = {
tr: "Yıllık Olağan Toplantı kapatma ve Cari Yaratma",
en: "Annual Meeting Close and Accountings",
},
appList: [],
siteUrl: "/annual/meeting/close",
};
const EmergencyMeeting = {
@ -97,7 +94,7 @@ const EmergencyMeeting = {
tr: "Acil Toplantı Tanımlama ve Davet",
en: "Emergency Meeting and Invitations",
},
appList: [],
siteUrl: "emergency/meeting",
};
const EmergencyMeetingClose = {
@ -106,7 +103,7 @@ const EmergencyMeetingClose = {
tr: "Acil Olağan Toplantı kapatma ve Cari Yaratma",
en: "Emergency Meeting Close and Accountings",
},
appList: [],
siteUrl: "/emergency/meeting/close",
};
const MeetingParticipations = {
@ -115,7 +112,7 @@ const MeetingParticipations = {
tr: "Toplantı Katılım İşlemleri",
en: "Meeting Participations",
},
appList: ["SomeUUID"],
siteUrl: "/meeting/participations",
};
const Menu = [

View File

@ -49,19 +49,19 @@ services:
ports:
- "11222:6379"
# client_frontend:
# container_name: client_frontend
# build:
# context: .
# dockerfile: WebServices/client-frontend/Dockerfile
# networks:
# - wag-services
# ports:
# - "3000:3000"
# # volumes:
# # - client-frontend:/WebServices/client-frontend
# environment:
# - NODE_ENV=development
client_frontend:
container_name: client_frontend
build:
context: .
dockerfile: WebServices/client-frontend/Dockerfile
networks:
- wag-services
ports:
- "3000:3000"
# volumes:
# - client-frontend:/WebServices/client-frontend
environment:
- NODE_ENV=development
# management_frontend:
# container_name: management_frontend