@appcorp/fusion-storybook 0.2.12 → 0.2.14

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.
Files changed (173) hide show
  1. package/base-modules/admission/context/use-admission-module.d.ts +88 -0
  2. package/base-modules/admission/context/use-admission-module.js +771 -0
  3. package/base-modules/admission/context.d.ts +1 -87
  4. package/base-modules/admission/context.js +3 -769
  5. package/base-modules/admission/filter.d.ts +1 -1
  6. package/base-modules/admission/form.d.ts +1 -1
  7. package/base-modules/admission/more-actions.d.ts +1 -1
  8. package/base-modules/admission/page.d.ts +8 -1
  9. package/base-modules/admission/page.js +25 -4
  10. package/base-modules/admission/view.d.ts +1 -1
  11. package/base-modules/attendance/form.d.ts +1 -1
  12. package/base-modules/attendance/page.d.ts +8 -1
  13. package/base-modules/attendance/page.js +25 -4
  14. package/base-modules/attendance/view.d.ts +1 -1
  15. package/base-modules/campus/filter.d.ts +1 -1
  16. package/base-modules/campus/form.d.ts +1 -1
  17. package/base-modules/campus/more-actions.d.ts +1 -1
  18. package/base-modules/campus/more-actions.js +0 -1
  19. package/base-modules/campus/page.d.ts +8 -1
  20. package/base-modules/campus/page.js +25 -4
  21. package/base-modules/campus/view.d.ts +1 -1
  22. package/base-modules/class/filter.d.ts +1 -1
  23. package/base-modules/class/form.d.ts +1 -1
  24. package/base-modules/class/more-actions.d.ts +1 -1
  25. package/base-modules/class/more-actions.js +1 -6
  26. package/base-modules/class/page.d.ts +8 -1
  27. package/base-modules/class/page.js +25 -4
  28. package/base-modules/class/view.d.ts +1 -1
  29. package/base-modules/course/filter.d.ts +1 -1
  30. package/base-modules/course/form.d.ts +1 -1
  31. package/base-modules/course/more-actions.d.ts +1 -1
  32. package/base-modules/course/page.d.ts +8 -1
  33. package/base-modules/course/page.js +25 -4
  34. package/base-modules/course/view.d.ts +1 -1
  35. package/base-modules/discount-code/filter.d.ts +2 -1
  36. package/base-modules/discount-code/form.d.ts +1 -1
  37. package/base-modules/discount-code/page.d.ts +8 -1
  38. package/base-modules/discount-code/page.js +25 -4
  39. package/base-modules/discount-code/view.d.ts +1 -1
  40. package/base-modules/enrollment/filter.d.ts +1 -1
  41. package/base-modules/enrollment/form.d.ts +1 -1
  42. package/base-modules/enrollment/more-actions.d.ts +1 -1
  43. package/base-modules/enrollment/page.d.ts +8 -1
  44. package/base-modules/enrollment/page.js +25 -4
  45. package/base-modules/enrollment/view.d.ts +1 -1
  46. package/base-modules/expense/filter.d.ts +1 -1
  47. package/base-modules/expense/form.d.ts +1 -1
  48. package/base-modules/expense/more-actions.d.ts +1 -1
  49. package/base-modules/expense/more-actions.js +1 -6
  50. package/base-modules/expense/page.d.ts +8 -1
  51. package/base-modules/expense/page.js +25 -4
  52. package/base-modules/expense/view.d.ts +1 -1
  53. package/base-modules/family/filter.d.ts +1 -1
  54. package/base-modules/family/form.d.ts +1 -1
  55. package/base-modules/family/more-actions.d.ts +1 -1
  56. package/base-modules/family/page.d.ts +8 -1
  57. package/base-modules/family/page.js +25 -4
  58. package/base-modules/family/view.d.ts +1 -1
  59. package/base-modules/family-member/filter.d.ts +1 -1
  60. package/base-modules/family-member/form.d.ts +1 -1
  61. package/base-modules/family-member/more-actions.d.ts +1 -1
  62. package/base-modules/family-member/page.d.ts +8 -1
  63. package/base-modules/family-member/page.js +25 -4
  64. package/base-modules/family-member/view.d.ts +1 -1
  65. package/base-modules/fee-structure/filter.d.ts +1 -1
  66. package/base-modules/fee-structure/form.d.ts +1 -1
  67. package/base-modules/fee-structure/more-actions.d.ts +1 -1
  68. package/base-modules/fee-structure/more-actions.js +1 -6
  69. package/base-modules/fee-structure/page.d.ts +8 -1
  70. package/base-modules/fee-structure/page.js +25 -4
  71. package/base-modules/fee-structure/view.d.ts +1 -1
  72. package/base-modules/rbac/assign-permissions.d.ts +1 -1
  73. package/base-modules/rbac/filter.d.ts +1 -1
  74. package/base-modules/rbac/form.d.ts +1 -1
  75. package/base-modules/rbac/more-actions.d.ts +1 -1
  76. package/base-modules/rbac/page.d.ts +8 -1
  77. package/base-modules/rbac/page.js +25 -4
  78. package/base-modules/rbac/view.d.ts +7 -1
  79. package/base-modules/school/drawer.d.ts +1 -1
  80. package/base-modules/school/filter.d.ts +1 -1
  81. package/base-modules/school/form.d.ts +1 -1
  82. package/base-modules/school/more-actions.d.ts +1 -1
  83. package/base-modules/school/view.d.ts +1 -1
  84. package/base-modules/section/filter.d.ts +1 -1
  85. package/base-modules/section/form.d.ts +1 -1
  86. package/base-modules/section/more-actions.d.ts +1 -1
  87. package/base-modules/section/page.d.ts +8 -1
  88. package/base-modules/section/page.js +25 -4
  89. package/base-modules/section/view.d.ts +1 -1
  90. package/base-modules/student-fee/context/shared.d.ts +178 -0
  91. package/base-modules/student-fee/context/shared.js +59 -0
  92. package/base-modules/student-fee/context/use-student-fee-module.d.ts +64 -0
  93. package/base-modules/student-fee/context/use-student-fee-module.js +610 -0
  94. package/base-modules/student-fee/context.d.ts +21 -235
  95. package/base-modules/student-fee/context.js +2 -674
  96. package/base-modules/student-fee/filter.d.ts +1 -1
  97. package/base-modules/student-fee/form.d.ts +1 -1
  98. package/base-modules/student-fee/more-actions.d.ts +1 -1
  99. package/base-modules/student-fee/more-actions.js +1 -6
  100. package/base-modules/student-fee/page.d.ts +8 -1
  101. package/base-modules/student-fee/page.js +25 -4
  102. package/base-modules/student-fee/view.d.ts +1 -1
  103. package/base-modules/student-profile/context/module-base.d.ts +187 -0
  104. package/base-modules/student-profile/context/module-base.js +50 -0
  105. package/base-modules/student-profile/context/use-student-profile-module.d.ts +70 -0
  106. package/base-modules/student-profile/context/use-student-profile-module.js +506 -0
  107. package/base-modules/student-profile/context.d.ts +20 -256
  108. package/base-modules/student-profile/context.js +2 -601
  109. package/base-modules/student-profile/filter.d.ts +1 -1
  110. package/base-modules/student-profile/form.d.ts +1 -1
  111. package/base-modules/student-profile/more-actions.d.ts +1 -1
  112. package/base-modules/student-profile/page.d.ts +8 -1
  113. package/base-modules/student-profile/page.js +25 -4
  114. package/base-modules/student-profile/view.d.ts +1 -1
  115. package/base-modules/subject/filter.d.ts +1 -1
  116. package/base-modules/subject/form.d.ts +1 -1
  117. package/base-modules/subject/more-actions.d.ts +1 -1
  118. package/base-modules/subject/page.d.ts +8 -1
  119. package/base-modules/subject/page.js +25 -4
  120. package/base-modules/subject/view.d.ts +1 -1
  121. package/base-modules/teacher/avatar-upload.js +1 -4
  122. package/base-modules/teacher/filter.d.ts +1 -1
  123. package/base-modules/teacher/form.d.ts +1 -1
  124. package/base-modules/teacher/more-actions.d.ts +1 -1
  125. package/base-modules/teacher/more-actions.js +1 -6
  126. package/base-modules/teacher/page.d.ts +8 -1
  127. package/base-modules/teacher/page.js +25 -4
  128. package/base-modules/teacher/view.d.ts +1 -1
  129. package/base-modules/user/context/use-user-module.d.ts +53 -0
  130. package/base-modules/user/context/use-user-module.js +546 -0
  131. package/base-modules/user/context.d.ts +1 -52
  132. package/base-modules/user/context.js +5 -547
  133. package/base-modules/user/drawer.d.ts +1 -1
  134. package/base-modules/user/filter.d.ts +1 -1
  135. package/base-modules/user/form.d.ts +1 -1
  136. package/base-modules/user/more-actions.d.ts +1 -1
  137. package/base-modules/user/page.d.ts +8 -1
  138. package/base-modules/user/page.js +25 -4
  139. package/base-modules/user/view.d.ts +1 -1
  140. package/base-modules/workspace/context.d.ts +1 -1
  141. package/base-modules/workspace/drawer.d.ts +1 -1
  142. package/base-modules/workspace/filter.d.ts +1 -1
  143. package/base-modules/workspace/form.d.ts +1 -1
  144. package/base-modules/workspace/more-actions.d.ts +1 -1
  145. package/base-modules/workspace/view.d.ts +1 -1
  146. package/base-modules/workspace-user/filter.d.ts +1 -1
  147. package/base-modules/workspace-user/form.d.ts +1 -1
  148. package/base-modules/workspace-user/more-actions.d.ts +1 -1
  149. package/base-modules/workspace-user/more-actions.js +1 -6
  150. package/base-modules/workspace-user/page.d.ts +8 -1
  151. package/base-modules/workspace-user/page.js +25 -4
  152. package/base-modules/workspace-user/view.d.ts +1 -1
  153. package/components/module-error.d.ts +9 -0
  154. package/components/module-error.js +3 -0
  155. package/components/timeline.d.ts +1 -1
  156. package/package.json +6 -5
  157. package/tsconfig.build.tsbuildinfo +1 -1
  158. package/type.d.ts +3 -1242
  159. package/type.js +3 -445
  160. package/types/academics.d.ts +264 -0
  161. package/types/academics.js +8 -0
  162. package/types/admission.d.ts +85 -0
  163. package/types/admission.js +6 -0
  164. package/types/communication.d.ts +165 -0
  165. package/types/communication.js +7 -0
  166. package/types/enums.d.ts +411 -0
  167. package/types/enums.js +442 -0
  168. package/types/finance.d.ts +126 -0
  169. package/types/finance.js +7 -0
  170. package/types/index.d.ts +12 -0
  171. package/types/index.js +12 -0
  172. package/types/user-management.d.ts +236 -0
  173. package/types/user-management.js +7 -0
@@ -17,25 +17,9 @@
17
17
  * - `USER_DRAWER` — drawer type constants
18
18
  * - `useUserModule()` — hook that returns state, dispatch, and handlers
19
19
  */
20
- import { useCallback, useEffect, useMemo, useRef } from "react";
21
- import { useTheme } from "next-themes";
22
- import { useTranslations } from "next-intl";
23
- import { isCreatedOrUpdated, validateForm, API_METHODS, fetchData, } from "@react-pakistan/util-functions";
24
- import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
25
- import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
26
20
  import { createGenericModule } from "@react-pakistan/util-functions/factory/generic-module-factory";
27
21
  import { DRAWER_TYPES } from "@react-pakistan/util-functions/factory/generic-component-factory";
28
- import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
29
- import { USER_API_ROUTES, pageLimit } from "./constants";
30
- import { userFormValidation } from "./validate";
31
- import { getCachedUsers, invalidateUsersCache } from "./cache";
32
- import { getCachedWorkspaceSync } from "../workspace/cache";
33
- import { invalidateWorkspaceUsersCache } from "../workspace-user/cache";
34
- import { blobToWebP } from "webp-converter-browser";
35
- import { supabasePublicStorageUrl } from "../../constants";
36
- import { toastNetworkError } from "../../utils/toast-network-error";
37
- import { formatNumber } from "@react-pakistan/util-functions/general/format-number";
38
- import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
22
+ import { pageLimit } from "./constants";
39
23
  // ============================================================================
40
24
  // 1.1 DRAWER TYPES
41
25
  // ============================================================================
@@ -45,6 +29,9 @@ export const USER_DRAWER = {
45
29
  MORE_ACTIONS_DRAWER: DRAWER_TYPES.MORE_ACTIONS_DRAWER,
46
30
  VIEW_DRAWER: DRAWER_TYPES.VIEW_DRAWER,
47
31
  };
32
+ // ============================================================================
33
+ // 1.2 MODULE CONFIGURATION
34
+ // ============================================================================
48
35
  const userConfig = {
49
36
  name: "User",
50
37
  displayName: "User",
@@ -78,533 +65,4 @@ const userConfig = {
78
65
  // 1.3 CREATE USER MODULE
79
66
  // ============================================================================
80
67
  export const { actionTypes: USER_ACTION_TYPES, config: userModuleConfig, initialState: initialUserState, Provider: UserProvider, reducer: userReducer, useContext: useUserContext, } = createGenericModule(userConfig);
81
- // ============================================================================
82
- // 1.4 ENHANCED USER HOOK WITH API INTEGRATION
83
- // ============================================================================
84
- export const useUserModule = () => {
85
- // ============================================================================
86
- // 1.4.1 STATE & CORE HOOKS
87
- // ============================================================================
88
- const context = useUserContext();
89
- const { dispatch } = context;
90
- const state = context.state;
91
- const t = useTranslations("user");
92
- const { theme } = useTheme();
93
- const workspace = getCachedWorkspaceSync();
94
- const listFetchNowRef = useRef(null);
95
- const debouncedQuery = useDebounce(state.searchQuery, 800);
96
- // ============================================================================
97
- // 1.4.2 API PARAMETERS
98
- // ============================================================================
99
- const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, workspaceId: (workspace === null || workspace === void 0 ? void 0 : workspace.id) || "" }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
100
- ? { filterEnabled: String(state.filterEnabled) }
101
- : {}))), [
102
- state.currentPage,
103
- state.filterEnabled,
104
- state.pageLimit,
105
- debouncedQuery,
106
- workspace === null || workspace === void 0 ? void 0 : workspace.id,
107
- ]);
108
- const updateParams = useMemo(() => ({
109
- avatar: state.avatar,
110
- email: (state.email || "").trim(),
111
- enabled: state.enabled,
112
- id: state.id,
113
- name: (state.name || "").trim(),
114
- password: state.password,
115
- phone: formatNumber(state.phone),
116
- userRole: state.userRole,
117
- workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id,
118
- }), [state, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
119
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
120
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
121
- const isDefaultListState = state.currentPage === 1 &&
122
- state.pageLimit === pageLimit &&
123
- !debouncedQuery &&
124
- state.filterEnabled === undefined;
125
- // ============================================================================
126
- // 1.4.3 UTILITIES
127
- // ============================================================================
128
- const showToast = useCallback((description, variant) => {
129
- generateThemeToast({
130
- description,
131
- theme: theme,
132
- variant,
133
- });
134
- }, [theme]);
135
- const resetFormAndCloseDrawer = useCallback(() => {
136
- dispatch({ type: USER_ACTION_TYPES.RESET_FORM });
137
- dispatch({
138
- type: USER_ACTION_TYPES.SET_ERRORS,
139
- payload: { errors: {} },
140
- });
141
- dispatch({
142
- type: USER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
143
- payload: { disabled: false },
144
- });
145
- dispatch({
146
- type: USER_ACTION_TYPES.SET_DRAWER,
147
- payload: { drawer: null },
148
- });
149
- }, [dispatch]);
150
- // ============================================================================
151
- // 1.4.4 API CALLBACKS
152
- // ============================================================================
153
- const listCallback = useCallback(({ data, error }) => {
154
- var _a, _b;
155
- if (error) {
156
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
157
- return;
158
- }
159
- if (data) {
160
- const response = data;
161
- dispatch({
162
- type: USER_ACTION_TYPES.SET_ITEMS,
163
- payload: { items: (_a = response.items) !== null && _a !== void 0 ? _a : [], count: (_b = response.count) !== null && _b !== void 0 ? _b : 0 },
164
- });
165
- }
166
- }, [dispatch, showToast, t]);
167
- const updateCallback = useCallback(({ data, error }) => {
168
- var _a;
169
- if (error) {
170
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
171
- return;
172
- }
173
- if (data) {
174
- const isCreated = isCreatedOrUpdated(data);
175
- invalidateUsersCache();
176
- invalidateWorkspaceUsersCache();
177
- showToast(isCreated ? t("messagesUserCreated") : t("messagesUserUpdated"), TOAST_VARIANT.SUCCESS);
178
- resetFormAndCloseDrawer();
179
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
180
- }
181
- }, [resetFormAndCloseDrawer, showToast, t]);
182
- const byIdCallback = useCallback(({ data, error }) => {
183
- var _a;
184
- if (error) {
185
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
186
- return;
187
- }
188
- if (data) {
189
- const user = data;
190
- const maybeWithWorkspaces = data;
191
- const wsEntry = (_a = maybeWithWorkspaces.workspaces) === null || _a === void 0 ? void 0 : _a.find((ws) => ws.workspaceId === (workspace === null || workspace === void 0 ? void 0 : workspace.id));
192
- let roleValue = null;
193
- if (wsEntry && wsEntry.role !== undefined && wsEntry.role !== null) {
194
- const r = wsEntry.role;
195
- if (typeof r === "string") {
196
- roleValue = r;
197
- }
198
- else if (typeof r === "object" && r !== null) {
199
- roleValue =
200
- r.userRole ||
201
- r.name ||
202
- null;
203
- }
204
- }
205
- const parsedUserRole = roleValue || null;
206
- dispatch({
207
- type: USER_ACTION_TYPES.SET_FORM_DATA,
208
- payload: {
209
- form: {
210
- id: user.id,
211
- name: user.name || "",
212
- email: user.email,
213
- phone: formatPhoneDisplay(user.phone) || "",
214
- avatar: user.avatar || "",
215
- enabled: user.enabled,
216
- userRole: parsedUserRole,
217
- password: "",
218
- },
219
- },
220
- });
221
- }
222
- }, [dispatch, showToast, t, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
223
- const deleteCallback = useCallback(({ data, error }) => {
224
- var _a;
225
- if (error) {
226
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
227
- return;
228
- }
229
- if (data) {
230
- invalidateUsersCache();
231
- invalidateWorkspaceUsersCache();
232
- showToast(t("messagesUserDeleted"), TOAST_VARIANT.SUCCESS);
233
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
234
- }
235
- }, [showToast, t]);
236
- // ============================================================================
237
- // 1.4.5 API HOOKS
238
- // ============================================================================
239
- const { byIdFetchNow, byIdLoading, deleteFetchNow, deleteLoading, listFetchNow, listLoading, updateFetchNow, updateLoading, } = useModuleEntityV2({
240
- byIdCallback,
241
- byIdParams,
242
- deleteCallback,
243
- deleteParams,
244
- listCallback,
245
- listParams,
246
- listUrl: USER_API_ROUTES.LIST,
247
- searchQuery: debouncedQuery,
248
- unitByIdUrl: USER_API_ROUTES.UNIT,
249
- unitUrl: USER_API_ROUTES.UNIT,
250
- updateCallback,
251
- updateParams,
252
- headers: {
253
- "Content-Type": "application/json",
254
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
255
- },
256
- });
257
- // ============================================================================
258
- // 1.4.6 HANDLERS
259
- // ============================================================================
260
- const handleChange = useCallback((field, value) => {
261
- dispatch({
262
- type: USER_ACTION_TYPES.SET_ERRORS,
263
- payload: { errors: {} },
264
- });
265
- dispatch({
266
- type: USER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
267
- payload: { disabled: false },
268
- });
269
- const normalized = field === "email" && typeof value === "string"
270
- ? value.toLowerCase()
271
- : value;
272
- dispatch({
273
- type: USER_ACTION_TYPES.SET_INPUT_FIELD,
274
- payload: {
275
- key: field,
276
- value: normalized,
277
- },
278
- });
279
- }, [dispatch]);
280
- const closeDrawer = useCallback(() => {
281
- resetFormAndCloseDrawer();
282
- }, [resetFormAndCloseDrawer]);
283
- const handleCreate = useCallback(() => {
284
- dispatch({
285
- type: USER_ACTION_TYPES.SET_DRAWER,
286
- payload: { drawer: USER_DRAWER.FORM_DRAWER },
287
- });
288
- }, [dispatch]);
289
- const handleView = useCallback((row) => {
290
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
291
- dispatch({
292
- type: USER_ACTION_TYPES.SET_DRAWER,
293
- payload: { drawer: USER_DRAWER.VIEW_DRAWER },
294
- });
295
- }, [byIdFetchNow, dispatch]);
296
- const handleEdit = useCallback((row) => {
297
- byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
298
- dispatch({
299
- type: USER_ACTION_TYPES.SET_DRAWER,
300
- payload: { drawer: USER_DRAWER.FORM_DRAWER },
301
- });
302
- }, [byIdFetchNow, dispatch]);
303
- const handleDelete = useCallback((row) => {
304
- if (!confirm(t("messagesDeleteConfirmation")))
305
- return;
306
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
307
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
308
- });
309
- }, [deleteFetchNow, t]);
310
- const handleFilters = useCallback(() => {
311
- dispatch({
312
- type: USER_ACTION_TYPES.SET_DRAWER,
313
- payload: { drawer: USER_DRAWER.FILTER_DRAWER },
314
- });
315
- }, [dispatch]);
316
- const handleMoreActions = useCallback(() => {
317
- dispatch({
318
- type: USER_ACTION_TYPES.SET_DRAWER,
319
- payload: { drawer: USER_DRAWER.MORE_ACTIONS_DRAWER },
320
- });
321
- }, [dispatch]);
322
- const handlePageChange = useCallback((page) => {
323
- const nextPage = typeof page === "number" ? page : state.currentPage + 1;
324
- dispatch({
325
- type: USER_ACTION_TYPES.SET_CURRENT_PAGE,
326
- payload: { currentPage: nextPage },
327
- });
328
- }, [dispatch, state.currentPage]);
329
- const handlePageLimitChange = useCallback((k, value) => {
330
- const val = Object.assign({}, value);
331
- dispatch({
332
- type: USER_ACTION_TYPES.SET_PAGE_LIMIT,
333
- payload: { pageLimit: Number(val.option) },
334
- });
335
- dispatch({
336
- type: USER_ACTION_TYPES.SET_CURRENT_PAGE,
337
- payload: { currentPage: 1 },
338
- });
339
- }, [dispatch]);
340
- const handleSearch = useCallback((query) => {
341
- dispatch({
342
- type: USER_ACTION_TYPES.SET_SEARCH_QUERY,
343
- payload: { searchQuery: query },
344
- });
345
- }, [dispatch]);
346
- const clearSearch = useCallback(() => {
347
- dispatch({
348
- type: USER_ACTION_TYPES.SET_SEARCH_QUERY,
349
- payload: { searchQuery: "" },
350
- });
351
- }, [dispatch]);
352
- const handleAvatar = useCallback((files) => {
353
- if (!files || files.length === 0)
354
- return;
355
- const file = files[0];
356
- const blob = new Blob([file], { type: file.type });
357
- const url = URL.createObjectURL(blob);
358
- dispatch({
359
- type: USER_ACTION_TYPES.SET_INPUT_FIELD,
360
- payload: { key: "avatar", value: url },
361
- });
362
- }, [dispatch]);
363
- const applyFilters = useCallback(() => {
364
- dispatch({
365
- type: USER_ACTION_TYPES.SET_CURRENT_PAGE,
366
- payload: { currentPage: 1 },
367
- });
368
- closeDrawer();
369
- }, [dispatch, closeDrawer]);
370
- const clearFilters = useCallback(() => {
371
- dispatch({
372
- type: USER_ACTION_TYPES.SET_FILTERS,
373
- payload: { filters: { filterEnabled: undefined } },
374
- });
375
- dispatch({
376
- type: USER_ACTION_TYPES.SET_CURRENT_PAGE,
377
- payload: { currentPage: 1 },
378
- });
379
- }, [dispatch]);
380
- const toggleStatus = useCallback((row) => {
381
- updateFetchNow(undefined, {
382
- body: JSON.stringify(Object.assign(Object.assign({}, row), { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id, enabled: !(row === null || row === void 0 ? void 0 : row.enabled) })),
383
- });
384
- }, [updateFetchNow, workspace === null || workspace === void 0 ? void 0 : workspace.id]);
385
- // ============================================================================
386
- // 1.4.7 NETWORK ACTIONS
387
- // ============================================================================
388
- const handleUploadImage = useCallback(async () => {
389
- var _a;
390
- if (!((_a = state.avatar) === null || _a === void 0 ? void 0 : _a.startsWith("blob:")))
391
- return undefined;
392
- const fileRef = `${workspace === null || workspace === void 0 ? void 0 : workspace.id}/${updateParams.id}/avatar/${updateParams.id}.webp`;
393
- try {
394
- const blob = await fetch(state.avatar).then((r) => r.blob());
395
- const webpBlob = await blobToWebP(blob, { quality: 0.8 });
396
- const arrayBuffer = await webpBlob.arrayBuffer();
397
- let binary = "";
398
- const bytes = new Uint8Array(arrayBuffer);
399
- const chunkSize = 0x8000;
400
- for (let i = 0; i < bytes.length; i += chunkSize) {
401
- const sub = bytes.subarray(i, i + chunkSize);
402
- for (let j = 0; j < sub.length; j++) {
403
- binary += String.fromCharCode(sub[j]);
404
- }
405
- }
406
- const base64 = btoa(binary);
407
- const res = await fetch("/api/uploads/avatar", {
408
- method: "POST",
409
- headers: { "Content-Type": "application/json" },
410
- body: JSON.stringify({
411
- fileBase64: base64,
412
- fileRef,
413
- contentType: webpBlob.type,
414
- }),
415
- });
416
- if (!res.ok)
417
- throw new Error("Upload failed");
418
- const responseData = await res.json();
419
- if (responseData === null || responseData === void 0 ? void 0 : responseData.path) {
420
- const url = `${supabasePublicStorageUrl}/${responseData.path}`;
421
- dispatch({
422
- type: USER_ACTION_TYPES.SET_INPUT_FIELD,
423
- payload: { key: "avatar", value: url },
424
- });
425
- return url;
426
- }
427
- }
428
- catch (_b) {
429
- toastNetworkError();
430
- }
431
- return undefined;
432
- }, [state.avatar, dispatch, workspace === null || workspace === void 0 ? void 0 : workspace.id, updateParams.id]);
433
- const checkUserEmailExists = useCallback(async (emailParam) => {
434
- var _a;
435
- const targetEmail = (typeof emailParam === "string" && emailParam) || state.email;
436
- if (!targetEmail)
437
- return null;
438
- const result = await fetchData({
439
- url: `${USER_API_ROUTES.UNIT_BY_EMAIL}?email=${encodeURIComponent(String(targetEmail))}`,
440
- method: API_METHODS.GET,
441
- headers: {
442
- "x-api-token": process.env.NEXT_PUBLIC_API_KEY,
443
- },
444
- });
445
- return (_a = result === null || result === void 0 ? void 0 : result.data) !== null && _a !== void 0 ? _a : null;
446
- }, [state.email]);
447
- const handleSubmit = useCallback(async () => {
448
- dispatch({
449
- type: USER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
450
- payload: { disabled: true },
451
- });
452
- const uploadedUrl = await handleUploadImage();
453
- const finalParams = uploadedUrl
454
- ? Object.assign(Object.assign({}, updateParams), { avatar: uploadedUrl }) : updateParams;
455
- validateForm({
456
- params: finalParams,
457
- schema: userFormValidation,
458
- successCallback: async () => {
459
- try {
460
- const existing = await checkUserEmailExists(state.email);
461
- if (existing &&
462
- existing.id &&
463
- existing.id !== state.id) {
464
- dispatch({
465
- type: USER_ACTION_TYPES.SET_ERRORS,
466
- payload: { errors: { email: t("messagesEmailAlreadyInUse") } },
467
- });
468
- dispatch({
469
- type: USER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
470
- payload: { disabled: false },
471
- });
472
- return;
473
- }
474
- updateFetchNow(undefined, { body: JSON.stringify(finalParams) });
475
- }
476
- catch (_a) {
477
- toastNetworkError();
478
- dispatch({
479
- type: USER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
480
- payload: { disabled: false },
481
- });
482
- }
483
- },
484
- errorCallback: (errors) => {
485
- dispatch({
486
- type: USER_ACTION_TYPES.SET_ERRORS,
487
- payload: { errors },
488
- });
489
- dispatch({
490
- type: USER_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
491
- payload: { disabled: false },
492
- });
493
- showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
494
- },
495
- });
496
- }, [
497
- checkUserEmailExists,
498
- dispatch,
499
- handleUploadImage,
500
- showToast,
501
- state.email,
502
- state.id,
503
- t,
504
- updateFetchNow,
505
- updateParams,
506
- ]);
507
- // ============================================================================
508
- // 1.4.8 HEADER & ROW ACTIONS
509
- // ============================================================================
510
- const headerActions = useMemo(() => [
511
- {
512
- enabled: false,
513
- handleOnClick: handleMoreActions,
514
- label: t("actionsButtonMoreActions"),
515
- order: 0,
516
- },
517
- {
518
- enabled: false,
519
- handleOnClick: handleFilters,
520
- label: t("actionsButtonFilters"),
521
- order: 1,
522
- },
523
- {
524
- enabled: true,
525
- handleOnClick: handleCreate,
526
- label: t("actionsButtonAdd"),
527
- order: 2,
528
- },
529
- ], [handleCreate, handleFilters, handleMoreActions, t]);
530
- const rowActions = useMemo(() => [
531
- {
532
- enabled: true,
533
- handleOnClick: handleView,
534
- label: t("actionsButtonView"),
535
- order: 1,
536
- },
537
- {
538
- enabled: true,
539
- handleOnClick: handleEdit,
540
- label: t("actionsButtonEdit"),
541
- order: 2,
542
- },
543
- {
544
- enabled: false,
545
- handleOnClick: handleDelete,
546
- label: t("actionsButtonDelete"),
547
- order: 3,
548
- },
549
- {
550
- enabled: false,
551
- handleOnClick: toggleStatus,
552
- label: t("actionsButtonToggleStatus"),
553
- order: 4,
554
- },
555
- ], [handleDelete, handleEdit, handleView, t, toggleStatus]);
556
- // ============================================================================
557
- // 1.4.9 EFFECTS
558
- // ============================================================================
559
- useEffect(() => {
560
- var _a;
561
- if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id))
562
- return;
563
- if (isDefaultListState) {
564
- (async () => {
565
- try {
566
- const { count, items } = await getCachedUsers({ params: listParams });
567
- dispatch({
568
- type: USER_ACTION_TYPES.SET_ITEMS,
569
- payload: { items: items || [], count: count || 0 },
570
- });
571
- }
572
- catch (_a) {
573
- showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
574
- }
575
- })();
576
- return;
577
- }
578
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
579
- }, [dispatch, isDefaultListState, listParams, workspace === null || workspace === void 0 ? void 0 : workspace.id, showToast, t]);
580
- useEffect(() => {
581
- listFetchNowRef.current = listFetchNow;
582
- }, [listFetchNow]);
583
- // ============================================================================
584
- // 1.4.10 RETURN
585
- // ============================================================================
586
- return Object.assign(Object.assign({}, context), { applyFilters,
587
- byIdLoading,
588
- clearFilters,
589
- clearSearch,
590
- closeDrawer,
591
- deleteLoading,
592
- handleAvatar,
593
- handleChange,
594
- handleCreate,
595
- handleDelete,
596
- handleEdit,
597
- handleFilters,
598
- handleMoreActions,
599
- handlePageChange,
600
- handlePageLimitChange,
601
- handleSearch,
602
- handleSubmit,
603
- handleView,
604
- headerActions,
605
- listFetchNow,
606
- listLoading,
607
- rowActions,
608
- toggleStatus,
609
- updateLoading });
610
- };
68
+ export { useUserModule } from "./context/use-user-module";
@@ -1 +1 @@
1
- export declare const Drawer: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const Drawer: () => import("react").JSX.Element;
@@ -1 +1 @@
1
- export declare const UserFilter: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const UserFilter: () => import("react").JSX.Element;
@@ -1 +1 @@
1
- export declare const UserForm: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const UserForm: () => import("react").JSX.Element;
@@ -1 +1 @@
1
- export declare const UserMoreActions: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const UserMoreActions: () => import("react").JSX.Element;
@@ -19,7 +19,14 @@ import { FC } from "react";
19
19
  import { USER_ROLE } from "../../type";
20
20
  interface Props {
21
21
  cancelLabel: string;
22
- drawerTitle: string;
22
+ drawerFilterDescription: string;
23
+ drawerFilterTitle: string;
24
+ drawerFormDescription: string;
25
+ drawerFormTitle: string;
26
+ drawerMoreActionsDescription: string;
27
+ drawerMoreActionsTitle: string;
28
+ drawerViewDescription: string;
29
+ drawerViewTitle: string;
23
30
  labelActions: string;
24
31
  labelEmail: string;
25
32
  labelEnabled: string;
@@ -47,7 +47,7 @@ const createComponentInstances = () => ({
47
47
  moreActions: _jsx(UserMoreActions, {}),
48
48
  view: _jsx(UserView, {}),
49
49
  });
50
- const createUserConfig = ({ cancelLabel, dispatch, drawerTitle, labelActions, labelEmail, labelEnabled, labelId, labelName, labelPhone, saveLabel, searchPlaceholder, tableDescription, tableTitle, }) => {
50
+ const createUserConfig = ({ cancelLabel, dispatch, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, labelActions, labelEmail, labelEnabled, labelId, labelName, labelPhone, saveLabel, searchPlaceholder, tableDescription, tableTitle, }) => {
51
51
  const components = createComponentInstances();
52
52
  return {
53
53
  moduleName: "user",
@@ -60,7 +60,14 @@ const createUserConfig = ({ cancelLabel, dispatch, drawerTitle, labelActions, la
60
60
  { label: labelActions, width: "5%" },
61
61
  ],
62
62
  cancelLabel,
63
- drawerTitle,
63
+ drawerFilterDescription,
64
+ drawerFilterTitle,
65
+ drawerFormDescription,
66
+ drawerFormTitle,
67
+ drawerMoreActionsDescription,
68
+ drawerMoreActionsTitle,
69
+ drawerViewDescription,
70
+ drawerViewTitle,
64
71
  filterContent: components.filter,
65
72
  formContent: components.form,
66
73
  moreActionsContent: components.moreActions,
@@ -83,7 +90,14 @@ const UserPageInner = (props) => {
83
90
  const userConfig = useMemo(() => createUserConfig({
84
91
  dispatch: context.dispatch,
85
92
  cancelLabel: props.cancelLabel,
86
- drawerTitle: props.drawerTitle,
93
+ drawerFormTitle: props.drawerFormTitle,
94
+ drawerFormDescription: props.drawerFormDescription,
95
+ drawerViewTitle: props.drawerViewTitle,
96
+ drawerViewDescription: props.drawerViewDescription,
97
+ drawerFilterTitle: props.drawerFilterTitle,
98
+ drawerFilterDescription: props.drawerFilterDescription,
99
+ drawerMoreActionsTitle: props.drawerMoreActionsTitle,
100
+ drawerMoreActionsDescription: props.drawerMoreActionsDescription,
87
101
  labelActions: props.labelActions,
88
102
  labelEmail: props.labelEmail,
89
103
  labelEnabled: props.labelEnabled,
@@ -97,7 +111,14 @@ const UserPageInner = (props) => {
97
111
  }), [
98
112
  context.dispatch,
99
113
  props.cancelLabel,
100
- props.drawerTitle,
114
+ props.drawerFormTitle,
115
+ props.drawerFormDescription,
116
+ props.drawerViewTitle,
117
+ props.drawerViewDescription,
118
+ props.drawerFilterTitle,
119
+ props.drawerFilterDescription,
120
+ props.drawerMoreActionsTitle,
121
+ props.drawerMoreActionsDescription,
101
122
  props.labelActions,
102
123
  props.labelEmail,
103
124
  props.labelEnabled,
@@ -1 +1 @@
1
- export declare const UserView: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const UserView: () => import("react").JSX.Element;
@@ -155,7 +155,7 @@ type Plan = {
155
155
  };
156
156
  export declare const WorkspaceStateContextProvider: ({ children, }: {
157
157
  children: React.ReactNode;
158
- }) => import("react/jsx-runtime").JSX.Element;
158
+ }) => import("react").JSX.Element;
159
159
  export declare const useWorkspaceModule: () => {
160
160
  handleChange: (field: string, value: string | number | boolean | undefined | Record<string, string>) => void;
161
161
  handleCloseDrawer: () => void;
@@ -1 +1 @@
1
- export declare const WorkspaceDrawer: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const WorkspaceDrawer: () => import("react").JSX.Element;
@@ -1 +1 @@
1
- export declare const WorkspaceFilter: () => import("react/jsx-runtime").JSX.Element;
1
+ export declare const WorkspaceFilter: () => import("react").JSX.Element;