@redacto.io/consent-sdk-react 4.0.0 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -1
- package/LICENSE +176 -0
- package/README.md +98 -1
- package/dist/index.js +231 -96
- package/dist/index.mjs +231 -96
- package/dist/privacy-center.d.mts +649 -0
- package/dist/privacy-center.d.ts +649 -0
- package/dist/privacy-center.js +20824 -0
- package/dist/privacy-center.mjs +20789 -0
- package/package.json +47 -3
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +6 -4
- package/src/RedactoNoticeConsent/api/index.ts +2 -0
- package/src/RedactoNoticeConsent/api/types.ts +2 -0
- package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +128 -62
- package/src/RedactoNoticeConsent/language-codes.ts +97 -0
- package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -3
- package/src/RedactoNoticeConsentInline/api/index.ts +0 -1
- package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +154 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +30 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +173 -0
- package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +55 -0
- package/src/RedactoPrivacyCenter/api/actions.ts +476 -0
- package/src/RedactoPrivacyCenter/api/client.ts +524 -0
- package/src/RedactoPrivacyCenter/api/config.ts +33 -0
- package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
- package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
- package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
- package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
- package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
- package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
- package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +38 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +31 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +73 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +87 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +95 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +147 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +171 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +23 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +116 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +36 -0
- package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +56 -0
- package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +469 -0
- package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +426 -0
- package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +732 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +238 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +304 -0
- package/src/RedactoPrivacyCenter/components/Form.tsx +1596 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +174 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +337 -0
- package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +330 -0
- package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
- package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +304 -0
- package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +232 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +408 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
- package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
- package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
- package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +159 -0
- package/src/RedactoPrivacyCenter/components/constant.ts +16 -0
- package/src/RedactoPrivacyCenter/components/types.ts +76 -0
- package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
- package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
- package/src/RedactoPrivacyCenter/config/table.ts +25 -0
- package/src/RedactoPrivacyCenter/context/AuthContext.tsx +137 -0
- package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +41 -0
- package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
- package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +96 -0
- package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
- package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
- package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
- package/src/RedactoPrivacyCenter/context/types.ts +14 -0
- package/src/RedactoPrivacyCenter/lib/api.ts +566 -0
- package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
- package/src/RedactoPrivacyCenter/lib/constants.ts +161 -0
- package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
- package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
- package/src/RedactoPrivacyCenter/lib/queries.ts +134 -0
- package/src/RedactoPrivacyCenter/lib/types.ts +531 -0
- package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
- package/src/RedactoPrivacyCenter/lib/utils.ts +626 -0
- package/src/RedactoPrivacyCenter/locales/as/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/bho/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/bn/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/brx/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/doi/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/en/translation.json +255 -0
- package/src/RedactoPrivacyCenter/locales/gom/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/gu/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/hi/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/kn/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ks/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/mai/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ml/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/mr/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ne/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/or/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/pa/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/sa/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/sat/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/sd/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ta/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/te/translation.json +280 -0
- package/src/RedactoPrivacyCenter/locales/ur/translation.json +280 -0
- package/src/RedactoPrivacyCenter/styles/base.css +117 -0
- package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1725 -0
- package/src/RedactoPrivacyCenter/styles/pcStyles.ts +813 -0
- package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
- package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +367 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +476 -0
- package/src/RedactoPrivacyCenter/table/index.ts +2 -0
- package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
- package/src/RedactoPrivacyCenter/ui/Footer.tsx +75 -0
- package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
- package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +93 -0
- package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
- package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
- package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
- package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
- package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
- package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +107 -0
- package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
- package/src/RedactoPrivacyCenter/ui/PCInput.tsx +132 -0
- package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +31 -0
- package/src/RedactoPrivacyCenter/ui/PCModal.tsx +106 -0
- package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +173 -0
- package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +387 -0
- package/src/RedactoPrivacyCenter/ui/PCTable.tsx +149 -0
- package/src/RedactoPrivacyCenter/ui/PCText.tsx +41 -0
- package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
- package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
- package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
- package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
- package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +53 -0
- package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +72 -0
- package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
- package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
- package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
- package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
- package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
- package/src/privacy-center.ts +108 -0
- package/tsconfig.json +2 -0
- package/tsup.config.ts +16 -1
- package/.turbo/turbo-build.log +0 -21
|
@@ -0,0 +1,566 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createCaseRequestServer,
|
|
3
|
+
fetchActivitiesServer,
|
|
4
|
+
fetchCaseHistoryServer,
|
|
5
|
+
fetchProductsServer,
|
|
6
|
+
fetchUserConsentsServer,
|
|
7
|
+
getFormDataServer,
|
|
8
|
+
manageConsentServer,
|
|
9
|
+
getCaseMessagesServer,
|
|
10
|
+
sendCaseMessageServer,
|
|
11
|
+
uploadCaseDocumentServer,
|
|
12
|
+
submitDocumentForRequestServer,
|
|
13
|
+
getCaseDocumentServer,
|
|
14
|
+
} from '../api/actions';
|
|
15
|
+
import type { BaseUrlContextValue } from '../context/BaseUrlContext';
|
|
16
|
+
import type {
|
|
17
|
+
ActivityDetail,
|
|
18
|
+
CaseHistoryDetail,
|
|
19
|
+
CaseMessage,
|
|
20
|
+
CreateCaseResponse,
|
|
21
|
+
FormData,
|
|
22
|
+
MessageDocument,
|
|
23
|
+
UploadDocumentResponse,
|
|
24
|
+
UserConsentDetail,
|
|
25
|
+
UserDataRequest,
|
|
26
|
+
} from './types';
|
|
27
|
+
import { ensureValidToken } from './utils';
|
|
28
|
+
|
|
29
|
+
// Auth context type for passing to API functions
|
|
30
|
+
export interface AuthContext {
|
|
31
|
+
accessToken?: string;
|
|
32
|
+
refreshToken?: string;
|
|
33
|
+
onError?: (error: Error) => boolean;
|
|
34
|
+
updateTokens?: (accessToken: string, refreshToken?: string) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Re-export server actions for client components
|
|
38
|
+
export {
|
|
39
|
+
createOtpServer as createOtp,
|
|
40
|
+
exchangeTokenServer as exchangeToken,
|
|
41
|
+
verifyOtpServer as verifyOtp,
|
|
42
|
+
} from '../api/actions';
|
|
43
|
+
|
|
44
|
+
// Re-export refreshOtpTokenServer for utils
|
|
45
|
+
export { refreshOtpTokenServer } from '../api/actions';
|
|
46
|
+
|
|
47
|
+
// Re-export types
|
|
48
|
+
export type {
|
|
49
|
+
ActivityDetail,
|
|
50
|
+
CaseHistoryDetail,
|
|
51
|
+
CreateCaseResponse,
|
|
52
|
+
FormData,
|
|
53
|
+
OrganizationResponse,
|
|
54
|
+
OtpResponse,
|
|
55
|
+
OtpVerificationResponse,
|
|
56
|
+
TokenExchangeResponse,
|
|
57
|
+
UserConsentDetail,
|
|
58
|
+
UserDataRequest,
|
|
59
|
+
} from './types';
|
|
60
|
+
|
|
61
|
+
// Keep utility functions
|
|
62
|
+
export { getCookieValue } from './utils';
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Check if an error is an authentication/JWT related error
|
|
66
|
+
*/
|
|
67
|
+
function isAuthError(error: any): boolean {
|
|
68
|
+
const errorMessage = error?.message || '';
|
|
69
|
+
return (
|
|
70
|
+
errorMessage.includes('401') ||
|
|
71
|
+
errorMessage.includes('JWT') ||
|
|
72
|
+
errorMessage.includes('expired') ||
|
|
73
|
+
errorMessage.includes('token') ||
|
|
74
|
+
errorMessage.includes('Unauthorized')
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Handle client-side auth errors by attempting token refresh
|
|
80
|
+
* If refresh fails, signs out and redirects to sign-in
|
|
81
|
+
* @returns true if token was refreshed successfully and caller should retry, false otherwise
|
|
82
|
+
*/
|
|
83
|
+
async function handleClientAuthError(
|
|
84
|
+
error: any,
|
|
85
|
+
organizationId: string,
|
|
86
|
+
workspaceId: string,
|
|
87
|
+
authContext?: AuthContext,
|
|
88
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
89
|
+
): Promise<boolean> {
|
|
90
|
+
if (isAuthError(error)) {
|
|
91
|
+
// Try to get a fresh token
|
|
92
|
+
const newToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
93
|
+
if (newToken) {
|
|
94
|
+
// Token refresh succeeded - caller should retry with new token
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
// Token refresh failed - ensureValidToken already handled sign out and redirect
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export const getFormData = async (
|
|
104
|
+
organizationId: string,
|
|
105
|
+
workspaceId: string,
|
|
106
|
+
contact: string,
|
|
107
|
+
_isPopup?: boolean,
|
|
108
|
+
useSessionAuth?: boolean,
|
|
109
|
+
authContext?: AuthContext,
|
|
110
|
+
consentClient?: BaseUrlContextValue['consentClient'],
|
|
111
|
+
language?: string
|
|
112
|
+
): Promise<FormData | null> => {
|
|
113
|
+
try {
|
|
114
|
+
// If useSessionAuth is explicitly set to true (case management), use session auth
|
|
115
|
+
if (useSessionAuth) {
|
|
116
|
+
return await getFormDataServer(organizationId, workspaceId, contact, undefined, true, consentClient, language);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Ensure we have a valid token before making the API call
|
|
120
|
+
const authToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
121
|
+
if (!authToken) {
|
|
122
|
+
// ensureValidToken already handled sign out and redirect
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const data = await getFormDataServer(
|
|
127
|
+
organizationId,
|
|
128
|
+
workspaceId,
|
|
129
|
+
contact,
|
|
130
|
+
authToken,
|
|
131
|
+
false,
|
|
132
|
+
consentClient,
|
|
133
|
+
language
|
|
134
|
+
);
|
|
135
|
+
return data;
|
|
136
|
+
} catch (error: any) {
|
|
137
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
138
|
+
if (shouldRetry) {
|
|
139
|
+
// Read from sessionStorage first (synchronously updated) then fall back to context
|
|
140
|
+
const newAuthToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
141
|
+
return await getFormDataServer(
|
|
142
|
+
organizationId,
|
|
143
|
+
workspaceId,
|
|
144
|
+
contact,
|
|
145
|
+
newAuthToken,
|
|
146
|
+
false,
|
|
147
|
+
consentClient,
|
|
148
|
+
language
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
console.error('Error fetching form data:', error);
|
|
152
|
+
if (error.message?.includes('404')) {
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export const createCaseRequest = async (
|
|
160
|
+
organizationId: string,
|
|
161
|
+
workspaceId: string,
|
|
162
|
+
data: UserDataRequest,
|
|
163
|
+
_isPopup?: boolean,
|
|
164
|
+
useSessionAuth?: boolean,
|
|
165
|
+
authContext?: AuthContext,
|
|
166
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
167
|
+
): Promise<CreateCaseResponse | null> => {
|
|
168
|
+
try {
|
|
169
|
+
// If useSessionAuth is explicitly set to true (case management), use session auth
|
|
170
|
+
if (useSessionAuth) {
|
|
171
|
+
return await createCaseRequestServer(organizationId, workspaceId, data, undefined, true, consentClient);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Ensure we have a valid token before making the API call
|
|
175
|
+
const authToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
176
|
+
if (!authToken) {
|
|
177
|
+
// ensureValidToken already handled sign out and redirect
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return await createCaseRequestServer(
|
|
182
|
+
organizationId,
|
|
183
|
+
workspaceId,
|
|
184
|
+
data,
|
|
185
|
+
authToken,
|
|
186
|
+
false,
|
|
187
|
+
consentClient
|
|
188
|
+
);
|
|
189
|
+
} catch (error: any) {
|
|
190
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
191
|
+
if (shouldRetry) {
|
|
192
|
+
// Read from sessionStorage first (synchronously updated) then fall back to context
|
|
193
|
+
const newAuthToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
194
|
+
return await createCaseRequestServer(
|
|
195
|
+
organizationId,
|
|
196
|
+
workspaceId,
|
|
197
|
+
data,
|
|
198
|
+
newAuthToken,
|
|
199
|
+
false,
|
|
200
|
+
consentClient
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
console.error('Error creating case request:', error);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export const fetchProducts = async (
|
|
209
|
+
organizationId: string,
|
|
210
|
+
workspaceId: string,
|
|
211
|
+
skip?: number,
|
|
212
|
+
limit?: number,
|
|
213
|
+
authContext?: AuthContext,
|
|
214
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
215
|
+
): Promise<Array<{ uuid: string; name: string; description?: string }> | null> => {
|
|
216
|
+
try {
|
|
217
|
+
// Ensure we have a valid token before making the API call
|
|
218
|
+
const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
219
|
+
if (!accessToken) {
|
|
220
|
+
// ensureValidToken already handled sign out and redirect
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const result = await fetchProductsServer({
|
|
225
|
+
organizationId,
|
|
226
|
+
workspaceId,
|
|
227
|
+
skip,
|
|
228
|
+
limit,
|
|
229
|
+
authToken: accessToken,
|
|
230
|
+
consentClient,
|
|
231
|
+
});
|
|
232
|
+
return result;
|
|
233
|
+
} catch (error: any) {
|
|
234
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
235
|
+
if (shouldRetry) {
|
|
236
|
+
// Read from sessionStorage first (synchronously updated) then fall back to context
|
|
237
|
+
const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
238
|
+
return await fetchProductsServer({
|
|
239
|
+
organizationId,
|
|
240
|
+
workspaceId,
|
|
241
|
+
skip,
|
|
242
|
+
limit,
|
|
243
|
+
authToken: newAccessToken || undefined,
|
|
244
|
+
consentClient,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
console.error('Error fetching products:', error);
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
export const fetchUserConsents = async (
|
|
253
|
+
organizationId: string,
|
|
254
|
+
workspaceId: string,
|
|
255
|
+
contact: string,
|
|
256
|
+
offset?: number,
|
|
257
|
+
limit?: number,
|
|
258
|
+
search?: string,
|
|
259
|
+
status?: string,
|
|
260
|
+
product_uuid?: string,
|
|
261
|
+
authContext?: AuthContext,
|
|
262
|
+
consentClient?: BaseUrlContextValue['consentClient'],
|
|
263
|
+
language?: string
|
|
264
|
+
): Promise<UserConsentDetail | null> => {
|
|
265
|
+
try {
|
|
266
|
+
// Ensure we have a valid token before making the API call
|
|
267
|
+
const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
268
|
+
if (!accessToken) {
|
|
269
|
+
// ensureValidToken already handled sign out and redirect
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const result = await fetchUserConsentsServer({
|
|
274
|
+
organizationId,
|
|
275
|
+
workspaceId,
|
|
276
|
+
contact,
|
|
277
|
+
offset,
|
|
278
|
+
limit,
|
|
279
|
+
search,
|
|
280
|
+
status,
|
|
281
|
+
product_uuid,
|
|
282
|
+
language,
|
|
283
|
+
authToken: accessToken,
|
|
284
|
+
consentClient,
|
|
285
|
+
});
|
|
286
|
+
return result;
|
|
287
|
+
} catch (error: any) {
|
|
288
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
289
|
+
if (shouldRetry) {
|
|
290
|
+
// Read from sessionStorage first (synchronously updated) then fall back to context
|
|
291
|
+
const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
292
|
+
return await fetchUserConsentsServer({
|
|
293
|
+
organizationId,
|
|
294
|
+
workspaceId,
|
|
295
|
+
contact,
|
|
296
|
+
offset,
|
|
297
|
+
limit,
|
|
298
|
+
search,
|
|
299
|
+
status,
|
|
300
|
+
product_uuid,
|
|
301
|
+
language,
|
|
302
|
+
authToken: newAccessToken || undefined,
|
|
303
|
+
consentClient,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
console.error('Error fetching user consent data:', error);
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
export const manageConsent = async ({
|
|
312
|
+
organizationId,
|
|
313
|
+
workspaceId,
|
|
314
|
+
purposeId,
|
|
315
|
+
contact,
|
|
316
|
+
action,
|
|
317
|
+
authContext,
|
|
318
|
+
consentClient,
|
|
319
|
+
nominatorContact,
|
|
320
|
+
dataElementUuids,
|
|
321
|
+
}: {
|
|
322
|
+
organizationId: string;
|
|
323
|
+
workspaceId: string;
|
|
324
|
+
purposeId: string;
|
|
325
|
+
contact: string;
|
|
326
|
+
action: 'revoke' | 'regrant' | 'renew';
|
|
327
|
+
authContext?: AuthContext;
|
|
328
|
+
consentClient?: BaseUrlContextValue['consentClient'];
|
|
329
|
+
nominatorContact?: string;
|
|
330
|
+
dataElementUuids?: string[];
|
|
331
|
+
}): Promise<boolean | null> => {
|
|
332
|
+
try {
|
|
333
|
+
// Ensure we have a valid token before making the API call
|
|
334
|
+
const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
335
|
+
if (!accessToken) {
|
|
336
|
+
// ensureValidToken already handled sign out and redirect
|
|
337
|
+
return null;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const result = await manageConsentServer({
|
|
341
|
+
organizationId,
|
|
342
|
+
workspaceId,
|
|
343
|
+
purposeId,
|
|
344
|
+
contact,
|
|
345
|
+
action,
|
|
346
|
+
authToken: accessToken,
|
|
347
|
+
consentClient,
|
|
348
|
+
nominatorContact,
|
|
349
|
+
dataElementUuids,
|
|
350
|
+
});
|
|
351
|
+
return result;
|
|
352
|
+
} catch (error: any) {
|
|
353
|
+
// Re-throw nominator-specific errors (stable code) so the UI can show targeted messages
|
|
354
|
+
if (error?.name === 'ConsentApiError') {
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
// Auth errors (401) mean the request was rejected before processing, so a single retry is safe
|
|
358
|
+
const recovered = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
359
|
+
if (recovered) {
|
|
360
|
+
const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
361
|
+
return await manageConsentServer({
|
|
362
|
+
organizationId,
|
|
363
|
+
workspaceId,
|
|
364
|
+
purposeId,
|
|
365
|
+
contact,
|
|
366
|
+
action,
|
|
367
|
+
authToken: newAccessToken || undefined,
|
|
368
|
+
consentClient,
|
|
369
|
+
nominatorContact,
|
|
370
|
+
dataElementUuids,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
console.error(`Error ${action} consent:`, error);
|
|
374
|
+
return null;
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
export const fetchActivities = async (
|
|
379
|
+
organizationId: string,
|
|
380
|
+
workspaceId: string,
|
|
381
|
+
offset?: number,
|
|
382
|
+
limit?: number,
|
|
383
|
+
authContext?: AuthContext,
|
|
384
|
+
consentClient?: BaseUrlContextValue['consentClient'],
|
|
385
|
+
language?: string
|
|
386
|
+
): Promise<ActivityDetail | null> => {
|
|
387
|
+
try {
|
|
388
|
+
// Ensure we have a valid token before making the API call
|
|
389
|
+
const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
390
|
+
if (!accessToken) {
|
|
391
|
+
// ensureValidToken already handled sign out and redirect
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const result = await fetchActivitiesServer({
|
|
396
|
+
organizationId,
|
|
397
|
+
workspaceId,
|
|
398
|
+
offset,
|
|
399
|
+
limit,
|
|
400
|
+
language,
|
|
401
|
+
authToken: accessToken,
|
|
402
|
+
consentClient,
|
|
403
|
+
});
|
|
404
|
+
return result;
|
|
405
|
+
} catch (error: any) {
|
|
406
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
407
|
+
if (shouldRetry) {
|
|
408
|
+
// Read from sessionStorage first (synchronously updated) then fall back to context
|
|
409
|
+
const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
410
|
+
return await fetchActivitiesServer({
|
|
411
|
+
organizationId,
|
|
412
|
+
workspaceId,
|
|
413
|
+
offset,
|
|
414
|
+
limit,
|
|
415
|
+
language,
|
|
416
|
+
authToken: newAccessToken || undefined,
|
|
417
|
+
consentClient,
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
console.error('Error fetching activities:', error);
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
export const fetchCaseHistory = async (
|
|
426
|
+
organizationId: string,
|
|
427
|
+
workspaceId: string,
|
|
428
|
+
contact: string,
|
|
429
|
+
offset?: number,
|
|
430
|
+
limit?: number,
|
|
431
|
+
authContext?: AuthContext,
|
|
432
|
+
consentClient?: BaseUrlContextValue['consentClient'],
|
|
433
|
+
language?: string
|
|
434
|
+
): Promise<CaseHistoryDetail | null> => {
|
|
435
|
+
try {
|
|
436
|
+
// Ensure we have a valid token before making the API call
|
|
437
|
+
const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
438
|
+
if (!accessToken) {
|
|
439
|
+
// ensureValidToken already handled sign out and redirect
|
|
440
|
+
return null;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const result = await fetchCaseHistoryServer({
|
|
444
|
+
organizationId,
|
|
445
|
+
workspaceId,
|
|
446
|
+
contact,
|
|
447
|
+
offset,
|
|
448
|
+
limit,
|
|
449
|
+
language,
|
|
450
|
+
authToken: accessToken,
|
|
451
|
+
consentClient,
|
|
452
|
+
});
|
|
453
|
+
return result;
|
|
454
|
+
} catch (error: any) {
|
|
455
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
456
|
+
if (shouldRetry) {
|
|
457
|
+
// Read from sessionStorage first (synchronously updated) then fall back to context
|
|
458
|
+
const newAccessToken = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
459
|
+
return await fetchCaseHistoryServer({
|
|
460
|
+
organizationId,
|
|
461
|
+
workspaceId,
|
|
462
|
+
contact,
|
|
463
|
+
offset,
|
|
464
|
+
limit,
|
|
465
|
+
language,
|
|
466
|
+
authToken: newAccessToken || undefined,
|
|
467
|
+
consentClient,
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
console.error('Error fetching case history: ', error);
|
|
471
|
+
return null;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
// ─── Auth-retry helper ──────────────────────────────────────────────────────
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Wraps an API call with token acquisition and single-retry-on-auth-error logic.
|
|
479
|
+
* `fn` receives a valid access token and returns the API result.
|
|
480
|
+
*/
|
|
481
|
+
async function withAuthRetry<T>(
|
|
482
|
+
organizationId: string,
|
|
483
|
+
workspaceId: string,
|
|
484
|
+
authContext: AuthContext | undefined,
|
|
485
|
+
consentClient: BaseUrlContextValue['consentClient'] | undefined,
|
|
486
|
+
errorLabel: string,
|
|
487
|
+
fn: (token: string) => Promise<T>
|
|
488
|
+
): Promise<T | null> {
|
|
489
|
+
try {
|
|
490
|
+
const accessToken = await ensureValidToken(organizationId, workspaceId, undefined, authContext, consentClient);
|
|
491
|
+
if (!accessToken) return null;
|
|
492
|
+
return await fn(accessToken);
|
|
493
|
+
} catch (error: any) {
|
|
494
|
+
const shouldRetry = await handleClientAuthError(error, organizationId, workspaceId, authContext, consentClient);
|
|
495
|
+
if (shouldRetry) {
|
|
496
|
+
const token = sessionStorage.getItem('access_token') || authContext?.accessToken || '';
|
|
497
|
+
return await fn(token);
|
|
498
|
+
}
|
|
499
|
+
console.error(errorLabel, error);
|
|
500
|
+
return null;
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
// ─── Case Communication ──────────────────────────────────────────────────────
|
|
505
|
+
|
|
506
|
+
export const getCaseMessages = async (
|
|
507
|
+
organizationId: string,
|
|
508
|
+
workspaceId: string,
|
|
509
|
+
caseUuid: string,
|
|
510
|
+
authContext?: AuthContext,
|
|
511
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
512
|
+
): Promise<CaseMessage[] | null> =>
|
|
513
|
+
withAuthRetry(organizationId, workspaceId, authContext, consentClient, 'Error fetching case messages:', (token) =>
|
|
514
|
+
getCaseMessagesServer({ organizationId, workspaceId, caseUuid, authToken: token, consentClient })
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
export const sendCaseMessage = async (
|
|
518
|
+
organizationId: string,
|
|
519
|
+
workspaceId: string,
|
|
520
|
+
caseUuid: string,
|
|
521
|
+
body: string,
|
|
522
|
+
documentUuids: string[],
|
|
523
|
+
authContext?: AuthContext,
|
|
524
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
525
|
+
): Promise<CaseMessage | null> =>
|
|
526
|
+
withAuthRetry(organizationId, workspaceId, authContext, consentClient, 'Error sending case message:', (token) =>
|
|
527
|
+
sendCaseMessageServer({ organizationId, workspaceId, caseUuid, body, documentUuids, authToken: token, consentClient })
|
|
528
|
+
);
|
|
529
|
+
|
|
530
|
+
export const uploadCaseDocument = async (
|
|
531
|
+
organizationId: string,
|
|
532
|
+
workspaceId: string,
|
|
533
|
+
caseUuid: string,
|
|
534
|
+
file: File,
|
|
535
|
+
authContext?: AuthContext,
|
|
536
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
537
|
+
): Promise<UploadDocumentResponse | null> =>
|
|
538
|
+
withAuthRetry(organizationId, workspaceId, authContext, consentClient, 'Error uploading case document:', (token) =>
|
|
539
|
+
uploadCaseDocumentServer({ organizationId, workspaceId, caseUuid, file, authToken: token, consentClient })
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
export const submitDocumentForRequest = async (
|
|
543
|
+
organizationId: string,
|
|
544
|
+
workspaceId: string,
|
|
545
|
+
caseUuid: string,
|
|
546
|
+
requestEventUuid: string,
|
|
547
|
+
documentUuid: string,
|
|
548
|
+
body: string,
|
|
549
|
+
authContext?: AuthContext,
|
|
550
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
551
|
+
): Promise<CaseMessage | null> =>
|
|
552
|
+
withAuthRetry(organizationId, workspaceId, authContext, consentClient, 'Error submitting document for request:', (token) =>
|
|
553
|
+
submitDocumentForRequestServer({ organizationId, workspaceId, caseUuid, requestEventUuid, documentUuid, body, authToken: token, consentClient })
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
export const getCaseDocument = async (
|
|
557
|
+
organizationId: string,
|
|
558
|
+
workspaceId: string,
|
|
559
|
+
caseUuid: string,
|
|
560
|
+
documentUuid: string,
|
|
561
|
+
authContext?: AuthContext,
|
|
562
|
+
consentClient?: BaseUrlContextValue['consentClient']
|
|
563
|
+
): Promise<MessageDocument | null> =>
|
|
564
|
+
withAuthRetry(organizationId, workspaceId, authContext, consentClient, 'Error fetching case document:', (token) =>
|
|
565
|
+
getCaseDocumentServer({ organizationId, workspaceId, caseUuid, documentUuid, authToken: token, consentClient })
|
|
566
|
+
);
|
|
@@ -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
|
+
};
|