@appcorp/fusion-storybook 0.5.39 → 0.5.40
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/base-modules/admission/context/use-admission-module.d.ts +3 -0
- package/base-modules/admission/context/use-admission-module.js +41 -5
- package/base-modules/student-profile/context/use-student-profile-module.js +4 -0
- package/base-modules/workspace/context.d.ts +6 -36
- package/base-modules/workspace/context.js +1 -20
- package/base-modules/workspace/view.js +12 -9
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/user-management.d.ts +2 -12
- package/utils/student-usage-api.d.ts +6 -0
- package/utils/student-usage-api.js +16 -0
- package/utils/student-usage.d.ts +20 -0
- package/utils/student-usage.js +40 -0
|
@@ -17,16 +17,10 @@ export interface PlanBE {
|
|
|
17
17
|
currency: CURRENCY;
|
|
18
18
|
enabled: boolean;
|
|
19
19
|
id: string;
|
|
20
|
-
maxClasses: number;
|
|
21
|
-
maxCourses: number;
|
|
22
|
-
maxFamilies: number;
|
|
23
|
-
maxStaffAccounts: number;
|
|
24
20
|
maxStudents: number;
|
|
25
|
-
maxTeachers: number;
|
|
26
21
|
name: string;
|
|
27
22
|
priceMonthly: number;
|
|
28
23
|
priceYearly: number;
|
|
29
|
-
storageLimitMB: number;
|
|
30
24
|
type: PRICING_PLAN_CODE;
|
|
31
25
|
updatedAt: string;
|
|
32
26
|
workspaces?: WorkspaceBE[];
|
|
@@ -41,13 +35,10 @@ export interface WorkspaceBE {
|
|
|
41
35
|
agreedPrice: number | string;
|
|
42
36
|
billingDate: number;
|
|
43
37
|
billingInterval: BILLING_INTERVAL;
|
|
44
|
-
classesCount: number;
|
|
45
|
-
coursesCount: number;
|
|
46
38
|
createdAt: string;
|
|
47
39
|
description: string | null;
|
|
48
40
|
dueDateLength: number;
|
|
49
41
|
enabled: boolean;
|
|
50
|
-
familiesCount: number;
|
|
51
42
|
id: string;
|
|
52
43
|
logo: string | null;
|
|
53
44
|
name: string;
|
|
@@ -55,11 +46,10 @@ export interface WorkspaceBE {
|
|
|
55
46
|
planId: string | null;
|
|
56
47
|
planStartDate: Date | string | null;
|
|
57
48
|
secrets?: any | null;
|
|
58
|
-
staffAccountsCount: number;
|
|
59
|
-
storageUsedMB: number;
|
|
60
49
|
studentsCount: number;
|
|
61
50
|
subdomain: string;
|
|
62
|
-
|
|
51
|
+
studentLimit?: number | null;
|
|
52
|
+
customMaxStudents?: number | null;
|
|
63
53
|
updatedAt: string;
|
|
64
54
|
customRoles?: RoleBE[];
|
|
65
55
|
plan?: PlanBE;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { StudentUsage } from "./student-usage";
|
|
2
|
+
/**
|
|
3
|
+
* Fetch the current workspace's student-seat usage. Returns `null` when the
|
|
4
|
+
* request fails so callers can keep rendering the rest of the UI.
|
|
5
|
+
*/
|
|
6
|
+
export declare const fetchStudentUsage: (workspaceId: string) => Promise<StudentUsage | null>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { API_METHODS } from "@react-pakistan/util-functions/constants/api-methods";
|
|
2
|
+
import { fetchData } from "@react-pakistan/util-functions/general/fetch-data";
|
|
3
|
+
/**
|
|
4
|
+
* Fetch the current workspace's student-seat usage. Returns `null` when the
|
|
5
|
+
* request fails so callers can keep rendering the rest of the UI.
|
|
6
|
+
*/
|
|
7
|
+
export const fetchStudentUsage = async (workspaceId) => {
|
|
8
|
+
const { data, error } = await fetchData({
|
|
9
|
+
url: `/api/v1/workspace/usage?workspaceId=${encodeURIComponent(workspaceId)}`,
|
|
10
|
+
method: API_METHODS.GET,
|
|
11
|
+
headers: { "Content-Type": "application/json" },
|
|
12
|
+
});
|
|
13
|
+
if (error || !data)
|
|
14
|
+
return null;
|
|
15
|
+
return data;
|
|
16
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface StudentUsage {
|
|
2
|
+
studentsCount: number;
|
|
3
|
+
studentLimit: number | null;
|
|
4
|
+
remaining: number | null;
|
|
5
|
+
percentUsed: number;
|
|
6
|
+
reached: boolean;
|
|
7
|
+
approaching: boolean;
|
|
8
|
+
planName: string | null;
|
|
9
|
+
}
|
|
10
|
+
export declare const STUDENT_USAGE_EVENT = "fusion:student-usage-changed";
|
|
11
|
+
export declare const STUDENT_LIMIT_APPROACHING_RATIO = 0.8;
|
|
12
|
+
/** Notify mounted usage consumers that the student count may have changed. */
|
|
13
|
+
export declare const emitStudentUsageChanged: () => void;
|
|
14
|
+
/** Subscribe to student-usage change events. Returns an unsubscribe function. */
|
|
15
|
+
export declare const onStudentUsageChanged: (handler: () => void) => (() => void);
|
|
16
|
+
/**
|
|
17
|
+
* Local status calculation used by UI that has a count/limit pair but not the
|
|
18
|
+
* API's pre-computed usage payload.
|
|
19
|
+
*/
|
|
20
|
+
export declare const getStudentLimitStatus: (studentsCount: number, studentLimit: number | null) => Pick<StudentUsage, "remaining" | "percentUsed" | "reached" | "approaching">;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export const STUDENT_USAGE_EVENT = "fusion:student-usage-changed";
|
|
2
|
+
export const STUDENT_LIMIT_APPROACHING_RATIO = 0.8;
|
|
3
|
+
/** Notify mounted usage consumers that the student count may have changed. */
|
|
4
|
+
export const emitStudentUsageChanged = () => {
|
|
5
|
+
if (typeof window !== "undefined") {
|
|
6
|
+
window.dispatchEvent(new Event(STUDENT_USAGE_EVENT));
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
/** Subscribe to student-usage change events. Returns an unsubscribe function. */
|
|
10
|
+
export const onStudentUsageChanged = (handler) => {
|
|
11
|
+
if (typeof window === "undefined")
|
|
12
|
+
return () => undefined;
|
|
13
|
+
window.addEventListener(STUDENT_USAGE_EVENT, handler);
|
|
14
|
+
return () => window.removeEventListener(STUDENT_USAGE_EVENT, handler);
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Local status calculation used by UI that has a count/limit pair but not the
|
|
18
|
+
* API's pre-computed usage payload.
|
|
19
|
+
*/
|
|
20
|
+
export const getStudentLimitStatus = (studentsCount, studentLimit) => {
|
|
21
|
+
if (studentLimit === null) {
|
|
22
|
+
return {
|
|
23
|
+
remaining: null,
|
|
24
|
+
percentUsed: 0,
|
|
25
|
+
reached: false,
|
|
26
|
+
approaching: false,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const remaining = Math.max(studentLimit - studentsCount, 0);
|
|
30
|
+
const percentUsed = studentLimit > 0
|
|
31
|
+
? Math.min(Math.round((studentsCount / studentLimit) * 100), 100)
|
|
32
|
+
: studentsCount > 0
|
|
33
|
+
? 100
|
|
34
|
+
: 0;
|
|
35
|
+
const reached = studentsCount >= studentLimit;
|
|
36
|
+
const approaching = !reached &&
|
|
37
|
+
studentLimit > 0 &&
|
|
38
|
+
studentsCount / studentLimit >= STUDENT_LIMIT_APPROACHING_RATIO;
|
|
39
|
+
return { remaining, percentUsed, reached, approaching };
|
|
40
|
+
};
|