@mui-toolpad-extended-tuni/courses 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,11 +42,11 @@ npm install @mui-toolpad-extended-tuni/courses @mui-toolpad-extended-tuni/main @
42
42
 
43
43
  ## API Configuration
44
44
 
45
- This package uses configurable API endpoints. You can customize all endpoints via the `apiConfig` prop in `ToolpadProvider`.
45
+ This package uses configurable API endpoints. Each microservice accepts its own `apiEndpoints` prop, allowing you to configure endpoints independently for only the services you use.
46
46
 
47
47
  ### Default Endpoints
48
48
 
49
- If no configuration is provided, the package uses these default endpoints:
49
+ If no `apiEndpoints` prop is provided, the package uses these default endpoints:
50
50
 
51
51
  - `get: "api/courses/"` - GET list of courses
52
52
  - `getById: "api/courses/:id"` - GET course by ID (use `:id` placeholder)
@@ -57,30 +57,39 @@ If no configuration is provided, the package uses these default endpoints:
57
57
 
58
58
  ### Customizing Endpoints
59
59
 
60
- Configure endpoints via `ToolpadProvider`:
60
+ Configure endpoints directly on the `CourseMicroservice` component:
61
61
 
62
62
  ```tsx
63
- import { ToolpadProvider } from '@mui-toolpad-extended-tuni/main';
63
+ import { CourseMicroservice } from '@mui-toolpad-extended-tuni/courses';
64
64
  import type { CoursesApiEndpoints } from '@mui-toolpad-extended-tuni/courses';
65
65
 
66
- const apiConfig = {
67
- courses: {
68
- get: "https://api.example.com/v1/courses",
69
- getById: "https://api.example.com/v1/courses/:id",
70
- getByUrl: "https://api.example.com/v1/courses?url=:encodedUrl",
71
- post: "https://api.example.com/v1/courses",
72
- put: "https://api.example.com/v1/courses/:id",
73
- delete: "https://api.example.com/v1/courses/:id",
74
- } as CoursesApiEndpoints,
66
+ const coursesEndpoints: CoursesApiEndpoints = {
67
+ get: "https://api.example.com/v1/courses",
68
+ getById: "https://api.example.com/v1/courses/:id",
69
+ getByUrl: "https://api.example.com/v1/courses?url=:encodedUrl",
70
+ post: "https://api.example.com/v1/courses",
71
+ put: "https://api.example.com/v1/courses/:id",
72
+ delete: "https://api.example.com/v1/courses/:id",
75
73
  };
76
74
 
77
- <ToolpadProvider apiConfig={apiConfig}>
78
- {/* Your app */}
79
- </ToolpadProvider>
75
+ <CourseMicroservice apiEndpoints={coursesEndpoints}>
76
+ {/* Your course microservices */}
77
+ </CourseMicroservice>
80
78
  ```
81
79
 
82
80
  **Note**: You can use either full URLs (`https://api.example.com/courses`) or relative paths (`api/courses/`). Placeholders like `:id` will be replaced with actual values at runtime.
83
81
 
82
+ **Partial Configuration**: You can configure only the endpoints you need to customize. Unspecified endpoints will use defaults:
83
+
84
+ ```tsx
85
+ <CourseMicroservice apiEndpoints={{
86
+ get: "api/v2/courses", // Only override GET endpoint
87
+ // Other endpoints use defaults
88
+ }}>
89
+ {/* Your course microservices */}
90
+ </CourseMicroservice>
91
+ ```
92
+
84
93
  ## Usage
85
94
 
86
95
  ### Basic Setup
@@ -682,6 +691,7 @@ type courseRelationType = "prerequisite" | "recommended" | "parallel" |
682
691
 
683
692
  ### Hooks
684
693
  - `useCourseMicroserviceRegistration` - Hook for registering custom course microservices (must be used within `CourseMicroservice` context)
694
+ - `useCoursesApiConfig` - Hook to access courses API endpoint configuration
685
695
 
686
696
  ### Store
687
697
  - `useCourseStore` - Zustand store for course management
@@ -1,6 +1,9 @@
1
1
  import { default as React, ReactNode } from 'react';
2
- interface CourseMicroserviceProps {
2
+ import { CoursesApiEndpoints } from '@mui-toolpad-extended-tuni/core';
3
+ export interface CourseMicroserviceProps {
3
4
  children?: ReactNode;
5
+ /** API endpoint configuration for the courses microservice */
6
+ apiEndpoints?: CoursesApiEndpoints;
4
7
  }
5
8
  /**
6
9
  * CourseMicroservice Component
@@ -0,0 +1,15 @@
1
+ import { CoursesApiEndpoints } from '@mui-toolpad-extended-tuni/core';
2
+ /**
3
+ * Hook to access courses API configuration.
4
+ * Returns the courses endpoint configuration merged with defaults.
5
+ *
6
+ * @returns Courses API endpoints configuration, or undefined if not registered
7
+ * @throws Error if used outside of ApiConfigProvider
8
+ *
9
+ * @example
10
+ * ```tsx
11
+ * const coursesConfig = useCoursesApiConfig();
12
+ * const endpoint = coursesConfig?.get; // "api/courses/" or custom value
13
+ * ```
14
+ */
15
+ export declare const useCoursesApiConfig: () => CoursesApiEndpoints | undefined;