Integrates page entity with backend API
Refactors all page entity operations (get, create, update, delete) to use the Kiota-generated API client instead of mock data. This involves: * Replacing in-memory data and simulated delays with actual API calls to the `/v1/page` endpoint. * Introducing `ApiClient` and `Guid` types from Kiota for API interactions. * Adding a mapping function (`mapPageResponseToPage`) to convert API DTOs to the application's local `Page` type. * Updating page-related UI components (`PageListPage`, `PageDetailPage`, `PageEditPage`) to pass the authenticated `ApiClient` and `userId` to the entity functions. * Regenerating the Kiota client to include new `image`, `page`, and `space` API endpoints and their associated DTOs. * Introducing `useApiClient` and `useUserId` hooks for streamlined API client access and user context.
This commit is contained in:
1 parent
947f3a1899
commit
6325f8f109
19 files changed
+2170
-53
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import { useMemo } from 'react';
|
||||
import { createAuthenticatedApiClient } from '../../config/apiClientFactory';
|
||||
import type { ApiClient } from '../../kiota/apiClient';
|
||||
|
||||
/**
|
||||
* Hook to get an authenticated API client instance
|
||||
* Uses MSAL for authentication
|
||||
*/
|
||||
export function useApiClient(): ApiClient {
|
||||
const { instance } = useMsal();
|
||||
|
||||
const apiClient = useMemo(() => {
|
||||
return createAuthenticatedApiClient(instance);
|
||||
}, [instance]);
|
||||
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to get the current user ID from MSAL
|
||||
*/
|
||||
export function useUserId(): string | null {
|
||||
const { accounts } = useMsal();
|
||||
|
||||
if (accounts.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Return the localAccountId (user's unique identifier)
|
||||
return accounts[0].localAccountId;
|
||||
}
|
||||
Reference in new issue
Block a user