@redacto.io/consent-sdk-react 3.4.0 → 3.6.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.
Files changed (155) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +176 -0
  3. package/dist/index.d.mts +51 -4
  4. package/dist/index.d.ts +51 -4
  5. package/dist/index.js +1912 -345
  6. package/dist/index.mjs +1911 -345
  7. package/dist/privacy-center.d.mts +566 -0
  8. package/dist/privacy-center.d.ts +566 -0
  9. package/dist/privacy-center.js +17174 -0
  10. package/dist/privacy-center.mjs +17136 -0
  11. package/package.json +47 -3
  12. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +201 -118
  13. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +1194 -93
  14. package/src/RedactoNoticeConsent/api/index.ts +337 -246
  15. package/src/RedactoNoticeConsent/api/types.ts +140 -41
  16. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +602 -0
  17. package/src/RedactoNoticeConsent/components/index.ts +7 -0
  18. package/src/RedactoNoticeConsent/injectStyles.ts +11 -0
  19. package/src/RedactoNoticeConsent/language-codes.ts +61 -0
  20. package/src/RedactoNoticeConsent/services/storage.ts +122 -0
  21. package/src/RedactoNoticeConsent/types.ts +2 -0
  22. package/src/RedactoNoticeConsentInline/api/index.ts +26 -64
  23. package/src/RedactoNoticeConsentInline/api/types.ts +0 -25
  24. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
  25. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
  26. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
  27. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +27 -0
  28. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +142 -0
  29. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +51 -0
  30. package/src/RedactoPrivacyCenter/api/actions.ts +444 -0
  31. package/src/RedactoPrivacyCenter/api/client.ts +413 -0
  32. package/src/RedactoPrivacyCenter/api/config.ts +33 -0
  33. package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
  34. package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
  35. package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
  36. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
  37. package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
  38. package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
  39. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
  40. package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
  41. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
  42. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
  43. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +468 -0
  44. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +433 -0
  45. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +726 -0
  46. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +239 -0
  47. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
  48. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
  49. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
  50. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
  51. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
  52. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +305 -0
  53. package/src/RedactoPrivacyCenter/components/Form.tsx +1455 -0
  54. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +176 -0
  55. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +330 -0
  56. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +329 -0
  57. package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
  58. package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +302 -0
  59. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +218 -0
  60. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
  61. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +412 -0
  62. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
  63. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
  64. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
  65. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
  66. package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
  67. package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
  68. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +179 -0
  69. package/src/RedactoPrivacyCenter/components/constant.ts +20 -0
  70. package/src/RedactoPrivacyCenter/components/types.ts +68 -0
  71. package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
  72. package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
  73. package/src/RedactoPrivacyCenter/config/table.ts +25 -0
  74. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +123 -0
  75. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +44 -0
  76. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
  77. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +64 -0
  78. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
  79. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
  80. package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
  81. package/src/RedactoPrivacyCenter/lib/api.ts +468 -0
  82. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
  83. package/src/RedactoPrivacyCenter/lib/constants.ts +116 -0
  84. package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
  85. package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
  86. package/src/RedactoPrivacyCenter/lib/queries.ts +30 -0
  87. package/src/RedactoPrivacyCenter/lib/types.ts +346 -0
  88. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
  89. package/src/RedactoPrivacyCenter/lib/utils.ts +625 -0
  90. package/src/RedactoPrivacyCenter/locales/as/translation.json +188 -0
  91. package/src/RedactoPrivacyCenter/locales/bho/translation.json +188 -0
  92. package/src/RedactoPrivacyCenter/locales/bn/translation.json +188 -0
  93. package/src/RedactoPrivacyCenter/locales/brx/translation.json +188 -0
  94. package/src/RedactoPrivacyCenter/locales/doi/translation.json +188 -0
  95. package/src/RedactoPrivacyCenter/locales/en/translation.json +188 -0
  96. package/src/RedactoPrivacyCenter/locales/gom/translation.json +188 -0
  97. package/src/RedactoPrivacyCenter/locales/gu/translation.json +188 -0
  98. package/src/RedactoPrivacyCenter/locales/hi/translation.json +188 -0
  99. package/src/RedactoPrivacyCenter/locales/kn/translation.json +188 -0
  100. package/src/RedactoPrivacyCenter/locales/ks/translation.json +188 -0
  101. package/src/RedactoPrivacyCenter/locales/mai/translation.json +188 -0
  102. package/src/RedactoPrivacyCenter/locales/ml/translation.json +188 -0
  103. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +188 -0
  104. package/src/RedactoPrivacyCenter/locales/mr/translation.json +188 -0
  105. package/src/RedactoPrivacyCenter/locales/ne/translation.json +188 -0
  106. package/src/RedactoPrivacyCenter/locales/or/translation.json +188 -0
  107. package/src/RedactoPrivacyCenter/locales/pa/translation.json +188 -0
  108. package/src/RedactoPrivacyCenter/locales/sa/translation.json +188 -0
  109. package/src/RedactoPrivacyCenter/locales/sat/translation.json +188 -0
  110. package/src/RedactoPrivacyCenter/locales/sd/translation.json +188 -0
  111. package/src/RedactoPrivacyCenter/locales/ta/translation.json +188 -0
  112. package/src/RedactoPrivacyCenter/locales/te/translation.json +188 -0
  113. package/src/RedactoPrivacyCenter/locales/ur/translation.json +188 -0
  114. package/src/RedactoPrivacyCenter/styles/base.css +117 -0
  115. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1000 -0
  116. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +819 -0
  117. package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
  118. package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
  119. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +365 -0
  120. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +479 -0
  121. package/src/RedactoPrivacyCenter/table/index.ts +2 -0
  122. package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
  123. package/src/RedactoPrivacyCenter/ui/Footer.tsx +73 -0
  124. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
  125. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +87 -0
  126. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
  127. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
  128. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
  129. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
  130. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
  131. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +97 -0
  132. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
  133. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +128 -0
  134. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +30 -0
  135. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +104 -0
  136. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +175 -0
  137. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +381 -0
  138. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +137 -0
  139. package/src/RedactoPrivacyCenter/ui/PCText.tsx +39 -0
  140. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
  141. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
  142. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
  143. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
  144. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +55 -0
  145. package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +70 -0
  146. package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
  147. package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
  148. package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
  149. package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
  150. package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
  151. package/src/index.ts +10 -0
  152. package/src/privacy-center.ts +107 -0
  153. package/tsconfig.json +2 -0
  154. package/tsup.config.ts +16 -1
  155. package/src/utils/isLegacyApi.ts +0 -12
@@ -0,0 +1,468 @@
1
+ import {
2
+ createCaseRequestServer,
3
+ fetchActivitiesServer,
4
+ fetchCaseHistoryServer,
5
+ fetchProductsServer,
6
+ fetchUserConsentsServer,
7
+ getFormDataServer,
8
+ manageConsentServer,
9
+ createOtpServer,
10
+ verifyOtpServer,
11
+ } from '../api/actions';
12
+ import type { BaseUrlContextValue } from '../context/BaseUrlContext';
13
+ import type {
14
+ ActivityDetail,
15
+ CaseHistoryDetail,
16
+ CreateCaseResponse,
17
+ FormData,
18
+ OrganizationResponse,
19
+ UserConsentDetail,
20
+ UserDataRequest,
21
+ } from './types';
22
+ import { ensureValidToken } from './utils';
23
+
24
+ // Auth context type for passing to API functions
25
+ export interface AuthContext {
26
+ accessToken?: string;
27
+ refreshToken?: string;
28
+ onError?: (error: Error) => boolean;
29
+ updateTokens?: (accessToken: string, refreshToken?: string) => void;
30
+ }
31
+
32
+ // Re-export server actions for client components
33
+ export {
34
+ createOtpServer as createOtp,
35
+ exchangeTokenServer as exchangeToken,
36
+ verifyOtpServer as verifyOtp,
37
+ } from '../api/actions';
38
+
39
+ // Re-export refreshOtpTokenServer for utils
40
+ export { refreshOtpTokenServer } from '../api/actions';
41
+
42
+ // Re-export types
43
+ export type {
44
+ ActivityDetail,
45
+ CaseHistoryDetail,
46
+ CreateCaseResponse,
47
+ FormData,
48
+ OrganizationResponse,
49
+ OtpResponse,
50
+ OtpVerificationResponse,
51
+ TokenExchangeResponse,
52
+ UserConsentDetail,
53
+ UserDataRequest,
54
+ } from './types';
55
+
56
+ // Keep utility functions
57
+ export { getCookieValue } from './utils';
58
+
59
+ /**
60
+ * Check if an error is an authentication/JWT related error
61
+ */
62
+ function isAuthError(error: any): boolean {
63
+ const errorMessage = error?.message || '';
64
+ return (
65
+ errorMessage.includes('401') ||
66
+ errorMessage.includes('JWT') ||
67
+ errorMessage.includes('expired') ||
68
+ errorMessage.includes('token') ||
69
+ errorMessage.includes('Unauthorized')
70
+ );
71
+ }
72
+
73
+ /**
74
+ * Handle client-side auth errors by attempting token refresh
75
+ * If refresh fails, signs out and redirects to sign-in
76
+ * @returns true if token was refreshed successfully and caller should retry, false otherwise
77
+ */
78
+ async function handleClientAuthError(
79
+ error: any,
80
+ organizationId: string,
81
+ workspaceId: string,
82
+ authContext?: AuthContext,
83
+ consentClient?: BaseUrlContextValue['consentClient']
84
+ ): Promise<boolean> {
85
+ if (isAuthError(error)) {
86
+ // Try to get a fresh token
87
+ const newToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
88
+ if (newToken) {
89
+ // Token refresh succeeded - caller should retry with new token
90
+ return true;
91
+ }
92
+ // Token refresh failed - ensureValidToken already handled sign out and redirect
93
+ return false;
94
+ }
95
+ return false;
96
+ }
97
+
98
+ export const getFormData = async (
99
+ organizationId: string,
100
+ workspaceId: string,
101
+ contact: string,
102
+ _isPopup?: boolean,
103
+ useSessionAuth?: boolean,
104
+ authContext?: AuthContext,
105
+ consentClient?: BaseUrlContextValue['consentClient'],
106
+ language?: string
107
+ ): Promise<FormData | null> => {
108
+ try {
109
+ // If useSessionAuth is explicitly set to true (case management), use session auth
110
+ if (useSessionAuth) {
111
+ return await getFormDataServer(organizationId, workspaceId, contact, undefined, true, consentClient, language);
112
+ }
113
+
114
+ // Ensure we have a valid token before making the API call
115
+ const authToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
116
+ if (!authToken) {
117
+ // ensureValidToken already handled sign out and redirect
118
+ return null;
119
+ }
120
+
121
+ const data = await getFormDataServer(
122
+ organizationId,
123
+ workspaceId,
124
+ contact,
125
+ authToken,
126
+ false,
127
+ consentClient,
128
+ language
129
+ );
130
+ return data;
131
+ } catch (error: any) {
132
+ const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
133
+ if (shouldRetry) {
134
+ // Read from sessionStorage first (synchronously updated) then fall back to context
135
+ const newAuthToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
136
+ return await getFormDataServer(
137
+ organizationId,
138
+ workspaceId,
139
+ contact,
140
+ newAuthToken,
141
+ false,
142
+ consentClient,
143
+ language
144
+ );
145
+ }
146
+ console.error('Error fetching form data:', error);
147
+ if (error.message?.includes('404')) {
148
+ throw error;
149
+ }
150
+ return null;
151
+ }
152
+ };
153
+
154
+ export const createCaseRequest = async (
155
+ organizationId: string,
156
+ workspaceId: string,
157
+ data: UserDataRequest,
158
+ _isPopup?: boolean,
159
+ useSessionAuth?: boolean,
160
+ authContext?: AuthContext,
161
+ consentClient?: BaseUrlContextValue['consentClient']
162
+ ): Promise<CreateCaseResponse | null> => {
163
+ try {
164
+ // If useSessionAuth is explicitly set to true (case management), use session auth
165
+ if (useSessionAuth) {
166
+ return await createCaseRequestServer(organizationId, workspaceId, data, undefined, true, consentClient);
167
+ }
168
+
169
+ // Ensure we have a valid token before making the API call
170
+ const authToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
171
+ if (!authToken) {
172
+ // ensureValidToken already handled sign out and redirect
173
+ return null;
174
+ }
175
+
176
+ return await createCaseRequestServer(
177
+ organizationId,
178
+ workspaceId,
179
+ data,
180
+ authToken,
181
+ false,
182
+ consentClient
183
+ );
184
+ } catch (error: any) {
185
+ const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
186
+ if (shouldRetry) {
187
+ // Read from sessionStorage first (synchronously updated) then fall back to context
188
+ const newAuthToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
189
+ return await createCaseRequestServer(
190
+ organizationId,
191
+ workspaceId,
192
+ data,
193
+ newAuthToken,
194
+ false,
195
+ consentClient
196
+ );
197
+ }
198
+ console.error('Error creating case request:', error);
199
+ return null;
200
+ }
201
+ };
202
+
203
+ export const fetchProducts = async (
204
+ organizationId: string,
205
+ workspaceId: string,
206
+ skip?: number,
207
+ limit?: number,
208
+ authContext?: AuthContext,
209
+ consentClient?: BaseUrlContextValue['consentClient']
210
+ ): Promise<Array<{ uuid: string; name: string; description?: string }> | null> => {
211
+ try {
212
+ // Ensure we have a valid token before making the API call
213
+ const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
214
+ if (!accessToken) {
215
+ // ensureValidToken already handled sign out and redirect
216
+ return null;
217
+ }
218
+
219
+ const result = await fetchProductsServer({
220
+ organizationId,
221
+ workspaceId,
222
+ skip,
223
+ limit,
224
+ authToken: accessToken,
225
+ consentClient,
226
+ });
227
+ return result;
228
+ } catch (error: any) {
229
+ const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
230
+ if (shouldRetry) {
231
+ // Read from sessionStorage first (synchronously updated) then fall back to context
232
+ const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
233
+ return await fetchProductsServer({
234
+ organizationId,
235
+ workspaceId,
236
+ skip,
237
+ limit,
238
+ authToken: newAccessToken || undefined,
239
+ consentClient,
240
+ });
241
+ }
242
+ console.error('Error fetching products:', error);
243
+ return null;
244
+ }
245
+ };
246
+
247
+ export const fetchUserConsents = async (
248
+ organizationId: string,
249
+ workspaceId: string,
250
+ contact: string,
251
+ offset?: number,
252
+ limit?: number,
253
+ search?: string,
254
+ status?: string,
255
+ product_uuid?: string,
256
+ authContext?: AuthContext,
257
+ consentClient?: BaseUrlContextValue['consentClient'],
258
+ language?: string
259
+ ): Promise<UserConsentDetail | null> => {
260
+ try {
261
+ // Ensure we have a valid token before making the API call
262
+ const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
263
+ if (!accessToken) {
264
+ // ensureValidToken already handled sign out and redirect
265
+ return null;
266
+ }
267
+
268
+ const result = await fetchUserConsentsServer({
269
+ organizationId,
270
+ workspaceId,
271
+ contact,
272
+ offset,
273
+ limit,
274
+ search,
275
+ status,
276
+ product_uuid,
277
+ language,
278
+ authToken: accessToken,
279
+ consentClient,
280
+ });
281
+ return result;
282
+ } catch (error: any) {
283
+ const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
284
+ if (shouldRetry) {
285
+ // Read from sessionStorage first (synchronously updated) then fall back to context
286
+ const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
287
+ return await fetchUserConsentsServer({
288
+ organizationId,
289
+ workspaceId,
290
+ contact,
291
+ offset,
292
+ limit,
293
+ search,
294
+ status,
295
+ product_uuid,
296
+ language,
297
+ authToken: newAccessToken || undefined,
298
+ consentClient,
299
+ });
300
+ }
301
+ console.error('Error fetching user consent data:', error);
302
+ return null;
303
+ }
304
+ };
305
+
306
+ export const manageConsent = async ({
307
+ organizationId,
308
+ workspaceId,
309
+ purposeId,
310
+ contact,
311
+ action,
312
+ authContext,
313
+ consentClient,
314
+ nominatorContact,
315
+ dataElementUuids,
316
+ }: {
317
+ organizationId: string;
318
+ workspaceId: string;
319
+ purposeId: string;
320
+ contact: string;
321
+ action: 'revoke' | 'regrant' | 'renew';
322
+ authContext?: AuthContext;
323
+ consentClient?: BaseUrlContextValue['consentClient'];
324
+ nominatorContact?: string;
325
+ dataElementUuids?: string[];
326
+ }): Promise<boolean | null> => {
327
+ try {
328
+ // Ensure we have a valid token before making the API call
329
+ const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
330
+ if (!accessToken) {
331
+ // ensureValidToken already handled sign out and redirect
332
+ return null;
333
+ }
334
+
335
+ const result = await manageConsentServer({
336
+ organizationId,
337
+ workspaceId,
338
+ purposeId,
339
+ contact,
340
+ action,
341
+ authToken: accessToken,
342
+ consentClient,
343
+ nominatorContact,
344
+ dataElementUuids,
345
+ });
346
+ return result;
347
+ } catch (error: any) {
348
+ // Re-throw nominator-specific errors (stable code) so the UI can show targeted messages
349
+ if (error?.name === 'ConsentApiError') {
350
+ throw error;
351
+ }
352
+ // Auth errors (401) mean the request was rejected before processing, so a single retry is safe
353
+ const recovered = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
354
+ if (recovered) {
355
+ const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
356
+ return await manageConsentServer({
357
+ organizationId,
358
+ workspaceId,
359
+ purposeId,
360
+ contact,
361
+ action,
362
+ authToken: newAccessToken || undefined,
363
+ consentClient,
364
+ nominatorContact,
365
+ dataElementUuids,
366
+ });
367
+ }
368
+ console.error(`Error ${action} consent:`, error);
369
+ return null;
370
+ }
371
+ };
372
+
373
+ export const fetchActivities = async (
374
+ organizationId: string,
375
+ workspaceId: string,
376
+ offset?: number,
377
+ limit?: number,
378
+ authContext?: AuthContext,
379
+ consentClient?: BaseUrlContextValue['consentClient'],
380
+ language?: string
381
+ ): Promise<ActivityDetail | null> => {
382
+ try {
383
+ // Ensure we have a valid token before making the API call
384
+ const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
385
+ if (!accessToken) {
386
+ // ensureValidToken already handled sign out and redirect
387
+ return null;
388
+ }
389
+
390
+ const result = await fetchActivitiesServer({
391
+ organizationId,
392
+ workspaceId,
393
+ offset,
394
+ limit,
395
+ language,
396
+ authToken: accessToken,
397
+ consentClient,
398
+ });
399
+ return result;
400
+ } catch (error: any) {
401
+ const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
402
+ if (shouldRetry) {
403
+ // Read from sessionStorage first (synchronously updated) then fall back to context
404
+ const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
405
+ return await fetchActivitiesServer({
406
+ organizationId,
407
+ workspaceId,
408
+ offset,
409
+ limit,
410
+ language,
411
+ authToken: newAccessToken || undefined,
412
+ consentClient,
413
+ });
414
+ }
415
+ console.error('Error fetching activities:', error);
416
+ return null;
417
+ }
418
+ };
419
+
420
+ export const fetchCaseHistory = async (
421
+ organizationId: string,
422
+ workspaceId: string,
423
+ contact: string,
424
+ offset?: number,
425
+ limit?: number,
426
+ authContext?: AuthContext,
427
+ consentClient?: BaseUrlContextValue['consentClient'],
428
+ language?: string
429
+ ): Promise<CaseHistoryDetail | null> => {
430
+ try {
431
+ // Ensure we have a valid token before making the API call
432
+ const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
433
+ if (!accessToken) {
434
+ // ensureValidToken already handled sign out and redirect
435
+ return null;
436
+ }
437
+
438
+ const result = await fetchCaseHistoryServer({
439
+ organizationId,
440
+ workspaceId,
441
+ contact,
442
+ offset,
443
+ limit,
444
+ language,
445
+ authToken: accessToken,
446
+ consentClient,
447
+ });
448
+ return result;
449
+ } catch (error: any) {
450
+ const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
451
+ if (shouldRetry) {
452
+ // Read from sessionStorage first (synchronously updated) then fall back to context
453
+ const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
454
+ return await fetchCaseHistoryServer({
455
+ organizationId,
456
+ workspaceId,
457
+ contact,
458
+ offset,
459
+ limit,
460
+ language,
461
+ authToken: newAccessToken || undefined,
462
+ consentClient,
463
+ });
464
+ }
465
+ console.error('Error fetching case history: ', error);
466
+ return null;
467
+ }
468
+ };
@@ -0,0 +1,63 @@
1
+ import { useMemo } from 'react';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { ConsentStatusEnum } from '../types';
4
+ import type { UserConsent } from '../types';
5
+ import { formatDateTime as formatDateTimeShared } from '../../utils/date';
6
+
7
+ // Re-export shared date formatting
8
+ export const formatDateTime = formatDateTimeShared;
9
+
10
+ export const useStatusOptions = () => {
11
+ const { t } = useTranslation();
12
+ return useMemo(
13
+ () => [
14
+ { label: t('statusActive'), value: ConsentStatusEnum.ACTIVE },
15
+ { label: t('statusWithdrawn'), value: ConsentStatusEnum.WITHDRAWN },
16
+ { label: t('statusExpired'), value: ConsentStatusEnum.EXPIRED },
17
+ { label: t('statusDeclined'), value: ConsentStatusEnum.DECLINED },
18
+ ],
19
+ [t]
20
+ );
21
+ };
22
+
23
+ export const exportTableToCSV = (rows: UserConsent[]) => {
24
+ if (!rows || rows.length === 0) {
25
+ console.warn('No data to export');
26
+ return;
27
+ }
28
+
29
+ const excludedFields = ['Action', 'data_elements'];
30
+ const headers = Array.from(new Set(rows.flatMap((r) => Object.keys(r))))
31
+ .filter((key) => !excludedFields.includes(key))
32
+ .map((key) => key.toUpperCase())
33
+ .join(',');
34
+
35
+ const csvRows = rows.map((row) => {
36
+ return Object.entries(row)
37
+ .filter(([key]) => !excludedFields.includes(key))
38
+ .map(([key, value]) => {
39
+ let formattedValue = value;
40
+ if ((key === 'given_date' || key === 'valid_till') && value) {
41
+ formattedValue = formatDateTime(String(value));
42
+ }
43
+ return `"${String(formattedValue).replace(/"/g, '""')}"`;
44
+ })
45
+ .join(',');
46
+ });
47
+
48
+ const csvContent = [headers, ...csvRows].join('\n');
49
+
50
+ try {
51
+ const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
52
+ const url = URL.createObjectURL(blob);
53
+ const link = document.createElement('a');
54
+ link.href = url;
55
+ link.setAttribute('download', `consent-records.csv`);
56
+ document.body.appendChild(link);
57
+ link.click();
58
+ document.body.removeChild(link);
59
+ URL.revokeObjectURL(url);
60
+ } catch (error) {
61
+ console.error('Failed to export CSV:', error);
62
+ }
63
+ };
@@ -0,0 +1,116 @@
1
+ import { RequestTypeEnum } from './types';
2
+ import { useTranslation } from 'react-i18next';
3
+ import { GRIEVANCE_TAB_IDS } from '../components/constant';
4
+ import { menuItemsPC } from '../components/SideMenuBarPC/constants';
5
+ import type { MenuItem } from '../components/SideMenuBarPC/types';
6
+ import type { InternalPage } from '../context/NavigationContext';
7
+
8
+ export const useRequestTypeLabels = () => {
9
+ const { t } = useTranslation();
10
+
11
+ return {
12
+ [RequestTypeEnum.ACCESS]: t('access'),
13
+ [RequestTypeEnum.CORRECTION]: t('correction'),
14
+ [RequestTypeEnum.ERASURE]: t('erasure'),
15
+ [RequestTypeEnum.GRIEVANCE]: t('grievance'),
16
+ [RequestTypeEnum.NOMINATION]: t('nomination'),
17
+ } as Record<RequestTypeEnum, string>;
18
+ };
19
+
20
+ export const languageOptions = [
21
+ { value: 'en', label: 'English' },
22
+ { value: 'hi', label: 'हिन्दी (Hindi)' },
23
+ { value: 'te', label: 'తెలుగు (Telugu)' },
24
+ { value: 'mr', label: 'मराठी (Marathi)' },
25
+ { value: 'ta', label: 'தமிழ் (Tamil)' },
26
+ { value: 'ur', label: 'اردو (Urdu)' },
27
+ { value: 'gu', label: 'ગુજરાતી (Gujarati)' },
28
+ { value: 'kn', label: 'ಕನ್ನಡ (Kannada)' },
29
+ { value: 'ml', label: 'മലയാളം (Malayalam)' },
30
+ { value: 'pa', label: 'ਪੰਜਾਬੀ (Punjabi)' },
31
+ { value: 'or', label: 'ଓଡ଼ିଆ (Odia)' },
32
+ { value: 'as', label: 'অসমীয়া (Assamese)' },
33
+ { value: 'bn', label: 'বাংলা (Bengali)' },
34
+ { value: 'mai', label: 'मैथिली (Maithili)' },
35
+ { value: 'ne', label: 'नेपाली (Nepali)' },
36
+ { value: 'sd', label: 'سنڌي (Sindhi)' },
37
+ { value: 'doi', label: 'डोगरी (Dogri)' },
38
+ { value: 'mni-Mtei', label: 'ꯃꯩꯇꯩꯂꯣꯟ (Manipuri)' },
39
+ { value: 'gom', label: 'कोंकणी (Konkani)' },
40
+ { value: 'sa', label: 'संस्कृतम् (Sanskrit)' },
41
+ { value: 'bho', label: 'भोजपुरी (Bhojpuri)' },
42
+ { value: 'brx', label: 'बड़ो (Bodo)' },
43
+ { value: 'ks', label: 'كٲشُر (Kashmiri)' },
44
+ { value: 'sat', label: 'ᱥᱟᱱᱛᱟᱲᱤ (Santali)' },
45
+ ];
46
+
47
+ export const useTimePeriodOptions = () => {
48
+ const { t } = useTranslation();
49
+
50
+ return [
51
+ { value: '1', label: t('today') },
52
+ { value: '7', label: t('last7Days') },
53
+ { value: '30', label: t('last30Days') },
54
+ { value: '90', label: t('last3Months') },
55
+ ];
56
+ };
57
+
58
+ export const useGrievanceTabs = () => {
59
+ const { t } = useTranslation();
60
+
61
+ return [
62
+ { id: GRIEVANCE_TAB_IDS.ALL, label: t('allRequests') },
63
+ { id: GRIEVANCE_TAB_IDS.PROCESSING, label: t('processing') },
64
+ { id: GRIEVANCE_TAB_IDS.COMPLETED, label: t('completed') },
65
+ { id: GRIEVANCE_TAB_IDS.REJECTED, label: t('rejected') },
66
+ ];
67
+ };
68
+
69
+ export type PageChromeConfig = {
70
+ titleKey: string;
71
+ descriptionKey: string;
72
+ };
73
+
74
+ export const PAGE_CHROME_BY_PAGE: Record<InternalPage, PageChromeConfig> = {
75
+ 'consent-manager': {
76
+ titleKey: 'manageConsent',
77
+ descriptionKey: 'manageConsentSubtitle',
78
+ },
79
+ form: {
80
+ titleKey: 'grievanceRequests',
81
+ descriptionKey: 'grievanceSubtitle',
82
+ },
83
+ activity: {
84
+ titleKey: 'activities',
85
+ descriptionKey: 'activitiesSubtitle',
86
+ },
87
+ };
88
+
89
+ const HREF_TO_NAME_KEY: Record<string, string> = {
90
+ 'consent-manager': 'consentManager',
91
+ form: 'grievance',
92
+ activity: 'activity',
93
+ };
94
+
95
+ export const useMenuItemsPC = (): MenuItem[] => {
96
+ const { t } = useTranslation();
97
+ return menuItemsPC.map((item) => ({
98
+ ...item,
99
+ name: t((item.href && HREF_TO_NAME_KEY[item.href]) ?? item.name),
100
+ }));
101
+ };
102
+
103
+ // Activity columns constants
104
+ export const ACTIVITY_COLUMN_SIZES = {
105
+ TITLE: 220,
106
+ ACTIVITY_TYPE: 160,
107
+ DESCRIPTION: 320,
108
+ TIMESTAMP: 200,
109
+ } as const;
110
+
111
+ export const ACTIVITY_DESCRIPTION_TRUNCATE_LENGTH = 100;
112
+
113
+ export const ACTIVITY_DATE_FORMATS = {
114
+ DISPLAY: 'MMM D, YYYY [at] h:mm A',
115
+ TOOLTIP: 'MMMM D, YYYY [at] h:mm:ss A',
116
+ } as const;