From 01f3e82a54679bb657f9ddd6fb5b4c1c5453426c Mon Sep 17 00:00:00 2001 From: Berkay Date: Sat, 3 May 2025 23:35:03 +0300 Subject: [PATCH] updated service binders updated --- .../DealerService/init_service_to_events.py | 15 + .../Endpoints/service_endpoints/route.py | 1 + .../Events/application/supers_events.py | 2 +- .../Events/service_endpoints/supers_events.py | 28 +- Controllers/Postgres/response.py | 16 +- Schemas/event/event.py | 4 + .../ActionButtonsDisplay/CreateButton.tsx | 25 -- .../CustomButtonComponent.tsx | 31 -- .../common/ActionButtonsDisplay/index.ts | 3 - .../common/ActionButtonsDisplay/types.ts | 17 - .../common/CardDisplay/CardDisplay.tsx | 71 --- .../common/CardDisplay/CardItem.tsx | 130 ------ .../common/CardDisplay/CardSkeleton.tsx | 46 -- .../components/common/CardDisplay/index.tsx | 1 - .../components/common/CardDisplay/schema.ts | 117 ----- .../components/common/CardDisplay/utils.ts | 46 -- .../common/FormDisplay/CreateComponent.tsx | 303 ------------- .../common/FormDisplay/FormDisplay.tsx | 146 ------- .../common/FormDisplay/UpdateComponent.tsx | 411 ------------------ .../common/FormDisplay/ViewComponent.tsx | 251 ----------- .../components/common/FormDisplay/index.ts | 5 - .../components/common/FormDisplay/types.ts | 52 --- .../GridSelectionComponent.tsx | 42 -- .../LanguageSelectionComponent.tsx | 29 -- .../PaginationModifiers/PageNavigation.tsx | 116 ----- .../PaginationModifiers/PageSizeSelector.tsx | 52 --- .../PaginationModifiers/PaginationStats.tsx | 36 -- .../PaginationToolsComponent.tsx | 43 -- .../common/PaginationModifiers/index.ts | 5 - .../common/PaginationModifiers/types.ts | 19 - .../QueryModifiers/SelectQueryModifier.tsx | 67 --- .../QueryModifiers/TextQueryModifier.tsx | 80 ---- .../QueryModifiers/TypeQueryModifier.tsx | 51 --- .../components/common/QueryModifiers/index.ts | 4 - .../components/common/QueryModifiers/types.ts | 35 -- .../src/components/common/ReadMe.md | 128 ------ .../Screenshot from 2025-04-29 19-36-45.png | Bin 68479 -> 0 bytes .../SortingComponent/SortingComponent.tsx | 49 --- .../common/SortingComponent/index.ts | 2 - .../common/SortingComponent/types.ts | 13 - .../src/components/common/hooks/useApiData.ts | 70 --- .../common/hooks/useDashboardPage.ts | 62 --- .../common/hooks/useDataFetching.ts | 178 -------- .../common/hooks/useStandardApiFetch.ts | 181 -------- .../src/components/common/index.ts | 26 -- .../src/components/common/schemas.ts | 45 -- .../src/apicalls/api-fetcher.ts | 2 +- .../{application.tsx => endpoints.tsx} | 2 +- .../cookies/{token.tsx => endpoints.tsx} | 26 +- .../login/{login.tsx => endpoints.tsx} | 2 +- .../src/apicalls/services/endpoints.tsx | 84 ++++ .../src/app/(AuthLayout)/auth/select/page.tsx | 2 +- .../src/app/(DashboardLayout)/layout.tsx | 2 +- .../src/app/api/appenders/list/route.ts | 4 + .../src/app/api/applications/create/route.ts | 2 +- .../src/app/api/applications/list/route.ts | 2 +- .../src/app/api/applications/update/route.ts | 2 +- .../src/app/api/events/list/route.ts | 4 + .../src/app/api/services/list/route.ts | 4 + .../src/components/auth/LoginEmployee.tsx | 2 +- .../src/components/auth/LoginOccupant.tsx | 6 +- .../src/components/auth/login.tsx | 6 +- .../src/components/auth/select.tsx | 20 +- .../common/CardDisplay/CardDisplay.tsx | 11 +- .../common/CardDisplay/CardItem.tsx | 6 +- .../components/common/CardDisplay/schema.ts | 132 ++---- .../components/common/CardDisplay/utils.ts | 29 +- .../common/FormDisplay/FormDisplay.tsx | 9 +- .../common/FormDisplay/ViewComponent.tsx | 162 +++---- .../src/components/common/hooks/useApiData.ts | 5 - .../src/components/header/Header.tsx | 2 +- .../menu/EmployeeProfileSection.tsx | 4 +- .../menu/OccupantProfileSection.tsx | 4 +- .../src/components/menu/menu.tsx | 2 +- .../eventRouters/appendersService/language.ts | 11 +- .../appendersService/listComponent.tsx | 91 +++- .../eventRouters/appendersService/page.tsx | 54 ++- .../appendersService/schemaList/schema.ts | 13 - .../appendersService/schemaList/services.ts | 298 +++++++++++++ .../src/eventRouters/appendersService/type.ts | 21 +- .../src/eventRouters/application/schema.ts | 23 - .../src/eventRouters/schemas/zodSchemas.ts | 3 - 82 files changed, 735 insertions(+), 3371 deletions(-) delete mode 100644 WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CreateButton.tsx delete mode 100644 WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CustomButtonComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/ActionButtonsDisplay/index.ts delete mode 100644 WebServices/client-frontend/src/components/common/ActionButtonsDisplay/types.ts delete mode 100644 WebServices/client-frontend/src/components/common/CardDisplay/CardDisplay.tsx delete mode 100644 WebServices/client-frontend/src/components/common/CardDisplay/CardItem.tsx delete mode 100644 WebServices/client-frontend/src/components/common/CardDisplay/CardSkeleton.tsx delete mode 100644 WebServices/client-frontend/src/components/common/CardDisplay/index.tsx delete mode 100644 WebServices/client-frontend/src/components/common/CardDisplay/schema.ts delete mode 100644 WebServices/client-frontend/src/components/common/CardDisplay/utils.ts delete mode 100644 WebServices/client-frontend/src/components/common/FormDisplay/CreateComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/FormDisplay/FormDisplay.tsx delete mode 100644 WebServices/client-frontend/src/components/common/FormDisplay/UpdateComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/FormDisplay/ViewComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/FormDisplay/index.ts delete mode 100644 WebServices/client-frontend/src/components/common/FormDisplay/types.ts delete mode 100644 WebServices/client-frontend/src/components/common/HeaderSelections/GridSelectionComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/HeaderSelections/LanguageSelectionComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/PaginationModifiers/PageNavigation.tsx delete mode 100644 WebServices/client-frontend/src/components/common/PaginationModifiers/PageSizeSelector.tsx delete mode 100644 WebServices/client-frontend/src/components/common/PaginationModifiers/PaginationStats.tsx delete mode 100644 WebServices/client-frontend/src/components/common/PaginationModifiers/PaginationToolsComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/PaginationModifiers/index.ts delete mode 100644 WebServices/client-frontend/src/components/common/PaginationModifiers/types.ts delete mode 100644 WebServices/client-frontend/src/components/common/QueryModifiers/SelectQueryModifier.tsx delete mode 100644 WebServices/client-frontend/src/components/common/QueryModifiers/TextQueryModifier.tsx delete mode 100644 WebServices/client-frontend/src/components/common/QueryModifiers/TypeQueryModifier.tsx delete mode 100644 WebServices/client-frontend/src/components/common/QueryModifiers/index.ts delete mode 100644 WebServices/client-frontend/src/components/common/QueryModifiers/types.ts delete mode 100644 WebServices/client-frontend/src/components/common/ReadMe.md delete mode 100644 WebServices/client-frontend/src/components/common/Screenshot from 2025-04-29 19-36-45.png delete mode 100644 WebServices/client-frontend/src/components/common/SortingComponent/SortingComponent.tsx delete mode 100644 WebServices/client-frontend/src/components/common/SortingComponent/index.ts delete mode 100644 WebServices/client-frontend/src/components/common/SortingComponent/types.ts delete mode 100644 WebServices/client-frontend/src/components/common/hooks/useApiData.ts delete mode 100644 WebServices/client-frontend/src/components/common/hooks/useDashboardPage.ts delete mode 100644 WebServices/client-frontend/src/components/common/hooks/useDataFetching.ts delete mode 100644 WebServices/client-frontend/src/components/common/hooks/useStandardApiFetch.ts delete mode 100644 WebServices/client-frontend/src/components/common/index.ts delete mode 100644 WebServices/client-frontend/src/components/common/schemas.ts rename WebServices/management-frontend/src/apicalls/application/{application.tsx => endpoints.tsx} (99%) rename WebServices/management-frontend/src/apicalls/cookies/{token.tsx => endpoints.tsx} (83%) rename WebServices/management-frontend/src/apicalls/login/{login.tsx => endpoints.tsx} (99%) create mode 100644 WebServices/management-frontend/src/apicalls/services/endpoints.tsx create mode 100644 WebServices/management-frontend/src/app/api/appenders/list/route.ts create mode 100644 WebServices/management-frontend/src/app/api/events/list/route.ts create mode 100644 WebServices/management-frontend/src/app/api/services/list/route.ts create mode 100644 WebServices/management-frontend/src/eventRouters/appendersService/schemaList/services.ts diff --git a/ApiServices/DealerService/init_service_to_events.py b/ApiServices/DealerService/init_service_to_events.py index e38353a..e0487bd 100644 --- a/ApiServices/DealerService/init_service_to_events.py +++ b/ApiServices/DealerService/init_service_to_events.py @@ -17,7 +17,21 @@ def init_service_to_event_matches_for_super_user(super_user, db_session=None) -> db=db_session, ).data list_of_all_events = Events.filter_all(db=db_session).data + Service2Events.filter_all(db=db_session).query.delete() + Service2Events.save(db=db_session) + for list_of_event_code in list_of_all_events: + service_to_event_found = Service2Events.filter_one_system( + Service2Events.event_id == list_of_event_code.id, + Service2Events.service_id == service_match.id, + db=db_session, + ) + if service_to_event_found.data: + service_to_event_found.destroy(db=db_session) + print( + f"UUID: {service_to_event_found.uu_id} event is deleted from {service_match.uu_id}" + ) + created_service = Service2Events.find_or_create( service_id=service_match.id, service_uu_id=str(service_match.uu_id), @@ -32,6 +46,7 @@ def init_service_to_event_matches_for_super_user(super_user, db_session=None) -> print( f"UUID: {created_service.uu_id} event is saved to {service_match.uu_id}" ) + employee_added_service = Event2Employee.find_or_create( event_service_id=service_match.id, diff --git a/ApiServices/ManagementService/Endpoints/service_endpoints/route.py b/ApiServices/ManagementService/Endpoints/service_endpoints/route.py index 12781e1..969fc8b 100644 --- a/ApiServices/ManagementService/Endpoints/service_endpoints/route.py +++ b/ApiServices/ManagementService/Endpoints/service_endpoints/route.py @@ -5,6 +5,7 @@ from ApiControllers.providers.token_provider import TokenProvider from Controllers.Postgres.pagination import PaginateOnly, Pagination, PaginationResult from Controllers.Postgres.response import EndpointResponse +from Events.service_endpoints.cluster import ServiceEndpointRouterCluster # Create API router diff --git a/ApiServices/ManagementService/Events/application/supers_events.py b/ApiServices/ManagementService/Events/application/supers_events.py index 2ccc50c..0f2e025 100644 --- a/ApiServices/ManagementService/Events/application/supers_events.py +++ b/ApiServices/ManagementService/Events/application/supers_events.py @@ -72,7 +72,7 @@ def application_list_callable(list_options: PaginateOnly): data=applications_list, pagination=pagination, # response_model="", - ).pagination.as_dict + ) return EndpointResponse( message="MSG0003-LIST", pagination_result=pagination_result, diff --git a/ApiServices/ManagementService/Events/service_endpoints/supers_events.py b/ApiServices/ManagementService/Events/service_endpoints/supers_events.py index d985ac0..6247aa0 100644 --- a/ApiServices/ManagementService/Events/service_endpoints/supers_events.py +++ b/ApiServices/ManagementService/Events/service_endpoints/supers_events.py @@ -14,29 +14,21 @@ ServiceEndpointListEvent = Event( ) -def service_endpoint_list_callable(list_options: PaginateOnly): +def service_endpoint_list_callable(data: PaginateOnly): """ - Example callable method + List services endpoint callable method """ - list_options = PaginateOnly(**list_options.model_dump()) + list_options = PaginateOnly(**data.model_dump()) with Services.new_session() as db_session: - if list_options.query: - services_list = Services.filter_all( - *Services.convert(list_options.query), db=db_session - ) + if data.query: + services_list = Services.filter_all_system(*Services.convert(data.query), db=db_session) else: - services_list = Services.filter_all(db=db_session) + services_list = Services.filter_all_system(db=db_session) pagination = Pagination(data=services_list) - pagination.change(**list_options.model_dump()) - pagination_result = PaginationResult( - data=services_list, - pagination=pagination, - # response_model="", - ).pagination.as_dict - return EndpointResponse( - message="MSG0003-LIST", - pagination_result=pagination_result, - ).response + pagination.change(**data.model_dump()) + pagination_result = PaginationResult(data=services_list, pagination=pagination) + print("service pagination_result", pagination_result) + return EndpointResponse(message="MSG0003-LIST", pagination_result=pagination_result).response ServiceEndpointListEvent.event_callable = service_endpoint_list_callable diff --git a/Controllers/Postgres/response.py b/Controllers/Postgres/response.py index 7a672f1..b28a4c0 100644 --- a/Controllers/Postgres/response.py +++ b/Controllers/Postgres/response.py @@ -121,7 +121,19 @@ class EndpointResponse(BaseModel): @property def response(self): """Convert response to dictionary format.""" - resutl_data = getattr(self.pagination_result, "data", None) + result_data = getattr(self.pagination_result, "data", None) + if not result_data: + return { + "completed": False, + "message": "MSG0004-NODATA", + "data": None, + "pagination": { + "page": 1, + "size": 10, + "total_count": 0, + "total_pages": 0, + }, + } result_pagination = getattr(self.pagination_result, "pagination", None) if not result_pagination: raise ValueError("Invalid pagination result pagination.") @@ -131,7 +143,7 @@ class EndpointResponse(BaseModel): return { "completed": self.completed, "message": self.message, - "data": resutl_data, + "data": result_data, "pagination": pagination_dict, } diff --git a/Schemas/event/event.py b/Schemas/event/event.py index 024f316..1ad847c 100644 --- a/Schemas/event/event.py +++ b/Schemas/event/event.py @@ -295,14 +295,17 @@ class Event2Employee(CrudCollection): db=db, ).data service_ids = list(set([event.event_service_id for event in employee_events])) + print("service_ids", service_ids) active_event_ids = Service2Events.filter_all( Service2Events.service_id.in_(service_ids), db=db, ).data + print("active_event_ids", active_event_ids) active_events = Events.filter_all( Events.id.in_([event.event_id for event in active_event_ids]), db=db, ).data + print("active_events", active_events) if extra_events := Event2EmployeeExtra.filter_all( Event2EmployeeExtra.employee_id == employee_id, db=db, @@ -318,6 +321,7 @@ class Event2Employee(CrudCollection): events_dict[str(event.endpoint_code)] = str(event.function_code) else: ValueError("Duplicate event code found for single endpoint") + print("events_dict", events_dict) return events_dict diff --git a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CreateButton.tsx b/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CreateButton.tsx deleted file mode 100644 index 2716947..0000000 --- a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CreateButton.tsx +++ /dev/null @@ -1,25 +0,0 @@ -"use client"; -import React from "react"; -import { Button } from "@/components/ui/button"; -import { Plus } from "lucide-react"; - -interface CreateButtonProps { - onClick: () => void; - translations: Record; - lang: string; -} - -export const CreateButton: React.FC = ({ - onClick, - translations, - lang, -}) => { - const t = translations[lang] || {}; - - return ( - - ); -}; diff --git a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CustomButtonComponent.tsx b/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CustomButtonComponent.tsx deleted file mode 100644 index 2d86b8b..0000000 --- a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/CustomButtonComponent.tsx +++ /dev/null @@ -1,31 +0,0 @@ -"use client"; -import React from "react"; -import { Button } from "@/components/ui/button"; -import { CustomButton } from "./types"; -import { cn } from "@/lib/utils"; - -interface CustomButtonComponentProps { - button: CustomButton; - isSelected: boolean; - onClick: () => void; -} - -export const CustomButtonComponent: React.FC = ({ - button, - isSelected, - onClick, -}) => { - return ( - - ); -}; diff --git a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/index.ts b/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/index.ts deleted file mode 100644 index 5b1e2de..0000000 --- a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './CreateButton'; -export * from './CustomButtonComponent'; -export * from './types'; diff --git a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/types.ts b/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/types.ts deleted file mode 100644 index 270f86a..0000000 --- a/WebServices/client-frontend/src/components/common/ActionButtonsDisplay/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { ReactNode } from "react"; - -export interface CustomButton { - id: string; - label: string; - onClick: () => void; - variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link"; - icon?: ReactNode; -} - -export interface ActionButtonsProps { - onCreateClick: () => void; - translations: Record; - lang: string; - customButtons?: CustomButton[]; - defaultSelectedButtonId?: string; -} diff --git a/WebServices/client-frontend/src/components/common/CardDisplay/CardDisplay.tsx b/WebServices/client-frontend/src/components/common/CardDisplay/CardDisplay.tsx deleted file mode 100644 index 584e098..0000000 --- a/WebServices/client-frontend/src/components/common/CardDisplay/CardDisplay.tsx +++ /dev/null @@ -1,71 +0,0 @@ -"use client"; -import React from "react"; -import { CardItem } from "./CardItem"; -import { CardSkeleton } from "./CardSkeleton"; -import { getFieldValue, getGridClasses } from "./utils"; -import { CardDisplayProps } from "./schema"; - -export function CardDisplay({ - showFields, - data, - lang, - translations, - error, - loading, - titleField = "name", - onCardClick, - renderCustomField, - gridCols = 4, - showViewIcon = false, - showUpdateIcon = false, - onViewClick, - onUpdateClick, -}: CardDisplayProps) { - if (error) { - return ( -
- {error.message || "An error occurred while fetching data."} -
- ); - } - - return ( -
- {loading ? ( - // Loading skeletons - Array.from({ length: 10 }).map((_, index) => ( - - )) - ) : data.length === 0 ? ( -
- {(translations[lang] || {}).noData || "No data found"} -
- ) : ( - data.map((item, index) => ( - - )) - )} -
- ); -} diff --git a/WebServices/client-frontend/src/components/common/CardDisplay/CardItem.tsx b/WebServices/client-frontend/src/components/common/CardDisplay/CardItem.tsx deleted file mode 100644 index 83bd719..0000000 --- a/WebServices/client-frontend/src/components/common/CardDisplay/CardItem.tsx +++ /dev/null @@ -1,130 +0,0 @@ -"use client"; -import React from "react"; -import { - Card, - CardContent, - CardHeader, -} from "@/components/ui/card"; -import { Button } from "@/components/ui/button"; -import { Eye, Edit } from "lucide-react"; -import { CardItemProps, CardActionsProps, CardFieldProps } from "./schema"; - -export function CardItem({ - item, - index, - showFields, - titleField, - lang, - translations, - onCardClick, - renderCustomField, - showViewIcon, - showUpdateIcon, - onViewClick, - onUpdateClick, - getFieldValue, -}: CardItemProps) { - return ( -
- onCardClick(item) : undefined} - > - -

- {getFieldValue(item, titleField)} -

- -
- -
- {showFields.map((field) => ( - - ))} -
-
-
-
- ); -} - -// Interface moved to schema.ts - -function CardActions({ - item, - showViewIcon, - showUpdateIcon, - onViewClick, - onUpdateClick, -}: CardActionsProps) { - if (!showViewIcon && !showUpdateIcon) return null; - - return ( -
- {showViewIcon && ( - - )} - {showUpdateIcon && ( - - )} -
- ); -} - -// Interface moved to schema.ts - -function CardField({ - item, - field, - lang, - translations, - renderCustomField, - getFieldValue, -}: CardFieldProps) { - return ( -
- - {translations[field]?.[lang] || field}: - - - {renderCustomField - ? renderCustomField(item, field) - : getFieldValue(item, field)} - -
- ); -} diff --git a/WebServices/client-frontend/src/components/common/CardDisplay/CardSkeleton.tsx b/WebServices/client-frontend/src/components/common/CardDisplay/CardSkeleton.tsx deleted file mode 100644 index 73c0620..0000000 --- a/WebServices/client-frontend/src/components/common/CardDisplay/CardSkeleton.tsx +++ /dev/null @@ -1,46 +0,0 @@ -"use client"; -import React from "react"; -import { - Card, - CardContent, - CardHeader, -} from "@/components/ui/card"; -import { Skeleton } from "@/components/ui/skeleton"; -import { CardSkeletonProps } from "./schema"; - -// Interface moved to schema.ts - -export function CardSkeleton({ - index, - showFields, - showViewIcon, - showUpdateIcon, -}: CardSkeletonProps) { - return ( -
- - - -
- {showViewIcon && ( - - )} - {showUpdateIcon && ( - - )} -
-
- -
- {showFields.map((field, fieldIndex) => ( -
- - -
- ))} -
-
-
-
- ); -} diff --git a/WebServices/client-frontend/src/components/common/CardDisplay/index.tsx b/WebServices/client-frontend/src/components/common/CardDisplay/index.tsx deleted file mode 100644 index b3dba2c..0000000 --- a/WebServices/client-frontend/src/components/common/CardDisplay/index.tsx +++ /dev/null @@ -1 +0,0 @@ -export { CardDisplay } from './CardDisplay'; diff --git a/WebServices/client-frontend/src/components/common/CardDisplay/schema.ts b/WebServices/client-frontend/src/components/common/CardDisplay/schema.ts deleted file mode 100644 index b1637b0..0000000 --- a/WebServices/client-frontend/src/components/common/CardDisplay/schema.ts +++ /dev/null @@ -1,117 +0,0 @@ -/** - * CardDisplay component interfaces - */ - -/** - * Main props for the CardDisplay component - */ -export interface CardDisplayProps { - /** Fields to display in each card */ - showFields: string[]; - /** Array of data items to display */ - data: T[]; - /** Current language code */ - lang: string; - /** Translations object for field labels and messages */ - translations: Record; - /** Error object if data fetching failed */ - error: Error | null; - /** Loading state indicator */ - loading: boolean; - /** Field to use as the card title (default: "name") */ - titleField?: string; - /** Handler for when a card is clicked */ - onCardClick?: (item: T) => void; - /** Custom renderer for specific fields */ - renderCustomField?: (item: T, field: string) => React.ReactNode; - /** Number of columns in the grid (1-6) */ - gridCols?: 1 | 2 | 3 | 4 | 5 | 6; - /** Whether to show the view icon */ - showViewIcon?: boolean; - /** Whether to show the update/edit icon */ - showUpdateIcon?: boolean; - /** Handler for when the view icon is clicked */ - onViewClick?: (item: T) => void; - /** Handler for when the update/edit icon is clicked */ - onUpdateClick?: (item: T) => void; -} - -/** - * Props for the CardItem component - */ -export interface CardItemProps { - /** Data item to display */ - item: T; - /** Index of the item in the data array */ - index: number; - /** Fields to display in the card */ - showFields: string[]; - /** Field to use as the card title */ - titleField: string; - /** Current language code */ - lang: string; - /** Translations object for field labels */ - translations: Record; - /** Handler for when the card is clicked */ - onCardClick?: (item: T) => void; - /** Custom renderer for specific fields */ - renderCustomField?: (item: T, field: string) => React.ReactNode; - /** Whether to show the view icon */ - showViewIcon: boolean; - /** Whether to show the update/edit icon */ - showUpdateIcon: boolean; - /** Handler for when the view icon is clicked */ - onViewClick?: (item: T) => void; - /** Handler for when the update/edit icon is clicked */ - onUpdateClick?: (item: T) => void; - /** Function to get field values from the item */ - getFieldValue: (item: any, field: string) => any; -} - -/** - * Props for the CardActions component - */ -export interface CardActionsProps { - /** Data item the actions apply to */ - item: T; - /** Whether to show the view icon */ - showViewIcon: boolean; - /** Whether to show the update/edit icon */ - showUpdateIcon: boolean; - /** Handler for when the view icon is clicked */ - onViewClick?: (item: T) => void; - /** Handler for when the update/edit icon is clicked */ - onUpdateClick?: (item: T) => void; -} - -/** - * Props for the CardField component - */ -export interface CardFieldProps { - /** Data item the field belongs to */ - item: T; - /** Field name to display */ - field: string; - /** Current language code */ - lang: string; - /** Translations object for field labels */ - translations: Record; - /** Custom renderer for specific fields */ - renderCustomField?: (item: T, field: string) => React.ReactNode; - /** Function to get field values from the item */ - getFieldValue: (item: any, field: string) => any; -} - -/** - * Props for the CardSkeleton component - */ -export interface CardSkeletonProps { - /** Index of the skeleton in the loading array */ - index: number; - /** Fields to create skeleton placeholders for */ - showFields: string[]; - /** Whether to show a skeleton for the view icon */ - showViewIcon: boolean; - /** Whether to show a skeleton for the update/edit icon */ - showUpdateIcon: boolean; -} diff --git a/WebServices/client-frontend/src/components/common/CardDisplay/utils.ts b/WebServices/client-frontend/src/components/common/CardDisplay/utils.ts deleted file mode 100644 index 4e6e97f..0000000 --- a/WebServices/client-frontend/src/components/common/CardDisplay/utils.ts +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Safely gets a field value from an item, supporting nested fields with dot notation - */ -export function getFieldValue(item: any, field: string): any { - if (!item) return ""; - - // Handle nested fields with dot notation (e.g., "user.name") - if (field.includes(".")) { - const parts = field.split("."); - let value = item; - for (const part of parts) { - if (value === null || value === undefined) return ""; - value = value[part]; - } - return value; - } - - return item[field]; -} - -/** - * Gets a field label from translations or formats the field name - */ -export function getFieldLabel(field: string, translations: Record, lang: string): string { - const t = translations[lang] || {}; - return t[field] || field.charAt(0).toUpperCase() + field.slice(1).replace(/_/g, " "); -} - -/** - * Generates responsive grid classes based on the gridCols prop - */ -export function getGridClasses(gridCols: 1 | 2 | 3 | 4 | 5 | 6): string { - const baseClass = "grid grid-cols-1 gap-4"; - - // Map gridCols to responsive classes - const colClasses: Record = { - 1: "", - 2: "sm:grid-cols-2", - 3: "sm:grid-cols-2 md:grid-cols-3", - 4: "sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4", - 5: "sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5", - 6: "sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6" - }; - - return `${baseClass} ${colClasses[gridCols]}`; -} diff --git a/WebServices/client-frontend/src/components/common/FormDisplay/CreateComponent.tsx b/WebServices/client-frontend/src/components/common/FormDisplay/CreateComponent.tsx deleted file mode 100644 index 1a339bf..0000000 --- a/WebServices/client-frontend/src/components/common/FormDisplay/CreateComponent.tsx +++ /dev/null @@ -1,303 +0,0 @@ -"use client"; -import React, { useState, useEffect } from "react"; -import { Button } from "@/components/ui/button"; -import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; -import { CreateComponentProps, FieldDefinition } from "./types"; -import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; -import { Textarea } from "@/components/ui/textarea"; -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; -import { Checkbox } from "@/components/ui/checkbox"; -import { zodResolver } from "@hookform/resolvers/zod"; -import { useForm, SubmitHandler } from "react-hook-form"; -import { Alert, AlertDescription } from "@/components/ui/alert"; -import { AlertCircle } from "lucide-react"; - -export function CreateComponent({ - refetch, - setMode, - setSelectedItem, - onCancel, - lang, - translations, - formProps = {}, - apiUrl, -}: CreateComponentProps) { - const t = translations[lang as keyof typeof translations] || {}; - - // Get field definitions from formProps if available - const fieldDefinitions = formProps.fieldDefinitions || {}; - const validationSchema = formProps.validationSchema; - - // Group fields by their group property - const [groupedFields, setGroupedFields] = useState>({}); - - // Process field definitions to group them - useEffect(() => { - if (Object.keys(fieldDefinitions).length > 0) { - const groups: Record = {}; - - // Group fields by their group property - Object.entries(fieldDefinitions).forEach(([fieldName, definition]) => { - const def = definition as FieldDefinition; - if (!groups[def.group]) { - groups[def.group] = []; - } - groups[def.group].push({ ...def, name: fieldName }); - }); - - setGroupedFields(groups); - } - }, [fieldDefinitions]); - - // Initialize form with default values from field definitions - const defaultValues: Record = {}; - Object.entries(fieldDefinitions).forEach(([key, def]) => { - const fieldDef = def as FieldDefinition; - defaultValues[key] = fieldDef.defaultValue !== undefined ? fieldDef.defaultValue : ""; - }); - - // Setup form with validation schema if available - const { - register, - handleSubmit, - formState: { errors }, - setValue, - watch, - reset, - } = useForm>({ - defaultValues, - resolver: validationSchema ? zodResolver(validationSchema) : undefined, - }); - - const formValues = watch(); - - // Get language-specific validation schema if available - useEffect(() => { - if (formProps.schemaPath) { - const loadLanguageValidationSchema = async () => { - try { - // Dynamic import of the schema module - const schemaModule = await import(formProps.schemaPath); - - // Check if language-specific schema functions are available - if (schemaModule.getCreateApplicationSchema) { - const langValidationSchema = schemaModule.getCreateApplicationSchema(lang as "en" | "tr"); - - // Reset the form with the current values - reset(defaultValues); - - // Update the validation schema in formProps for future validations - formProps.validationSchema = langValidationSchema; - } - } catch (error) { - console.error("Error loading language-specific validation schema:", error); - } - }; - - loadLanguageValidationSchema(); - } - }, [lang, formProps.schemaPath, reset, defaultValues]); - - // Handle form submission - const onSubmit: SubmitHandler> = async (data) => { - try { - if (apiUrl) { - const createUrl = `${apiUrl}/create`; - const response = await fetch(createUrl, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify(data), - }); - console.log("Response:", response.ok); - if (!response.ok) { - throw new Error(`API error: ${response.status}`); - } - - const createdItem = await response.json(); - console.log("Created item:", createdItem); - } - - if (refetch) refetch(); - setMode("list"); - setSelectedItem(null); - } catch (error) { - console.error("Error saving form:", error); - } - }; - - // Handle select changes - const handleSelectChange = (name: string, value: string) => { - setValue(name, value); - }; - - // Handle checkbox changes - const handleCheckboxChange = (name: string, checked: boolean) => { - setValue(name, checked); - }; - - // Translate group names for display dynamically - const getGroupTitle = (groupName: string) => { - // Check if we have a translation for this group name - if (t[groupName]) { - return t[groupName]; - } - - // If no translation is found, just format the name as a fallback - const formattedName = groupName - .replace(/([A-Z])/g, ' $1') - .replace(/_/g, ' ') - .replace(/^./, (str) => str.toUpperCase()) - .replace(/\b\w/g, (c) => c.toUpperCase()); - return formattedName; - }; - - // Render a field based on its type - const renderField = (fieldName: string, field: FieldDefinition) => { - const errorMessage = errors[fieldName]?.message as string; - - switch (field.type) { - case "text": - return ( -
- - - {errorMessage && ( -

{errorMessage}

- )} -
- ); - - case "textarea": - return ( -
- -