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.
33 lines
804 B
TypeScript
33 lines
804 B
TypeScript
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;
|
|
}
|