@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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AdmissionAIBE, AdmissionBE, DiscountCodeBE } from "../../../type";
|
|
2
|
+
import { type StudentUsage } from "../../../utils/student-usage";
|
|
2
3
|
import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
|
|
3
4
|
export declare const useAdmissionModule: () => {
|
|
4
5
|
applyFilters: () => void;
|
|
@@ -36,6 +37,8 @@ export declare const useAdmissionModule: () => {
|
|
|
36
37
|
}[];
|
|
37
38
|
listLoading: boolean;
|
|
38
39
|
rowActions: RowAction[];
|
|
40
|
+
studentUsage: StudentUsage | null;
|
|
41
|
+
refreshStudentUsage: () => Promise<void>;
|
|
39
42
|
updateLoading: boolean;
|
|
40
43
|
uploadAdmissionDocuments: (files: File[]) => Promise<string[]>;
|
|
41
44
|
state: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { useTheme } from "next-themes";
|
|
4
4
|
import { useTranslations } from "next-intl";
|
|
5
5
|
import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
|
|
@@ -17,6 +17,8 @@ import { getCachedWorkspaceSync } from "../../workspace/cache";
|
|
|
17
17
|
import { downloadAdmissionFormPDF, } from "../../../utils/admission-pdf";
|
|
18
18
|
import { compressPdf, DocumentTooLargeError, isPdfFile, MAX_DOCUMENT_SIZE_BYTES, } from "../../../utils/compress-pdf";
|
|
19
19
|
import { uploadFiles } from "../../../utils/upload-file";
|
|
20
|
+
import { emitStudentUsageChanged, onStudentUsageChanged, } from "../../../utils/student-usage";
|
|
21
|
+
import { fetchStudentUsage } from "../../../utils/student-usage-api";
|
|
20
22
|
import { wakeStorageServer } from "../../../utils/wake-storage";
|
|
21
23
|
import { normalizeIdNumber } from "../../../utils/id-number";
|
|
22
24
|
import { isGovernmentIdType, } from "../../../utils/government-id";
|
|
@@ -34,6 +36,7 @@ export const useAdmissionModule = () => {
|
|
|
34
36
|
const t = useTranslations("admission");
|
|
35
37
|
const { theme } = useTheme();
|
|
36
38
|
const workspace = getCachedWorkspaceSync();
|
|
39
|
+
const [studentUsage, setStudentUsage] = useState(null);
|
|
37
40
|
const listFetchNowRef = useRef(null);
|
|
38
41
|
const debouncedQuery = useDebounce(state.searchQuery, 800);
|
|
39
42
|
// Discount codes are school-scoped; fetch once (not per render) so both the
|
|
@@ -347,6 +350,13 @@ export const useAdmissionModule = () => {
|
|
|
347
350
|
});
|
|
348
351
|
return uploaded.map((file) => file.url);
|
|
349
352
|
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
353
|
+
const refreshStudentUsage = useCallback(async () => {
|
|
354
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
|
|
355
|
+
return;
|
|
356
|
+
const usage = await fetchStudentUsage(workspace.id);
|
|
357
|
+
if (usage)
|
|
358
|
+
setStudentUsage(usage);
|
|
359
|
+
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
350
360
|
// ============================================================================
|
|
351
361
|
// 1.4.5 API HOOKS
|
|
352
362
|
// ============================================================================
|
|
@@ -635,6 +645,8 @@ export const useAdmissionModule = () => {
|
|
|
635
645
|
}),
|
|
636
646
|
});
|
|
637
647
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
648
|
+
emitStudentUsageChanged();
|
|
649
|
+
await refreshStudentUsage();
|
|
638
650
|
// `fetchData` returns the error body as `data` on failure — check the
|
|
639
651
|
// error first so we never show both toasts.
|
|
640
652
|
if (error) {
|
|
@@ -644,7 +656,7 @@ export const useAdmissionModule = () => {
|
|
|
644
656
|
if (data) {
|
|
645
657
|
showToast(t("messagesAdmitSuccess"), TOAST_VARIANT.SUCCESS);
|
|
646
658
|
}
|
|
647
|
-
}, [t, showToast, (_k = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _k === void 0 ? void 0 : _k.id]);
|
|
659
|
+
}, [t, showToast, (_k = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _k === void 0 ? void 0 : _k.id, refreshStudentUsage]);
|
|
648
660
|
// ============================================================================
|
|
649
661
|
// 1.4.7 NETWORK ACTIONS
|
|
650
662
|
// ============================================================================
|
|
@@ -972,8 +984,10 @@ export const useAdmissionModule = () => {
|
|
|
972
984
|
order: 5,
|
|
973
985
|
},
|
|
974
986
|
{
|
|
975
|
-
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.APPROVED
|
|
976
|
-
|
|
987
|
+
enabled: (row) => (row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.APPROVED &&
|
|
988
|
+
!(studentUsage === null || studentUsage === void 0 ? void 0 : studentUsage.reached),
|
|
989
|
+
// eslint-disable-next-line react-hooks/refs -- invoked on click, not during render
|
|
990
|
+
handleOnClick: (row) => handleAddStudent(row),
|
|
977
991
|
label: t("actionsButtonAddStudent"),
|
|
978
992
|
order: 6,
|
|
979
993
|
},
|
|
@@ -986,7 +1000,8 @@ export const useAdmissionModule = () => {
|
|
|
986
1000
|
{
|
|
987
1001
|
enabled: (row) => hasGeminiSecrets &&
|
|
988
1002
|
(row === null || row === void 0 ? void 0 : row.status) === ADMISSION_STATUS.PENDING,
|
|
989
|
-
|
|
1003
|
+
// eslint-disable-next-line react-hooks/refs -- invoked on click, not during render
|
|
1004
|
+
handleOnClick: (row) => handleAnalyze(row),
|
|
990
1005
|
label: t("actionsButtonAnalyzeWithAi"),
|
|
991
1006
|
order: 8,
|
|
992
1007
|
},
|
|
@@ -1008,6 +1023,7 @@ export const useAdmissionModule = () => {
|
|
|
1008
1023
|
handleAnalyze,
|
|
1009
1024
|
handleDelete,
|
|
1010
1025
|
hasGeminiSecrets,
|
|
1026
|
+
studentUsage === null || studentUsage === void 0 ? void 0 : studentUsage.reached,
|
|
1011
1027
|
t,
|
|
1012
1028
|
]);
|
|
1013
1029
|
const applyFilters = useCallback(() => {
|
|
@@ -1041,6 +1057,24 @@ export const useAdmissionModule = () => {
|
|
|
1041
1057
|
useEffect(() => {
|
|
1042
1058
|
listFetchNowRef.current = listFetchNow;
|
|
1043
1059
|
}, [listFetchNow]);
|
|
1060
|
+
useEffect(() => {
|
|
1061
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
|
|
1062
|
+
return;
|
|
1063
|
+
let active = true;
|
|
1064
|
+
const load = async () => {
|
|
1065
|
+
const usage = await fetchStudentUsage(workspace.id);
|
|
1066
|
+
if (active && usage)
|
|
1067
|
+
setStudentUsage(usage);
|
|
1068
|
+
};
|
|
1069
|
+
void load();
|
|
1070
|
+
const unsubscribe = onStudentUsageChanged(() => {
|
|
1071
|
+
void load();
|
|
1072
|
+
});
|
|
1073
|
+
return () => {
|
|
1074
|
+
active = false;
|
|
1075
|
+
unsubscribe();
|
|
1076
|
+
};
|
|
1077
|
+
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
1044
1078
|
useEffect(() => {
|
|
1045
1079
|
var _a;
|
|
1046
1080
|
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
|
|
@@ -1079,6 +1113,8 @@ export const useAdmissionModule = () => {
|
|
|
1079
1113
|
headerActions,
|
|
1080
1114
|
listLoading,
|
|
1081
1115
|
rowActions,
|
|
1116
|
+
studentUsage,
|
|
1117
|
+
refreshStudentUsage,
|
|
1082
1118
|
updateLoading,
|
|
1083
1119
|
uploadAdmissionDocuments });
|
|
1084
1120
|
};
|
|
@@ -13,6 +13,7 @@ import { toE164Phone } from "../../../utils/to-e164-phone";
|
|
|
13
13
|
import { STUDENT_PROFILE_API_ROUTES } from "../../../constants";
|
|
14
14
|
import { studentProfileFormValidation } from "../validate";
|
|
15
15
|
import { getCachedWorkspaceSync } from "../../workspace/cache";
|
|
16
|
+
import { emitStudentUsageChanged } from "../../../utils/student-usage";
|
|
16
17
|
import { useStudentProfileContext, STUDENT_PROFILE_ACTION_TYPES, STUDENT_PROFILE_DRAWER, } from "./module-base";
|
|
17
18
|
export const useStudentProfileModule = () => {
|
|
18
19
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -184,6 +185,7 @@ export const useStudentProfileModule = () => {
|
|
|
184
185
|
showToast(isCreated ? t("messagesCreateSuccess") : t("messagesSaveSuccess"), TOAST_VARIANT.SUCCESS);
|
|
185
186
|
resetFormAndCloseDrawer();
|
|
186
187
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
188
|
+
emitStudentUsageChanged();
|
|
187
189
|
}
|
|
188
190
|
}, [dispatch, resetFormAndCloseDrawer, showToast, t]);
|
|
189
191
|
const byIdCallback = useCallback(({ data, error }) => {
|
|
@@ -236,6 +238,7 @@ export const useStudentProfileModule = () => {
|
|
|
236
238
|
if (data) {
|
|
237
239
|
showToast(t("messagesDeleteSuccess"), TOAST_VARIANT.SUCCESS);
|
|
238
240
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
241
|
+
emitStudentUsageChanged();
|
|
239
242
|
}
|
|
240
243
|
}, [showToast, t]);
|
|
241
244
|
const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
|
|
@@ -442,6 +445,7 @@ export const useStudentProfileModule = () => {
|
|
|
442
445
|
(_b = listFetchNowRef.current) === null || _b === void 0 ? void 0 : _b.call(listFetchNowRef);
|
|
443
446
|
if (data) {
|
|
444
447
|
showToast(t("messagesReAdmitSuccess"), TOAST_VARIANT.SUCCESS);
|
|
448
|
+
emitStudentUsageChanged();
|
|
445
449
|
}
|
|
446
450
|
if (error) {
|
|
447
451
|
showToast(t("messagesReAdmitFailed"), TOAST_VARIANT.ERROR);
|
|
@@ -22,12 +22,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
22
22
|
agreedPrice: number;
|
|
23
23
|
billingDate: null;
|
|
24
24
|
billingInterval: string;
|
|
25
|
-
classesCount: number;
|
|
26
|
-
coursesCount: number;
|
|
27
25
|
description: string;
|
|
28
26
|
dueDateLength: number;
|
|
29
27
|
enabled: boolean;
|
|
30
|
-
familiesCount: number;
|
|
31
28
|
id: string;
|
|
32
29
|
logo: string;
|
|
33
30
|
logoFile: File | null;
|
|
@@ -41,11 +38,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
41
38
|
planId: string;
|
|
42
39
|
planStartDate: null;
|
|
43
40
|
secrets: {};
|
|
44
|
-
staffAccountsCount: number;
|
|
45
|
-
storageUsedMB: number;
|
|
46
41
|
studentsCount: number;
|
|
42
|
+
studentLimit: number | null;
|
|
47
43
|
subdomain: string;
|
|
48
|
-
teachersCount: number;
|
|
49
44
|
disableSaveButton: boolean;
|
|
50
45
|
drawer: null;
|
|
51
46
|
errors: Record<string, string>;
|
|
@@ -54,12 +49,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
54
49
|
agreedPrice: number;
|
|
55
50
|
billingDate: null;
|
|
56
51
|
billingInterval: string;
|
|
57
|
-
classesCount: number;
|
|
58
|
-
coursesCount: number;
|
|
59
52
|
description: string;
|
|
60
53
|
dueDateLength: number;
|
|
61
54
|
enabled: boolean;
|
|
62
|
-
familiesCount: number;
|
|
63
55
|
id: string;
|
|
64
56
|
logo: string;
|
|
65
57
|
logoFile: File | null;
|
|
@@ -73,11 +65,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
73
65
|
planId: string;
|
|
74
66
|
planStartDate: null;
|
|
75
67
|
secrets: {};
|
|
76
|
-
staffAccountsCount: number;
|
|
77
|
-
storageUsedMB: number;
|
|
78
68
|
studentsCount: number;
|
|
69
|
+
studentLimit: number | null;
|
|
79
70
|
subdomain: string;
|
|
80
|
-
teachersCount: number;
|
|
81
71
|
disableSaveButton: boolean;
|
|
82
72
|
drawer: null;
|
|
83
73
|
errors: Record<string, string>;
|
|
@@ -88,12 +78,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
88
78
|
agreedPrice: number;
|
|
89
79
|
billingDate: null;
|
|
90
80
|
billingInterval: string;
|
|
91
|
-
classesCount: number;
|
|
92
|
-
coursesCount: number;
|
|
93
81
|
description: string;
|
|
94
82
|
dueDateLength: number;
|
|
95
83
|
enabled: boolean;
|
|
96
|
-
familiesCount: number;
|
|
97
84
|
id: string;
|
|
98
85
|
logo: string;
|
|
99
86
|
logoFile: File | null;
|
|
@@ -107,11 +94,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
107
94
|
planId: string;
|
|
108
95
|
planStartDate: null;
|
|
109
96
|
secrets: {};
|
|
110
|
-
staffAccountsCount: number;
|
|
111
|
-
storageUsedMB: number;
|
|
112
97
|
studentsCount: number;
|
|
98
|
+
studentLimit: number | null;
|
|
113
99
|
subdomain: string;
|
|
114
|
-
teachersCount: number;
|
|
115
100
|
disableSaveButton: boolean;
|
|
116
101
|
drawer: null;
|
|
117
102
|
errors: Record<string, string>;
|
|
@@ -120,12 +105,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
120
105
|
agreedPrice: number;
|
|
121
106
|
billingDate: null;
|
|
122
107
|
billingInterval: string;
|
|
123
|
-
classesCount: number;
|
|
124
|
-
coursesCount: number;
|
|
125
108
|
description: string;
|
|
126
109
|
dueDateLength: number;
|
|
127
110
|
enabled: boolean;
|
|
128
|
-
familiesCount: number;
|
|
129
111
|
id: string;
|
|
130
112
|
logo: string;
|
|
131
113
|
logoFile: File | null;
|
|
@@ -139,11 +121,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
139
121
|
planId: string;
|
|
140
122
|
planStartDate: null;
|
|
141
123
|
secrets: {};
|
|
142
|
-
staffAccountsCount: number;
|
|
143
|
-
storageUsedMB: number;
|
|
144
124
|
studentsCount: number;
|
|
125
|
+
studentLimit: number | null;
|
|
145
126
|
subdomain: string;
|
|
146
|
-
teachersCount: number;
|
|
147
127
|
disableSaveButton: boolean;
|
|
148
128
|
drawer: null;
|
|
149
129
|
errors: Record<string, string>;
|
|
@@ -152,12 +132,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
152
132
|
agreedPrice: number;
|
|
153
133
|
billingDate: null;
|
|
154
134
|
billingInterval: string;
|
|
155
|
-
classesCount: number;
|
|
156
|
-
coursesCount: number;
|
|
157
135
|
description: string;
|
|
158
136
|
dueDateLength: number;
|
|
159
137
|
enabled: boolean;
|
|
160
|
-
familiesCount: number;
|
|
161
138
|
id: string;
|
|
162
139
|
logo: string;
|
|
163
140
|
logoFile: File | null;
|
|
@@ -171,11 +148,9 @@ export declare const WORKSPACE_ACTION_TYPES: {
|
|
|
171
148
|
planId: string;
|
|
172
149
|
planStartDate: null;
|
|
173
150
|
secrets: {};
|
|
174
|
-
staffAccountsCount: number;
|
|
175
|
-
storageUsedMB: number;
|
|
176
151
|
studentsCount: number;
|
|
152
|
+
studentLimit: number | null;
|
|
177
153
|
subdomain: string;
|
|
178
|
-
teachersCount: number;
|
|
179
154
|
disableSaveButton: boolean;
|
|
180
155
|
drawer: null;
|
|
181
156
|
errors: Record<string, string>;
|
|
@@ -206,12 +181,9 @@ export declare const useWorkspaceModule: () => {
|
|
|
206
181
|
agreedPrice: number;
|
|
207
182
|
billingDate: null;
|
|
208
183
|
billingInterval: string;
|
|
209
|
-
classesCount: number;
|
|
210
|
-
coursesCount: number;
|
|
211
184
|
description: string;
|
|
212
185
|
dueDateLength: number;
|
|
213
186
|
enabled: boolean;
|
|
214
|
-
familiesCount: number;
|
|
215
187
|
id: string;
|
|
216
188
|
logo: string;
|
|
217
189
|
logoFile: File | null;
|
|
@@ -225,11 +197,9 @@ export declare const useWorkspaceModule: () => {
|
|
|
225
197
|
planId: string;
|
|
226
198
|
planStartDate: null;
|
|
227
199
|
secrets: {};
|
|
228
|
-
staffAccountsCount: number;
|
|
229
|
-
storageUsedMB: number;
|
|
230
200
|
studentsCount: number;
|
|
201
|
+
studentLimit: number | null;
|
|
231
202
|
subdomain: string;
|
|
232
|
-
teachersCount: number;
|
|
233
203
|
disableSaveButton: boolean;
|
|
234
204
|
drawer: null;
|
|
235
205
|
errors: Record<string, string>;
|
|
@@ -51,12 +51,9 @@ const workspaceConfig = {
|
|
|
51
51
|
agreedPrice: 0,
|
|
52
52
|
billingDate: null,
|
|
53
53
|
billingInterval: "",
|
|
54
|
-
classesCount: 0,
|
|
55
|
-
coursesCount: 0,
|
|
56
54
|
description: "",
|
|
57
55
|
dueDateLength: 0,
|
|
58
56
|
enabled: true,
|
|
59
|
-
familiesCount: 0,
|
|
60
57
|
id: "",
|
|
61
58
|
logo: "",
|
|
62
59
|
logoFile: null,
|
|
@@ -66,11 +63,9 @@ const workspaceConfig = {
|
|
|
66
63
|
planId: "",
|
|
67
64
|
planStartDate: null,
|
|
68
65
|
secrets: {},
|
|
69
|
-
staffAccountsCount: 0,
|
|
70
|
-
storageUsedMB: 0,
|
|
71
66
|
studentsCount: 0,
|
|
67
|
+
studentLimit: null,
|
|
72
68
|
subdomain: "",
|
|
73
|
-
teachersCount: 0,
|
|
74
69
|
// UI State
|
|
75
70
|
disableSaveButton: false,
|
|
76
71
|
drawer: null,
|
|
@@ -162,12 +157,9 @@ export const useWorkspaceModule = () => {
|
|
|
162
157
|
agreedPrice: state.agreedPrice,
|
|
163
158
|
billingDate: state.billingDate,
|
|
164
159
|
billingInterval: state.billingInterval,
|
|
165
|
-
classesCount: state.classesCount,
|
|
166
|
-
coursesCount: state.coursesCount,
|
|
167
160
|
description: state.description,
|
|
168
161
|
dueDateLength: state.dueDateLength,
|
|
169
162
|
enabled: state.enabled,
|
|
170
|
-
familiesCount: state.familiesCount,
|
|
171
163
|
id: state.id,
|
|
172
164
|
logo: state.logo,
|
|
173
165
|
name: state.name,
|
|
@@ -175,22 +167,15 @@ export const useWorkspaceModule = () => {
|
|
|
175
167
|
planId: state.planId,
|
|
176
168
|
planStartDate: state.planStartDate,
|
|
177
169
|
secrets: state.secrets,
|
|
178
|
-
staffAccountsCount: state.staffAccountsCount,
|
|
179
|
-
storageUsedMB: state.storageUsedMB,
|
|
180
|
-
studentsCount: state.studentsCount,
|
|
181
170
|
subdomain: state.subdomain,
|
|
182
|
-
teachersCount: state.teachersCount,
|
|
183
171
|
}), [
|
|
184
172
|
state.agreedCurrency,
|
|
185
173
|
state.agreedPrice,
|
|
186
174
|
state.billingDate,
|
|
187
175
|
state.billingInterval,
|
|
188
|
-
state.classesCount,
|
|
189
|
-
state.coursesCount,
|
|
190
176
|
state.description,
|
|
191
177
|
state.dueDateLength,
|
|
192
178
|
state.enabled,
|
|
193
|
-
state.familiesCount,
|
|
194
179
|
state.id,
|
|
195
180
|
state.logo,
|
|
196
181
|
state.name,
|
|
@@ -198,11 +183,7 @@ export const useWorkspaceModule = () => {
|
|
|
198
183
|
state.planId,
|
|
199
184
|
state.planStartDate,
|
|
200
185
|
state.secrets,
|
|
201
|
-
state.staffAccountsCount,
|
|
202
|
-
state.storageUsedMB,
|
|
203
|
-
state.studentsCount,
|
|
204
186
|
state.subdomain,
|
|
205
|
-
state.teachersCount,
|
|
206
187
|
]);
|
|
207
188
|
// ============================================================================
|
|
208
189
|
// 1.5.3 UTILITIES
|
|
@@ -10,13 +10,14 @@ import { useTranslations } from "next-intl";
|
|
|
10
10
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@appcorp/shadcn/components/ui/card";
|
|
11
11
|
import { Badge } from "@appcorp/shadcn/components/ui/badge";
|
|
12
12
|
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
13
|
-
import {
|
|
13
|
+
import { Progress } from "@appcorp/shadcn/components/ui/progress";
|
|
14
|
+
import { Building2, Globe, FileText, Image as LucideImage, CheckCircle2, XCircle, Calendar, CreditCard, Users, GraduationCap, Clock, Shield, } from "lucide-react";
|
|
14
15
|
import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
|
|
15
16
|
import { formatValue } from "@react-pakistan/util-functions/general/format-value";
|
|
16
17
|
import { secretKeys } from "./constants";
|
|
17
18
|
const APP_DOMAIN = process.env.NEXT_PUBLIC_APP_DOMAIN || "edupilotpro.com";
|
|
18
19
|
export const WorkspaceView = () => {
|
|
19
|
-
var _a, _b, _c;
|
|
20
|
+
var _a, _b, _c, _d;
|
|
20
21
|
const { state, workspace } = useWorkspaceModule();
|
|
21
22
|
const t = useTranslations("workspace");
|
|
22
23
|
const appDomain = APP_DOMAIN;
|
|
@@ -39,19 +40,21 @@ export const WorkspaceView = () => {
|
|
|
39
40
|
return "—";
|
|
40
41
|
return interval.charAt(0).toUpperCase() + interval.slice(1).toLowerCase();
|
|
41
42
|
};
|
|
42
|
-
// Helper function to format storage
|
|
43
|
-
const formatStorage = (mb) => {
|
|
44
|
-
if (mb < 1024)
|
|
45
|
-
return `${mb} MB`;
|
|
46
|
-
return `${(mb / 1024).toFixed(1)} GB`;
|
|
47
|
-
};
|
|
48
43
|
return (_jsxs("div", { className: "space-y-6", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Building2, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionBasicInfo") })] }), _jsx(CardDescription, { children: t("viewBasicInfoDescription") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-2 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1 md:col-span-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Building2, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formNameLabel") })] }), _jsx("p", { className: "text-base", children: formatValue(state.name) })] }), _jsxs("div", { className: "space-y-1 md:col-span-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Globe, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formSubdomainLabel") })] }), _jsx("p", { className: "text-base", children: formatValue(state.subdomain) }), state.subdomain && (_jsxs("p", { className: "text-muted-foreground text-sm", children: [t("viewFieldUrlPrefix"), state.subdomain, ".", appDomain] }))] }), _jsxs("div", { className: "space-y-1 md:col-span-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(FileText, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formDescriptionLabel") })] }), _jsx("p", { className: "text-base", children: formatValue(state.description) === "—"
|
|
49
44
|
? t("viewTextDescriptionNotProvided")
|
|
50
45
|
: state.description })] }), state.logo && (_jsxs("div", { className: "space-y-1 md:col-span-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(LucideImage, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formLogoLabel") })] }), _jsx("div", { className: "mt-2", children: _jsx("img", { src: state.logo, alt: t("viewFieldLogoAlt"), width: 64, height: 64, className: "h-16 w-16 rounded border object-contain", onError: (e) => {
|
|
51
46
|
e.currentTarget.style.display = "none";
|
|
52
47
|
} }) })] })), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsxs(Badge, { variant: state.enabled ? "default" : "destructive", className: "gap-1", children: [state.enabled ? (_jsx(CheckCircle2, { className: "h-3 w-3" })) : (_jsx(XCircle, { className: "h-3 w-3" })), state.enabled
|
|
53
48
|
? t("viewStatusEnabled")
|
|
54
|
-
: t("viewStatusDisabled")] })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CreditCard, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionPlanBilling") })] }), _jsx(CardDescription, { children: t("viewPlanBillingDescription") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CreditCard, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldPlanIdLabel") })] }), _jsx("p", { className: "text-base", children: planName })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Calendar, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldPlanStartDateLabel") })] }), _jsx("p", { className: "text-base", children: formatDate(state.planStartDate || "", DATE_FORMATS.LOCALE_DATE) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Calendar, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldPlanEndDateLabel") })] }), _jsx("p", { className: "text-base", children: formatDate(state.planEndDate || "", DATE_FORMATS.LOCALE_DATE) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Clock, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldBillingIntervalLabel") })] }), _jsx("p", { className: "text-base", children: formatBillingInterval(state.billingInterval) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CreditCard, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldAgreedPriceLabel") })] }), _jsx("p", { className: "text-base", children: formatCurrency(state.agreedPrice, state.agreedCurrency) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Globe, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldCurrencyLabel") })] }), _jsx("p", { className: "text-base", children: formatValue(state.agreedCurrency) })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Users, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionUsageStats") })] }), _jsx(CardDescription, { children: t("viewUsageStatsDescription") })] }), _jsx(Separator, {}),
|
|
49
|
+
: t("viewStatusDisabled")] })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CreditCard, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionPlanBilling") })] }), _jsx(CardDescription, { children: t("viewPlanBillingDescription") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6 md:grid-cols-2", children: [_jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CreditCard, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldPlanIdLabel") })] }), _jsx("p", { className: "text-base", children: planName })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Calendar, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldPlanStartDateLabel") })] }), _jsx("p", { className: "text-base", children: formatDate(state.planStartDate || "", DATE_FORMATS.LOCALE_DATE) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Calendar, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldPlanEndDateLabel") })] }), _jsx("p", { className: "text-base", children: formatDate(state.planEndDate || "", DATE_FORMATS.LOCALE_DATE) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Clock, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldBillingIntervalLabel") })] }), _jsx("p", { className: "text-base", children: formatBillingInterval(state.billingInterval) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(CreditCard, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldAgreedPriceLabel") })] }), _jsx("p", { className: "text-base", children: formatCurrency(state.agreedPrice, state.agreedCurrency) })] }), _jsxs("div", { className: "space-y-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Globe, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldCurrencyLabel") })] }), _jsx("p", { className: "text-base", children: formatValue(state.agreedCurrency) })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Users, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionUsageStats") })] }), _jsx(CardDescription, { children: t("viewUsageStatsDescription") })] }), _jsx(Separator, {}), _jsxs(CardContent, { className: "pt-6", children: [_jsxs("div", { className: "flex flex-wrap items-end justify-between gap-4", children: [_jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(GraduationCap, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStudentsLabel") })] }), _jsxs("p", { className: "text-primary mt-1 text-3xl font-bold", children: [state.studentsCount, _jsxs("span", { className: "text-muted-foreground ml-1 text-base font-medium", children: ["/ ", (_d = state.studentLimit) !== null && _d !== void 0 ? _d : t("viewUnlimitedLabel")] })] })] }), _jsx("p", { className: "text-muted-foreground text-sm", children: state.studentLimit === null
|
|
50
|
+
? t("viewUnlimitedDescription")
|
|
51
|
+
: t("viewStudentsRemaining", {
|
|
52
|
+
remaining: Math.max(state.studentLimit - state.studentsCount, 0),
|
|
53
|
+
}) })] }), state.studentLimit !== null && (_jsx(Progress, { className: "mt-4", value: state.studentLimit > 0
|
|
54
|
+
? Math.min(Math.round((state.studentsCount / state.studentLimit) * 100), 100)
|
|
55
|
+
: state.studentsCount > 0
|
|
56
|
+
? 100
|
|
57
|
+
: 0 }))] })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(Shield, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionSecrets") })] }), _jsx(CardDescription, { children: t("viewSecretsDescription") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsx("div", { className: "space-y-4", children: _jsxs("div", { children: [_jsxs("div", { className: "mb-2 flex items-center gap-2", children: [_jsx(Shield, { className: "text-muted-foreground h-4 w-4" }), _jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldSecretsJsonLabel") })] }), state.secrets ? (_jsx("div", { className: "space-y-2", children: visibleSecrets.length === 0 ? (_jsx("p", { className: "text-muted-foreground italic", children: t("viewFieldNoSecretsConfigured") })) : (visibleSecrets.map(([k, v]) => (_jsxs("div", { className: "bg-muted/10 border-border/60 flex items-center justify-between rounded-md border p-3", children: [_jsx("div", { className: "text-foreground text-sm font-medium", children: k }), _jsx("div", { className: "text-foreground/80 text-sm", children: typeof v === "string" && v.length > 0
|
|
55
58
|
? t("viewFieldSecretConfigured")
|
|
56
59
|
: "—" })] }, k)))) })) : (_jsx("p", { className: "text-muted-foreground italic", children: t("viewFieldNoSecretsConfigured") })), _jsx("p", { className: "text-muted-foreground mt-2 text-xs", children: t("viewFieldSecretsHelpText") })] }) }) })] })] }));
|
|
57
60
|
};
|