From 734dc59e386ec4c1743e3a77628dc425b1498963 Mon Sep 17 00:00:00 2001 From: Berkay Date: Sat, 3 May 2025 15:13:44 +0300 Subject: [PATCH] updated mdenu --- .../menu/EmployeeProfileSection.tsx | 263 +++++--------- .../src/components/menu/NavigationMenu.tsx | 19 +- .../menu/OccupantProfileSection.tsx | 320 ++++-------------- .../components/menu/ProfileLoadingState.tsx | 5 +- .../src/components/menu/language.ts | 92 +++++ .../src/components/menu/menu.tsx | 29 +- .../src/components/menu/store.tsx | 255 -------------- .../src/components/menu/type.ts | 90 ++++- 8 files changed, 311 insertions(+), 762 deletions(-) create mode 100644 WebServices/management-frontend/src/components/menu/language.ts delete mode 100644 WebServices/management-frontend/src/components/menu/store.tsx diff --git a/WebServices/management-frontend/src/components/menu/EmployeeProfileSection.tsx b/WebServices/management-frontend/src/components/menu/EmployeeProfileSection.tsx index 5493744..ff55d8e 100644 --- a/WebServices/management-frontend/src/components/menu/EmployeeProfileSection.tsx +++ b/WebServices/management-frontend/src/components/menu/EmployeeProfileSection.tsx @@ -1,130 +1,58 @@ "use client"; import React, { useState, useEffect } from "react"; -import { User, Briefcase, ChevronDown } from "lucide-react"; -import { - retrieveAccessObjects, - retrieveUserSelection, -} from "@/apicalls/cookies/token"; +import { Briefcase } from "lucide-react"; +import { retrieveAccessObjects } from "@/apicalls/cookies/token"; import { loginSelectEmployee } from "@/apicalls/login/login"; +import { EmployeeProfileLanguage } from "./language"; +import { EmployeeProfileSectionProps, CompanyInfo } from "./type"; -// Language definitions for employee profile section -const profileLanguage = { - tr: { - userType: "Kullanıcı Tipi", - employee: "Çalışan", - loading: "Yükleniyor...", - changeSelection: "Seçimi Değiştir", - selectCompany: "Şirket Seçin", - noCompanies: "Kullanılabilir şirket bulunamadı", - duty: "Görev", - }, - en: { - userType: "User Type", - employee: "Employee", - loading: "Loading...", - changeSelection: "Change Selection", - selectCompany: "Select Company", - noCompanies: "No companies available", - duty: "Duty", - }, -}; - -interface CompanyInfo { - uu_id: string; - public_name: string; - company_type: string; - company_address: string | null; - duty: string; -} - -interface UserSelection { - userType: string; - selected: CompanyInfo; -} - -interface EmployeeProfileSectionProps { - userSelectionData: UserSelection; - lang?: "en" | "tr"; -} - -const EmployeeProfileSection: React.FC = ({ - userSelectionData, - lang = "en", -}) => { - const t = - profileLanguage[lang as keyof typeof profileLanguage] || profileLanguage.en; - +const EmployeeProfileSection: React.FC = ({ userSelectionData, lang = "en" }) => { + const t = EmployeeProfileLanguage[lang as keyof typeof EmployeeProfileLanguage] || EmployeeProfileLanguage.en; const [showSelectionList, setShowSelectionList] = useState(false); const [loading, setLoading] = useState(true); - // Initialize state with data from props - const [userSelection, setUserSelection] = useState( - userSelectionData?.selected || null - ); - const [selectionList, setSelectionList] = useState( - null - ); - const [availableCompanies, setAvailableCompanies] = useState( - [] - ); + const [userSelection, setUserSelection] = useState(userSelectionData?.selected || null); + const [selectionList, setSelectionList] = useState(null); + const [availableCompanies, setAvailableCompanies] = useState([]); const [hasMultipleOptions, setHasMultipleOptions] = useState(false); - // Fetch access objects for selection list when needed useEffect(() => { if (showSelectionList && !selectionList) { setLoading(true); - retrieveAccessObjects() - .then((accessObjectsData) => { - console.log("Access Objects:", accessObjectsData); + retrieveAccessObjects().then((accessObjectsData) => { + if (accessObjectsData && "selectionList" in accessObjectsData) { + const companies = (accessObjectsData as any).selectionList as CompanyInfo[]; + setSelectionList(companies); - if (accessObjectsData && "selectionList" in accessObjectsData) { - const companies = (accessObjectsData as any) - .selectionList as CompanyInfo[]; - setSelectionList(companies); - - // Filter out the currently selected company - if (userSelection) { - const filteredCompanies = companies.filter( - (company) => company.uu_id !== userSelection.uu_id - ); - setAvailableCompanies(filteredCompanies); - setHasMultipleOptions(filteredCompanies.length > 0); - } else { - setAvailableCompanies(companies); - setHasMultipleOptions(companies.length > 1); - } + if (userSelection) { + const filteredCompanies = companies.filter( + (company) => company.uu_id !== userSelection.uu_id + ); + setAvailableCompanies(filteredCompanies); + setHasMultipleOptions(filteredCompanies.length > 0); + } else { + setAvailableCompanies(companies); + setHasMultipleOptions(companies.length > 1); } - }) - .catch((err) => { - console.error("Error fetching access objects:", err); - }) - .finally(() => setLoading(false)); + } + }).catch((err) => { console.error("Error fetching access objects:", err) }).finally(() => setLoading(false)); } }, [showSelectionList, selectionList, userSelection]); - // Update user selection when props change useEffect(() => { if (userSelectionData?.selected) { setUserSelection(userSelectionData.selected as CompanyInfo); - // Check if we need to fetch selection list to determine if multiple options exist if (!selectionList) { - retrieveAccessObjects() - .then((accessObjectsData) => { - if (accessObjectsData && "selectionList" in accessObjectsData) { - const companies = (accessObjectsData as any) - .selectionList as CompanyInfo[]; - setSelectionList(companies); - - // Filter out the currently selected company - const filteredCompanies = companies.filter( - (company) => company.uu_id !== userSelectionData.selected.uu_id - ); - setHasMultipleOptions(filteredCompanies.length > 0); - } - }) - .catch((err) => { - console.error("Error fetching access objects:", err); - }); + retrieveAccessObjects().then((accessObjectsData) => { + if (accessObjectsData && "selectionList" in accessObjectsData) { + const companies = (accessObjectsData as any).selectionList as CompanyInfo[]; + setSelectionList(companies); + const filteredCompanies = companies.filter( + (company) => company.uu_id !== userSelectionData.selected.uu_id + ); + setHasMultipleOptions(filteredCompanies.length > 0); + } + }).catch((err) => { console.error("Error fetching access objects:", err) }); } } }, [userSelectionData, selectionList]); @@ -132,92 +60,55 @@ const EmployeeProfileSection: React.FC = ({ const handleSelectCompany = (company: any) => { loginSelectEmployee({ company_uu_id: company.uu_id }) .then((responseData: any) => { - if (responseData?.status === 200 || responseData?.status === 202) { - // Refresh the page to update the selection - window.location.reload(); - } - }) - .catch((error) => { - console.error("Error selecting company:", error); - }); + if (responseData?.status === 200 || responseData?.status === 202) { window.location.reload(); } + }).catch((error) => { console.error("Error selecting company:", error) }); }; if (!userSelection) { return
{t.loading}
; + } else { + return ( +
+
hasMultipleOptions && setShowSelectionList(!showSelectionList)} + > +
+
+ +
+
+

+ {userSelection.public_name} {userSelection.company_type} +

+

{userSelection.duty}

+
+
+
+ + {/* Selection dropdown */} + {showSelectionList && hasMultipleOptions && ( +
+
+

{t.selectCompany}

+
+
+ {loading ?
{t.loading}
: availableCompanies.length > 0 ? availableCompanies.map((company, index) => ( +
handleSelectCompany(company)}> +
{company.public_name}
+ {company.company_type &&
{company.company_type}
} + {company.duty &&
{t.duty}: {company.duty}
} +
+ )) : ( +
{t.noCompanies}
+ )} +
+
+ )} +
+ ); } - return ( -
- {/*
-
- -
-
-

{t.userType}

-

{t.employee}

-
-
*/} - -
- hasMultipleOptions && setShowSelectionList(!showSelectionList) - } - > -
-
- -
-
-

- {userSelection.public_name} {userSelection.company_type} -

-

{userSelection.duty}

-
-
-
- - {/* Selection dropdown */} - {showSelectionList && hasMultipleOptions && ( -
-
-

{t.selectCompany}

-
-
- {loading ? ( -
{t.loading}
- ) : availableCompanies.length > 0 ? ( - availableCompanies.map((company, index) => ( -
handleSelectCompany(company)} - > -
{company.public_name}
- {company.company_type && ( -
- {company.company_type} -
- )} - {company.duty && ( -
- {t.duty}: {company.duty} -
- )} -
- )) - ) : ( -
- {t.noCompanies} -
- )} -
-
- )} -
- ); }; export default EmployeeProfileSection; diff --git a/WebServices/management-frontend/src/components/menu/NavigationMenu.tsx b/WebServices/management-frontend/src/components/menu/NavigationMenu.tsx index d11353b..ee372f7 100644 --- a/WebServices/management-frontend/src/components/menu/NavigationMenu.tsx +++ b/WebServices/management-frontend/src/components/menu/NavigationMenu.tsx @@ -3,24 +3,13 @@ import Link from "next/link"; import React, { JSX } from "react"; import { getNavigationMenu } from "./type"; -function NavigationMenu({ - lang, - activePage, -}: { - lang: "en" | "tr"; - activePage: string; -}) { - +const NavigationMenu: React.FC<{ lang: "en" | "tr"; activePage: string; }> = ({ lang, activePage }) => { const navItems = getNavigationMenu(lang); - function createLinkComponent(url: string, title: string): JSX.Element { return ( - - {title} + {title} ); } diff --git a/WebServices/management-frontend/src/components/menu/OccupantProfileSection.tsx b/WebServices/management-frontend/src/components/menu/OccupantProfileSection.tsx index 5aaa973..fb81a06 100644 --- a/WebServices/management-frontend/src/components/menu/OccupantProfileSection.tsx +++ b/WebServices/management-frontend/src/components/menu/OccupantProfileSection.tsx @@ -1,192 +1,71 @@ "use client"; import React, { useState, useEffect } from "react"; -import { User, Building, Home, ChevronDown } from "lucide-react"; +import { Building, Home, ChevronDown } from "lucide-react"; import { retrieveAccessObjects } from "@/apicalls/cookies/token"; import { loginSelectOccupant } from "@/apicalls/login/login"; -import { useRouter } from "next/navigation"; - -// Language definitions for occupant profile section -const profileLanguage = { - tr: { - userType: "Kullanıcı Tipi", - occupant: "Sakin", - building: "Bina", - apartment: "Daire", - loading: "Yükleniyor...", - changeSelection: "Seçimi Değiştir", - selectOccupant: "Daire Seçin", - noOccupants: "Kullanılabilir daire bulunamadı", - }, - en: { - userType: "User Type", - occupant: "Occupant", - building: "Building", - apartment: "Apartment", - loading: "Loading...", - changeSelection: "Change Selection", - selectOccupant: "Select Apartment", - noOccupants: "No apartments available", - }, -}; - -// { -// "userType": "occupant", -// "selectionList": { -// "3fe72194-dad6-4ddc-8679-70acdbe7f619": { -// "build_uu_id": "3fe72194-dad6-4ddc-8679-70acdbe7f619", -// "build_name": "Build Example", -// "build_no": "B001", -// "occupants": [ -// { -// "build_living_space_uu_id": "b67e5a37-ac04-45ab-8bca-5a3427358015", -// "part_uu_id": "441ef61b-1cc5-465b-90b2-4835d0e16540", -// "part_name": "APARTMAN DAIRESI : 1", -// "part_level": 1, -// "occupant_uu_id": "6bde6bf9-0d13-4b6f-a612-28878cd7324f", -// "description": "Daire Kiracısı", -// "code": "FL-TEN" -// } -// ] -// } -// } -// } - -// Define interfaces for occupant data structures based on the access object structure -interface OccupantDetails { - build_living_space_uu_id: string; - part_uu_id: string; - part_name: string; - part_level: number; - occupant_uu_id: string; - description: string; - code: string; - [key: string]: any; // Allow other properties -} - -interface BuildingInfo { - build_uu_id: string; - build_name: string; - build_no: string; - occupants: OccupantDetails[]; - [key: string]: any; // Allow other properties -} - -interface OccupantSelectionList { - userType: string; - selectionList: { - [key: string]: BuildingInfo; - }; -} - -// Interface for the selected occupant data -interface OccupantInfo { - buildName?: string; - buildNo?: string; - occupantName?: string; - description?: string; - code?: string; - part_name?: string; - build_living_space_uu_id?: string; - [key: string]: any; // Allow other properties -} - -interface UserSelection { - userType: string; - selected: OccupantInfo; -} - -interface OccupantProfileSectionProps { - userSelectionData: UserSelection; - lang?: "en" | "tr"; -} +import { OccupantProfileLanguage } from "./language"; +import { OccupantSelectionList, BuildingInfo, OccupantInfo, OccupantDetails, OccupantProfileSectionProps } from "./type"; const OccupantProfileSection: React.FC = ({ userSelectionData, lang = "en", }) => { - const t = - profileLanguage[lang as keyof typeof profileLanguage] || profileLanguage.en; - const router = useRouter(); - const [showSelectionList, setShowSelectionList] = useState(false); - const [loading, setLoading] = useState(true); - // Initialize state with data from props - const [userSelection, setUserSelection] = useState( - userSelectionData?.selected || null - ); - const [selectionList, setSelectionList] = - useState(null); - const [availableOccupants, setAvailableOccupants] = useState([]); + const [userSelection, setUserSelection] = useState(userSelectionData?.selected || null); + const [selectionList, setSelectionList] = useState(null); const [hasMultipleOptions, setHasMultipleOptions] = useState(false); - const [selectedBuildingKey, setSelectedBuildingKey] = useState( - null - ); - const [buildings, setBuildings] = useState<{ [key: string]: BuildingInfo }>( - {} - ); + const [selectedBuildingKey, setSelectedBuildingKey] = useState(null); + const [buildings, setBuildings] = useState<{ [key: string]: BuildingInfo }>({}); + const [loading, setLoading] = useState(true); + const [availableOccupants, setAvailableOccupants] = useState([]); + + const t = handleProfileChange(OccupantProfileLanguage, lang); + function handleProfileChange(languages: any, lang: string) { + return languages[lang as keyof typeof languages] || languages.en; + } - // Fetch access objects for selection list when needed useEffect(() => { if (showSelectionList && !selectionList) { setLoading(true); - retrieveAccessObjects() - .then((accessObjectsData) => { - console.log("Access Objects:", accessObjectsData); + retrieveAccessObjects().then((accessObjectsData) => { + if (accessObjectsData && accessObjectsData.selectionList) { + const data = accessObjectsData as OccupantSelectionList; + setSelectionList(data); + setBuildings(data.selectionList); - if (accessObjectsData && accessObjectsData.selectionList) { - const data = accessObjectsData as OccupantSelectionList; - setSelectionList(data); - setBuildings(data.selectionList); + const buildingKeys = Object.keys(data.selectionList); + let totalOccupants = 0; + let currentBuildingKey = null; + let currentOccupantId = null; - // Check if there are multiple buildings or multiple occupants across all buildings - const buildingKeys = Object.keys(data.selectionList); - let totalOccupants = 0; - let currentBuildingKey = null; - let currentOccupantId = null; + buildingKeys.forEach((key) => { + const building = data.selectionList[key]; + if (building.occupants && building.occupants.length > 0) { + totalOccupants += building.occupants.length; - // Count total occupants and find current building/occupant - buildingKeys.forEach((key) => { - const building = data.selectionList[key]; - if (building.occupants && building.occupants.length > 0) { - totalOccupants += building.occupants.length; - - // Try to find the current user's building and occupant - if (userSelection) { - building.occupants.forEach((occupant) => { - if ( - occupant.build_living_space_uu_id === - userSelection.build_living_space_uu_id - ) { - currentBuildingKey = key; - currentOccupantId = occupant.build_living_space_uu_id; - } - }); - } + if (userSelection) { + building.occupants.forEach((occupant) => { + if (occupant.build_living_space_uu_id === userSelection.build_living_space_uu_id) { + currentBuildingKey = key; + currentOccupantId = occupant.build_living_space_uu_id; + } + }); } - }); - - // Set whether there are multiple options - setHasMultipleOptions(totalOccupants > 1); - - // If we found the current building, set it as selected - if (currentBuildingKey) { - setSelectedBuildingKey(currentBuildingKey); } - } - }) - .catch((err) => { - console.error("Error fetching access objects:", err); - }) + }); + setHasMultipleOptions(totalOccupants > 1); + if (currentBuildingKey) { setSelectedBuildingKey(currentBuildingKey) } + } + }) + .catch((err) => { console.error("Error fetching access objects:", err) }) .finally(() => setLoading(false)); } }, [showSelectionList, userSelection]); - // Update user selection when props change useEffect(() => { if (userSelectionData?.selected) { setUserSelection(userSelectionData.selected as OccupantInfo); - // Check if we need to fetch selection list to determine if multiple options exist if (!selectionList) { retrieveAccessObjects() .then((accessObjectsData) => { @@ -195,7 +74,6 @@ const OccupantProfileSection: React.FC = ({ setSelectionList(data); setBuildings(data.selectionList); - // Count total occupants across all buildings let totalOccupants = 0; let currentBuildingKey = null; @@ -203,13 +81,8 @@ const OccupantProfileSection: React.FC = ({ const building = data.selectionList[key]; if (building.occupants && building.occupants.length > 0) { totalOccupants += building.occupants.length; - - // Try to find the current user's building building.occupants.forEach((occupant) => { - if ( - userSelectionData.selected.build_living_space_uu_id === - occupant.build_living_space_uu_id - ) { + if (userSelectionData.selected.build_living_space_uu_id === occupant.build_living_space_uu_id) { currentBuildingKey = key; } }); @@ -217,25 +90,18 @@ const OccupantProfileSection: React.FC = ({ }); setHasMultipleOptions(totalOccupants > 1); - if (currentBuildingKey) { - setSelectedBuildingKey(currentBuildingKey); - } + if (currentBuildingKey) { setSelectedBuildingKey(currentBuildingKey) } } }) - .catch((err) => { - console.error("Error fetching access objects:", err); - }); + .catch((err) => { console.error("Error fetching access objects:", err) }); } } }, [userSelectionData, selectionList]); - // Helper function to process occupant data const processOccupantData = (data: OccupantSelectionList) => { if (!data.selectionList) return; - const occupantList: any[] = []; - // Process the building/occupant structure Object.keys(data.selectionList).forEach((buildKey) => { const building = data.selectionList[buildKey]; if (building.occupants && building.occupants.length > 0) { @@ -253,7 +119,6 @@ const OccupantProfileSection: React.FC = ({ setAvailableOccupants(occupantList); }; - // Process occupant data when selection menu is opened or when selectionList changes useEffect(() => { if (showSelectionList && selectionList && selectionList.selectionList) { setLoading(true); @@ -263,18 +128,9 @@ const OccupantProfileSection: React.FC = ({ }, [showSelectionList, selectionList]); const handleSelectOccupant = (occupant: any) => { - loginSelectOccupant({ - build_living_space_uu_id: occupant.build_living_space_uu_id, - }) - .then((responseData: any) => { - if (responseData?.status === 200 || responseData?.status === 202) { - // Refresh the page to update the selection - window.location.reload(); - } - }) - .catch((error) => { - console.error("Error selecting occupant:", error); - }); + loginSelectOccupant({ build_living_space_uu_id: occupant.build_living_space_uu_id }) + .then((responseData: any) => { if (responseData?.status === 200 || responseData?.status === 202) { window.location.reload() } }) + .catch((error) => { console.error("Error selecting occupant:", error) }); }; if (!userSelection) { @@ -283,16 +139,6 @@ const OccupantProfileSection: React.FC = ({ return (
- {/*
-
- -
-
-

{t.userType}

-

{t.occupant}

-
-
*/} - {userSelection?.buildName && (
@@ -307,12 +153,8 @@ const OccupantProfileSection: React.FC = ({ {userSelection?.part_name && (
- hasMultipleOptions && setShowSelectionList(!showSelectionList) - } + className={`flex items-center justify-between space-x-3 p-2 ${hasMultipleOptions ? "hover:bg-gray-100 cursor-pointer" : ""} rounded-lg transition-colors`} + onClick={() => hasMultipleOptions && setShowSelectionList(!showSelectionList)} >
@@ -321,18 +163,10 @@ const OccupantProfileSection: React.FC = ({

{t.apartment}

{userSelection.part_name}

- {userSelection.description && ( -

- {userSelection.description} -

- )} + {userSelection.description &&

{userSelection.description}

}
- {hasMultipleOptions && ( -
- {t.changeSelection} -
- )} + {hasMultipleOptions &&
{t.changeSelection}
}
)} @@ -347,7 +181,6 @@ const OccupantProfileSection: React.FC = ({
{t.loading}
) : buildings && Object.keys(buildings).length > 0 ? ( selectedBuildingKey ? ( - // Second layer: Occupants in the selected building
@@ -357,67 +190,42 @@ const OccupantProfileSection: React.FC = ({ className="text-xs text-blue-600" onClick={() => setSelectedBuildingKey(null)} > - Back to buildings + {t.backToBuildings}
{buildings[selectedBuildingKey].occupants.length > 0 ? ( buildings[selectedBuildingKey].occupants.map( (occupant, index) => { - // Skip the currently selected occupant - if ( - userSelection && - occupant.build_living_space_uu_id === - userSelection.build_living_space_uu_id - ) { - return null; - } - + if (userSelection && occupant.build_living_space_uu_id === userSelection.build_living_space_uu_id) { return null } return (
handleSelectOccupant(occupant)} > -
- {occupant.description || "Apartment"} -
-
- {occupant.part_name} -
- {occupant.code && ( -
- {t.apartment} {occupant.code} -
- )} +
{occupant.description || "Apartment"}
+
{occupant.part_name}
+ {occupant.code &&
{t.apartment} {occupant.code}
}
); } ) ) : ( -
- {t.noOccupants} -
+
{t.noOccupants}
)}
) : ( - // First layer: Buildings list Object.keys(buildings).map((buildingKey, index) => { const building = buildings[buildingKey]; - // Skip buildings with no occupants or only the current occupant if (!building.occupants || building.occupants.length === 0) { return null; } - // Check if this building has any occupants other than the current one if (userSelection) { const hasOtherOccupants = building.occupants.some( - (occupant) => - occupant.build_living_space_uu_id !== - userSelection.build_living_space_uu_id + (occupant) => occupant.build_living_space_uu_id !== userSelection.build_living_space_uu_id ); - if (!hasOtherOccupants) { - return null; - } + if (!hasOtherOccupants) { return null } } return ( @@ -427,23 +235,17 @@ const OccupantProfileSection: React.FC = ({ onClick={() => setSelectedBuildingKey(buildingKey)} >
{building.build_name}
-
- No: {building.build_no} -
+
{t.buildNo}: {building.build_no}
{building.occupants.length}{" "} - {building.occupants.length === 1 - ? t.apartment.toLowerCase() - : t.apartment.toLowerCase() + "s"} + {building.occupants.length === 1 ? t.apartment.toLowerCase() : t.apartment.toLowerCase() + "s"}
); }) ) ) : ( -
- {t.noOccupants} -
+
{t.noOccupants}
)}
diff --git a/WebServices/management-frontend/src/components/menu/ProfileLoadingState.tsx b/WebServices/management-frontend/src/components/menu/ProfileLoadingState.tsx index b5f2b63..db2f85e 100644 --- a/WebServices/management-frontend/src/components/menu/ProfileLoadingState.tsx +++ b/WebServices/management-frontend/src/components/menu/ProfileLoadingState.tsx @@ -1,9 +1,6 @@ "use client"; import React from "react"; - -interface ProfileLoadingStateProps { - loadingText: string; -} +import { ProfileLoadingStateProps } from "./type"; const ProfileLoadingState: React.FC = ({ loadingText }) => { return ( diff --git a/WebServices/management-frontend/src/components/menu/language.ts b/WebServices/management-frontend/src/components/menu/language.ts new file mode 100644 index 0000000..02f190c --- /dev/null +++ b/WebServices/management-frontend/src/components/menu/language.ts @@ -0,0 +1,92 @@ +export const dashboardLanguage = { + tr: { + dashboard: "Kontrol Paneli", + loading: "Yükleniyor...", + }, + en: { + dashboard: "Control Panel", + loading: "Loading...", + }, +}; +export const NavigationLanguage = { + en: { + "/dashboard": "Dashboard", + "/append/event": "Event Board", + "/append/service": "Service Board", + "/application": "Application Board", + }, + tr: { + "/dashboard": "Kontrol Paneli", + "/append/event": "Event Paneli", + "/append/service": "Servis Paneli", + "/application": "Uygulama Paneli", + }, +}; +export const EmployeeProfileLanguage = { + tr: { + userType: "Kullanıcı Tipi", + employee: "Çalışan", + loading: "Yükleniyor...", + changeSelection: "Seçimi Değiştir", + selectCompany: "Şirket Seçin", + noCompanies: "Kullanılabilir şirket bulunamadı", + duty: "Görev", + }, + en: { + userType: "User Type", + employee: "Employee", + loading: "Loading...", + changeSelection: "Change Selection", + selectCompany: "Select Company", + noCompanies: "No companies available", + duty: "Duty", + }, +}; +export const OccupantProfileLanguage = { + tr: { + userType: "Kullanıcı Tipi", + occupant: "Sakin", + building: "Bina", + apartment: "Daire", + loading: "Yükleniyor...", + changeSelection: "Seçimi Değiştir", + selectOccupant: "Daire Seçin", + noOccupants: "Kullanılabilir daire bulunamadı", + backToBuildings: "Binalara Geri Dön", + buildNo: "Bina No", + }, + en: { + userType: "User Type", + occupant: "Occupant", + building: "Building", + apartment: "Apartment", + loading: "Loading...", + changeSelection: "Change Selection", + selectOccupant: "Select Apartment", + noOccupants: "No apartments available", + backToBuildings: "Back to buildings", + buildNo: "Build No", + }, +}; + +// { +// "userType": "occupant", +// "selectionList": { +// "3fe72194-dad6-4ddc-8679-70acdbe7f619": { +// "build_uu_id": "3fe72194-dad6-4ddc-8679-70acdbe7f619", +// "build_name": "Build Example", +// "build_no": "B001", +// "occupants": [ +// { +// "build_living_space_uu_id": "b67e5a37-ac04-45ab-8bca-5a3427358015", +// "part_uu_id": "441ef61b-1cc5-465b-90b2-4835d0e16540", +// "part_name": "APARTMAN DAIRESI : 1", +// "part_level": 1, +// "occupant_uu_id": "6bde6bf9-0d13-4b6f-a612-28878cd7324f", +// "description": "Daire Kiracısı", +// "code": "FL-TEN" +// } +// ] +// } +// } +// } diff --git a/WebServices/management-frontend/src/components/menu/menu.tsx b/WebServices/management-frontend/src/components/menu/menu.tsx index 1a3e5f8..ae87b7c 100644 --- a/WebServices/management-frontend/src/components/menu/menu.tsx +++ b/WebServices/management-frontend/src/components/menu/menu.tsx @@ -1,31 +1,15 @@ "use client"; - import React, { useEffect, useState, Suspense, JSX } from "react"; import { retrieveUserSelection } from "@/apicalls/cookies/token"; +import { ClientMenuProps, UserSelection } from "@/validations/menu/menu"; +import { dashboardLanguage } from "./language"; import EmployeeProfileSection from "./EmployeeProfileSection"; import OccupantProfileSection from "./OccupantProfileSection"; import ProfileLoadingState from "./ProfileLoadingState"; -import { - ClientMenuProps, - UserSelection, -} from "@/validations/menu/menu"; import NavigationMenu from "./NavigationMenu"; -// Language definitions for dashboard title -const dashboardLanguage = { - tr: { - dashboard: "Kontrol Paneli", - loading: "Yükleniyor...", - }, - en: { - dashboard: "Control Panel", - loading: "Loading...", - }, -}; - const ClientMenu: React.FC = ({ lang, activePage }) => { const t = dashboardLanguage[lang as keyof typeof dashboardLanguage] || dashboardLanguage.en; - const [loading, setLoading] = useState(true); const [userType, setUserType] = useState(null); const [userSelectionData, setUserSelectionData] = useState(null); @@ -65,15 +49,10 @@ const ClientMenu: React.FC = ({ lang, activePage }) => { return (
-

- {t.dashboard} -

+

{t.dashboard}

-
- {t.loading}
} - > + {t.loading}
}> {createProfileComponent()}
diff --git a/WebServices/management-frontend/src/components/menu/store.tsx b/WebServices/management-frontend/src/components/menu/store.tsx deleted file mode 100644 index c04419f..0000000 --- a/WebServices/management-frontend/src/components/menu/store.tsx +++ /dev/null @@ -1,255 +0,0 @@ -const Individual = { - name: "Individual", - lg: { - tr: "Birey", - en: "Individual", - }, - siteUrl: "/individual", -}; - -const User = { - name: "User", - lg: { - tr: "Kullanıcı", - en: "User", - }, - siteUrl: "/user", -}; - -const Build = { - name: "Build", - lg: { - tr: "Apartman", - en: "Build", - }, - siteUrl: "/build", -}; - -const Dashboard = { - name: "Dashboard", - lg: { - tr: "Pano", - en: "Dashboard", - }, - siteUrl: "/dashboard", -}; - -const BuildParts = { - name: "BuildParts", - lg: { - tr: "Daireler", - en: "Build Parts", - }, - siteUrl: "/build/parts", -}; - -const BuildArea = { - name: "BuildArea", - lg: { - tr: "Daire Alanları", - en: "Build Area", - }, - siteUrl: "/build/area", -}; - -const ManagementAccounting = { - name: "ManagementAccounting", - lg: { - tr: "Yönetim Cari Hareketler", - en: "ManagementAccounting", - }, - siteUrl: "/management/accounting", -}; - -const ManagementBudget = { - name: "ManagementBudget", - lg: { - tr: "Yönetim Bütçe İşlemleri", - en: "Management Budget", - }, - siteUrl: "/management/budget", -}; - -const BuildPartsAccounting = { - name: "BuildPartsAccounting", - lg: { - tr: "Daire Cari Hareketler", - en: "Build Parts Accounting", - }, - siteUrl: "/build/parts/accounting", -}; - -const AnnualMeeting = { - name: "AnnualMeeting", - lg: { - tr: "Yıllık Olağan Toplantı Tanımlama ve Davet", - en: "Annual Meetings and Invitations", - }, - siteUrl: "/annual/meeting", -}; - -const AnnualMeetingClose = { - name: "AnnualMeetingClose", - lg: { - tr: "Yıllık Olağan Toplantı kapatma ve Cari Yaratma", - en: "Annual Meeting Close and Accountings", - }, - siteUrl: "/annual/meeting/close", -}; - -const EmergencyMeeting = { - name: "EmergencyMeeting", - lg: { - tr: "Acil Toplantı Tanımlama ve Davet", - en: "Emergency Meeting and Invitations", - }, - siteUrl: "/emergency/meeting", -}; - -const EmergencyMeetingClose = { - name: "EmergencyMeetingClose", - lg: { - tr: "Acil Olağan Toplantı kapatma ve Cari Yaratma", - en: "Emergency Meeting Close and Accountings", - }, - siteUrl: "/emergency/meeting/close", -}; - -const MeetingParticipations = { - name: "MeetingParticipations", - lg: { - tr: "Toplantı Katılım İşlemleri", - en: "Meeting Participations", - }, - siteUrl: "/meeting/participation", -}; - -const TenantSendMessageToBuildManager = { - name: "TenantSendMessageToBuildManager", - lg: { - tr: "Bina Yöneticisine Mesaj Gönder", - en: "Send Message to Build Manager", - }, - siteUrl: "/tenant/messageToBM", -}; - -const TenantSendMessageToOwner = { - name: "TenantSendMessageToOwner", - lg: { - tr: "Sahibine Mesaj Gönder", - en: "Send Message to Owner", - }, - siteUrl: "/tenant/messageToOwner", -}; - -const TenantAccountView = { - name: "TenantAccountView", - lg: { - tr: "Kiracı Cari Hareketleri", - en: "Tenant Accountings", - }, - siteUrl: "/tenant/accounting", -}; - -const Menu = [ - { - name: "Dashboard", - lg: { - tr: "Pano", - en: "Dashboard", - }, - subList: [ - { - name: "Dashboard", - lg: { - tr: "Pano", - en: "Dashboard", - }, - subList: [Dashboard], - }, - ], - }, - { - name: "Definitions", - lg: { - tr: "Tanımlar", - en: "Definitions", - }, - subList: [ - { - name: "People", - lg: { - tr: "Kişiler", - en: "People", - }, - subList: [Individual, User], - }, - { - name: "Building", - lg: { - tr: "Binalar", - en: "Building", - }, - subList: [Build, BuildParts, BuildArea], - }, - ], - }, - { - name: "Building Management", - lg: { - tr: "Bina Yönetimi", - en: "Building Management", - }, - subList: [ - { - name: "Management Accounting", - lg: { - tr: "Cari işlemler", - en: "Management Accounting", - }, - subList: [ManagementAccounting, ManagementBudget, BuildPartsAccounting], - }, - { - name: "Meetings", - lg: { - tr: "Toplantılar", - en: "Meetings", - }, - subList: [ - AnnualMeeting, - AnnualMeetingClose, - EmergencyMeeting, - EmergencyMeetingClose, - MeetingParticipations, - ], - }, - ], - }, - { - name: "Tenants", - lg: { - tr: "Kiracı İşlemleri", - en: "Tenant Actions", - }, - subList: [ - { - name: "Accountings", - lg: { - tr: "Kiracı Cari Hareketler", - en: "Tenant Accountings", - }, - subList: [TenantAccountView], - }, - { - name: "Messages", - lg: { - tr: "Mesaj Gönder", - en: "Send Messages", - }, - subList: [TenantSendMessageToBuildManager, TenantSendMessageToOwner], - }, - ], - }, -]; - -export default Menu; diff --git a/WebServices/management-frontend/src/components/menu/type.ts b/WebServices/management-frontend/src/components/menu/type.ts index 392949d..a2c4b30 100644 --- a/WebServices/management-frontend/src/components/menu/type.ts +++ b/WebServices/management-frontend/src/components/menu/type.ts @@ -1,21 +1,75 @@ -export const NavigationLanguage = { - en: { - "/dashboard": "Dashboard", - "/append/event": "Event Board", - "/append/service": "Service Board", - "/application": "Application Board", - }, - tr: { - "/dashboard": "Kontrol Paneli", - "/append/event": "Event Paneli", - "/append/service": "Servis Paneli", - "/application": "Uygulama Paneli", - }, -}; +import { NavigationLanguage } from "./language"; + +export interface ProfileLoadingStateProps { + loadingText: string; +} + +export interface CompanyInfo { + uu_id: string; + public_name: string; + company_type: string; + company_address: string | null; + duty: string; +} + +export interface UserSelection { + userType: string; + selected: CompanyInfo; +} + +export interface EmployeeProfileSectionProps { + userSelectionData: UserSelection; + lang?: "en" | "tr"; +} + +export interface OccupantDetails { + build_living_space_uu_id: string; + part_uu_id: string; + part_name: string; + part_level: number; + occupant_uu_id: string; + description: string; + code: string; + [key: string]: any; +} + +export interface BuildingInfo { + build_uu_id: string; + build_name: string; + build_no: string; + occupants: OccupantDetails[]; + [key: string]: any; +} + +export interface OccupantSelectionList { + userType: string; + selectionList: { + [key: string]: BuildingInfo; + }; +} + +export interface OccupantInfo { + buildName?: string; + buildNo?: string; + occupantName?: string; + description?: string; + code?: string; + part_name?: string; + build_living_space_uu_id?: string; + [key: string]: any; +} + +export interface OccupantUserSelection { + userType: string; + selected: OccupantInfo; +} + +export interface OccupantProfileSectionProps { + userSelectionData: OccupantUserSelection; + lang?: "en" | "tr"; +} export function getNavigationMenu(lang: string) { - return ( - NavigationLanguage[lang as keyof typeof NavigationLanguage] || - NavigationLanguage.en - ); + const language = lang as keyof typeof NavigationLanguage; + return NavigationLanguage[language] || NavigationLanguage.en; }