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 { baseUrlAuth, tokenSecret } from "../basics";
import { cookies } from "next/headers"; import { cookies } from "next/headers";
import NextCrypto from "next-crypto"; import NextCrypto from "next-crypto";
import { console } from "inspector";
const checkToken = `${baseUrlAuth}/authentication/token/check`; const checkToken = `${baseUrlAuth}/authentication/token/check`;
const pageValid = `${baseUrlAuth}/authentication/page/valid`;
const siteUrls = `${baseUrlAuth}/authentication/page/list`;
const nextCrypto = new NextCrypto(tokenSecret); const nextCrypto = new NextCrypto(tokenSecret);
async function checkAccessTokenIsValid() { async function checkAccessTokenIsValid() {
@ -13,6 +15,27 @@ async function checkAccessTokenIsValid() {
return response?.status === 200 || response?.status === 202 ? true : false; 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() { async function retrieveAccessToken() {
const cookieStore = await cookies(); const cookieStore = await cookies();
const encrpytAccessToken = cookieStore.get("accessToken")?.value || ""; const encrpytAccessToken = cookieStore.get("accessToken")?.value || "";
@ -112,5 +135,7 @@ export {
retrieveUserType, retrieveUserType,
retrieveAccessObjects, retrieveAccessObjects,
retrieveUserSelection, retrieveUserSelection,
retrievePagebyUrl,
retrievePageList,
// retrieveavailablePages, // retrieveavailablePages,
}; };

View File

@ -1,9 +1,12 @@
import React from "react"; import React from "react";
import { checkAccessTokenIsValid } from "@/apicalls/cookies/token"; import {
checkAccessTokenIsValid,
retrievePageList,
retrievePagebyUrl,
} from "@/apicalls/cookies/token";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { retrievePage } from "@/components/NavigatePages";
import LeftMenu from "./leftMenu"; import LeftMenu from "@/components/menu/leftMenu";
import MainPage from "./main";
export default async function DashboardLayout({ export default async function DashboardLayout({
searchParams, searchParams,
@ -11,32 +14,27 @@ export default async function DashboardLayout({
searchParams: { [key: string]: string | undefined }; searchParams: { [key: string]: string | undefined };
}) { }) {
const token_is_valid = await checkAccessTokenIsValid(); const token_is_valid = await checkAccessTokenIsValid();
const siteUrlsList = await retrievePageList();
if (!token_is_valid) { if (!token_is_valid) {
redirect("/auth/login"); redirect("/auth/login");
} }
const pageUuidList = [ const lang = "tr";
"6015129b-f665-479c-a440-04fb82ea6114", const pageToDirect = await retrievePagebyUrl("/dashboard");
"14a98ae7-c64e-403d-9b53-32e7ea867ab4", const PageComponent = retrievePage(pageToDirect);
"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;
return ( return (
<>
<div className="flex h-screen overflow-hidden"> <div className="flex h-screen overflow-hidden">
{/* Sidebar */} {/* Sidebar */}
<aside className="w-1/4 border-r p-4 overflow-y-auto"> <aside className="w-1/4 border-r p-4 overflow-y-auto">
<LeftMenu <LeftMenu
pageUuidList={pageUuidList} pageUuidList={siteUrlsList}
lang={lang} lang={lang}
searchParams={queryParams} searchParams={searchParams}
/> />
</aside> </aside>
{/* Main Content Area */} {/* Main Content Area */}
<div className="flex flex-col w-3/4"> <div className="flex flex-col w-3/4">
{/* Sticky Header */} {/* Sticky Header */}
<header className="sticky top-0 bg-white shadow-md z-10 p-4 flex justify-between items-center"> <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 className="w-10 h-10 bg-gray-300 rounded-full"></div>
</div> </div>
</header> </header>
<MainPage pageSelected={pageSelected} lang={lang} /> <PageComponent lang={lang} queryParams={searchParams} />
</div> </div>
</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 Page0001 from "./page0001";
import { PageProps } from "./interFaces";
const PageIndexs = { export const PageIndexs = {
"6015129b-f665-479c-a440-04fb82ea6114": Page0001, "6015129b-f665-479c-a440-04fb82ea6114": Page0001,
app000001: App000001,
}; };
function UnAuthorizedPage({ lang }: PageProps) { function UnAuthorizedPage({ lang }: PageProps) {

View File

@ -1,3 +1,6 @@
import { LanguageTranslation } from "@/components/menu/runner";
export interface PageProps { 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"> <div className="ml-5">
{subItem.subList.map((subSubItem) => ( {subItem.subList.map((subSubItem) => (
<Link <Link
key={subSubItem.appUUID} key={subSubItem.name}
href={`/dashboard?page=${subSubItem.appUUID}&menu=${firstIndex}*${secondIndex}`} 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 ${ 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" ? " bg-gray-100 cursor-not-allowed"
: "hover:bg-gray-200" : "hover:bg-gray-200"
}`} }`}

View File

@ -4,7 +4,7 @@
* @param {Array} menu - The original menu structure * @param {Array} menu - The original menu structure
* @returns {Array} - Filtered menu structure with only matching items * @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 // Define TypeScript interfaces for menu structure
interface LanguageTranslation { interface LanguageTranslation {
@ -15,7 +15,7 @@ interface LanguageTranslation {
interface MenuThirdLevel { interface MenuThirdLevel {
name: string; name: string;
lg: LanguageTranslation; lg: LanguageTranslation;
appList: string[]; siteUrl: string;
} }
interface MenuSecondLevel { interface MenuSecondLevel {
@ -34,7 +34,7 @@ interface MenuFirstLevel {
interface FilteredMenuThirdLevel { interface FilteredMenuThirdLevel {
name: string; name: string;
lg: LanguageTranslation; lg: LanguageTranslation;
appUUID: string; siteUrl: string;
} }
interface FilteredMenuSecondLevel { interface FilteredMenuSecondLevel {
@ -51,12 +51,7 @@ interface FilteredMenuFirstLevel {
export type { LanguageTranslation }; export type { LanguageTranslation };
function transformMenu(uuids: string[]) { function transformMenu(siteUrls: 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));
};
// Process the menu structure // Process the menu structure
const filteredMenu: FilteredMenuFirstLevel[] = Menu.reduce( const filteredMenu: FilteredMenuFirstLevel[] = Menu.reduce(
(acc: FilteredMenuFirstLevel[], firstLevel: MenuFirstLevel) => { (acc: FilteredMenuFirstLevel[], firstLevel: MenuFirstLevel) => {
@ -78,29 +73,21 @@ function transformMenu(uuids: string[]) {
// Process third level items // Process third level items
secondLevel.subList.forEach((thirdLevel: MenuThirdLevel) => { 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 ( if (
thirdLevel.appList && thirdLevel.siteUrl &&
hasIntersection(thirdLevel.appList, uuids) siteUrls.some((url) => url === thirdLevel.siteUrl)
) { ) {
// Find the first matching UUID // Create a modified third level item
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
const newThirdLevel: FilteredMenuThirdLevel = { const newThirdLevel: FilteredMenuThirdLevel = {
name: thirdLevel.name, name: thirdLevel.name,
lg: { ...thirdLevel.lg }, lg: { ...thirdLevel.lg },
appUUID: matchedUUID, siteUrl: thirdLevel.siteUrl,
}; };
// Add the modified third level to the second level's subList // Add the modified third level to the second level's subList
newSecondLevel.subList.push(newThirdLevel); newSecondLevel.subList.push(newThirdLevel);
} }
}
}); });
// Only add the second level to the first level if it has any matching third level items // 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", tr: "Birey",
en: "Individual", en: "Individual",
}, },
appList: [ siteUrl: "/individual",
"0362071d-90d9-48db-8fa0-3528aaf450bd",
"6015129b-f665-479c-a440-04fb82ea6114",
],
}; };
const User = { const User = {
@ -16,7 +13,7 @@ const User = {
tr: "Kullanıcı", tr: "Kullanıcı",
en: "User", en: "User",
}, },
appList: ["14a98ae7-c64e-403d-9b53-32e7ea867ab4"], siteUrl: "/user",
}; };
const Build = { const Build = {
@ -25,7 +22,7 @@ const Build = {
tr: "Apartman", tr: "Apartman",
en: "Build", en: "Build",
}, },
appList: ["e368137d-d548-4ed4-90da-337bcc5d1559"], siteUrl: "/build",
}; };
const BuildParts = { const BuildParts = {
@ -34,7 +31,7 @@ const BuildParts = {
tr: "Daire", tr: "Daire",
en: "BuildParts", en: "BuildParts",
}, },
appList: [], siteUrl: "/build/parts",
}; };
const BuildArea = { const BuildArea = {
@ -43,7 +40,7 @@ const BuildArea = {
tr: "Daire", tr: "Daire",
en: "BuildArea", en: "BuildArea",
}, },
appList: [], siteUrl: "/build/area",
}; };
const ManagementAccounting = { const ManagementAccounting = {
@ -52,7 +49,7 @@ const ManagementAccounting = {
tr: "Yönetim Cari Hareketler", tr: "Yönetim Cari Hareketler",
en: "ManagementAccounting", en: "ManagementAccounting",
}, },
appList: [], siteUrl: "/management/accounting",
}; };
const ManagementBudget = { const ManagementBudget = {
@ -61,7 +58,7 @@ const ManagementBudget = {
tr: "Yönetim Bütçe İşlemleri", tr: "Yönetim Bütçe İşlemleri",
en: "Management Budget", en: "Management Budget",
}, },
appList: [], siteUrl: "/management/budget",
}; };
const BuildPartsAccounting = { const BuildPartsAccounting = {
@ -70,7 +67,7 @@ const BuildPartsAccounting = {
tr: "Daire Cari Hareketler", tr: "Daire Cari Hareketler",
en: "Build Parts Accounting", en: "Build Parts Accounting",
}, },
appList: [], siteUrl: "/build/parts/accounting",
}; };
const AnnualMeeting = { const AnnualMeeting = {
@ -79,7 +76,7 @@ const AnnualMeeting = {
tr: "Yıllık Olağan Toplantı Tanımlama ve Davet", tr: "Yıllık Olağan Toplantı Tanımlama ve Davet",
en: "Annual Meetings and Invitations", en: "Annual Meetings and Invitations",
}, },
appList: ["d3d97973-41c6-4bad-881b-6bf77d837fa5"], siteUrl: "/annual/meeting",
}; };
const AnnualMeetingClose = { const AnnualMeetingClose = {
@ -88,7 +85,7 @@ const AnnualMeetingClose = {
tr: "Yıllık Olağan Toplantı kapatma ve Cari Yaratma", tr: "Yıllık Olağan Toplantı kapatma ve Cari Yaratma",
en: "Annual Meeting Close and Accountings", en: "Annual Meeting Close and Accountings",
}, },
appList: [], siteUrl: "/annual/meeting/close",
}; };
const EmergencyMeeting = { const EmergencyMeeting = {
@ -97,7 +94,7 @@ const EmergencyMeeting = {
tr: "Acil Toplantı Tanımlama ve Davet", tr: "Acil Toplantı Tanımlama ve Davet",
en: "Emergency Meeting and Invitations", en: "Emergency Meeting and Invitations",
}, },
appList: [], siteUrl: "emergency/meeting",
}; };
const EmergencyMeetingClose = { const EmergencyMeetingClose = {
@ -106,7 +103,7 @@ const EmergencyMeetingClose = {
tr: "Acil Olağan Toplantı kapatma ve Cari Yaratma", tr: "Acil Olağan Toplantı kapatma ve Cari Yaratma",
en: "Emergency Meeting Close and Accountings", en: "Emergency Meeting Close and Accountings",
}, },
appList: [], siteUrl: "/emergency/meeting/close",
}; };
const MeetingParticipations = { const MeetingParticipations = {
@ -115,7 +112,7 @@ const MeetingParticipations = {
tr: "Toplantı Katılım İşlemleri", tr: "Toplantı Katılım İşlemleri",
en: "Meeting Participations", en: "Meeting Participations",
}, },
appList: ["SomeUUID"], siteUrl: "/meeting/participations",
}; };
const Menu = [ const Menu = [

View File

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