@redacto.io/consent-sdk-react 10.0.0-beta.1 → 10.0.0-beta.12

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 (258) hide show
  1. package/NOTICE.md +17 -0
  2. package/README.md +145 -3
  3. package/dist/chunk-FEGTW73Q.mjs +182 -0
  4. package/dist/{chunk-6A665OPR.mjs → chunk-OGL6OC3A.mjs} +4 -0
  5. package/dist/fonts.d.mts +35 -0
  6. package/dist/fonts.d.ts +35 -0
  7. package/dist/fonts.js +183 -0
  8. package/dist/fonts.mjs +10 -0
  9. package/dist/index.d.mts +44 -5
  10. package/dist/index.d.ts +44 -5
  11. package/dist/index.js +950 -476
  12. package/dist/index.mjs +572 -314
  13. package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
  14. package/dist/privacy-center.d.mts +55 -12
  15. package/dist/privacy-center.d.ts +55 -12
  16. package/dist/privacy-center.js +848 -950
  17. package/dist/privacy-center.mjs +698 -802
  18. package/dist/types-6Aj7faxL.d.mts +57 -0
  19. package/dist/types-6Aj7faxL.d.ts +57 -0
  20. package/package.json +10 -1
  21. package/.turbo/turbo-build.log +0 -22
  22. package/.turbo/turbo-test.log +0 -203
  23. package/.turbo/turbo-verify-pack.log +0 -6
  24. package/CHANGELOG.md +0 -274
  25. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -847
  26. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2133
  27. package/src/RedactoNoticeAssisted/api/index.ts +0 -269
  28. package/src/RedactoNoticeAssisted/api/types.ts +0 -180
  29. package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
  30. package/src/RedactoNoticeAssisted/constants.ts +0 -51
  31. package/src/RedactoNoticeAssisted/i18n.ts +0 -1463
  32. package/src/RedactoNoticeAssisted/index.ts +0 -1
  33. package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
  34. package/src/RedactoNoticeAssisted/styles.ts +0 -730
  35. package/src/RedactoNoticeAssisted/types.ts +0 -24
  36. package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
  37. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1152
  38. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4258
  39. package/src/RedactoNoticeConsent/api/index.ts +0 -573
  40. package/src/RedactoNoticeConsent/api/types.ts +0 -490
  41. package/src/RedactoNoticeConsent/assets/redacto-logo.png +0 -0
  42. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +0 -602
  43. package/src/RedactoNoticeConsent/components/index.ts +0 -7
  44. package/src/RedactoNoticeConsent/constants.ts +0 -20
  45. package/src/RedactoNoticeConsent/index.ts +0 -1
  46. package/src/RedactoNoticeConsent/injectStyles.ts +0 -151
  47. package/src/RedactoNoticeConsent/language-codes.ts +0 -97
  48. package/src/RedactoNoticeConsent/services/storage.ts +0 -122
  49. package/src/RedactoNoticeConsent/styles.ts +0 -409
  50. package/src/RedactoNoticeConsent/types.ts +0 -54
  51. package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
  52. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
  53. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -629
  54. package/src/RedactoNoticeConsentInline/api/index.ts +0 -106
  55. package/src/RedactoNoticeConsentInline/api/types.ts +0 -183
  56. package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
  57. package/src/RedactoNoticeConsentInline/index.ts +0 -1
  58. package/src/RedactoNoticeConsentInline/injectStyles.ts +0 -40
  59. package/src/RedactoNoticeConsentInline/styles.ts +0 -397
  60. package/src/RedactoNoticeConsentInline/types.ts +0 -51
  61. package/src/RedactoNoticeConsentInline/useMediaQuery.ts +0 -36
  62. package/src/RedactoPrivacyCenter/NotificationsPage.tsx +0 -182
  63. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +0 -19
  64. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +0 -156
  65. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +0 -17
  66. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +0 -79
  67. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +0 -36
  68. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +0 -177
  69. package/src/RedactoPrivacyCenter/PrivacyCenterMyReceiptPage.tsx +0 -26
  70. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +0 -58
  71. package/src/RedactoPrivacyCenter/api/actions.ts +0 -680
  72. package/src/RedactoPrivacyCenter/api/client.ts +0 -906
  73. package/src/RedactoPrivacyCenter/api/config.ts +0 -33
  74. package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -260
  75. package/src/RedactoPrivacyCenter/api/orgBranding.ts +0 -16
  76. package/src/RedactoPrivacyCenter/api/upload.ts +0 -93
  77. package/src/RedactoPrivacyCenter/assets/character.svg +0 -31
  78. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +0 -9
  79. package/src/RedactoPrivacyCenter/assets/greenTick.svg +0 -4
  80. package/src/RedactoPrivacyCenter/assets/mail.svg +0 -3
  81. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +0 -9
  82. package/src/RedactoPrivacyCenter/assets/sentImg.svg +0 -9
  83. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +0 -9
  84. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +0 -252
  85. package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +0 -239
  86. package/src/RedactoPrivacyCenter/components/AppShell/AppShell.tsx +0 -240
  87. package/src/RedactoPrivacyCenter/components/AppShell/MobileNavDrawer.tsx +0 -218
  88. package/src/RedactoPrivacyCenter/components/AppShell/NavItem.tsx +0 -205
  89. package/src/RedactoPrivacyCenter/components/AppShell/PageHeader.tsx +0 -107
  90. package/src/RedactoPrivacyCenter/components/AppShell/SidebarNav.tsx +0 -100
  91. package/src/RedactoPrivacyCenter/components/AppShell/TopAppBar.tsx +0 -339
  92. package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +0 -243
  93. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useIsTruncated.ts +0 -28
  94. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useKeyboardShortcut.ts +0 -40
  95. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useSidebarState.ts +0 -62
  96. package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +0 -36
  97. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +0 -38
  98. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +0 -31
  99. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +0 -79
  100. package/src/RedactoPrivacyCenter/components/CaseDetails/FinalizedTooltipWrapper.tsx +0 -25
  101. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +0 -96
  102. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +0 -97
  103. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +0 -156
  104. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +0 -171
  105. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +0 -23
  106. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +0 -116
  107. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +0 -43
  108. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +0 -71
  109. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +0 -469
  110. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +0 -426
  111. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +0 -1198
  112. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -201
  113. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +0 -138
  114. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +0 -7
  115. package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +0 -179
  116. package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +0 -318
  117. package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +0 -333
  118. package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +0 -102
  119. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +0 -159
  120. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +0 -189
  121. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +0 -118
  122. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +0 -66
  123. package/src/RedactoPrivacyCenter/components/DataRequest/ProductSelectionSection.tsx +0 -222
  124. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +0 -331
  125. package/src/RedactoPrivacyCenter/components/Form.tsx +0 -1796
  126. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +0 -174
  127. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +0 -337
  128. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +0 -334
  129. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +0 -173
  130. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +0 -18
  131. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +0 -54
  132. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +0 -57
  133. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +0 -19
  134. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +0 -92
  135. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +0 -20
  136. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +0 -58
  137. package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +0 -10
  138. package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +0 -112
  139. package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +0 -27
  140. package/src/RedactoPrivacyCenter/components/Pagination.tsx +0 -140
  141. package/src/RedactoPrivacyCenter/components/PrivacyCenterEmptyState.tsx +0 -76
  142. package/src/RedactoPrivacyCenter/components/PrivacyCenterSessionExpired.tsx +0 -97
  143. package/src/RedactoPrivacyCenter/components/ReceiptsList.tsx +0 -454
  144. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +0 -270
  145. package/src/RedactoPrivacyCenter/components/SelectUser.tsx +0 -83
  146. package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -193
  147. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +0 -25
  148. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +0 -21
  149. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +0 -159
  150. package/src/RedactoPrivacyCenter/components/constant.ts +0 -52
  151. package/src/RedactoPrivacyCenter/components/groupHelpers.ts +0 -119
  152. package/src/RedactoPrivacyCenter/components/receiptColumns.tsx +0 -203
  153. package/src/RedactoPrivacyCenter/components/types.ts +0 -123
  154. package/src/RedactoPrivacyCenter/components/utils.tsx +0 -10
  155. package/src/RedactoPrivacyCenter/config/routes.ts +0 -9
  156. package/src/RedactoPrivacyCenter/config/table.ts +0 -25
  157. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +0 -160
  158. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +0 -47
  159. package/src/RedactoPrivacyCenter/context/BrandingContext.tsx +0 -52
  160. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +0 -92
  161. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +0 -181
  162. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +0 -11
  163. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +0 -96
  164. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +0 -30
  165. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +0 -80
  166. package/src/RedactoPrivacyCenter/context/ProfileSwitchContext.tsx +0 -15
  167. package/src/RedactoPrivacyCenter/context/types.ts +0 -19
  168. package/src/RedactoPrivacyCenter/lib/api.ts +0 -756
  169. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
  170. package/src/RedactoPrivacyCenter/lib/constants.ts +0 -277
  171. package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
  172. package/src/RedactoPrivacyCenter/lib/locales.ts +0 -105
  173. package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
  174. package/src/RedactoPrivacyCenter/lib/types.ts +0 -868
  175. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
  176. package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
  177. package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
  178. package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
  179. package/src/RedactoPrivacyCenter/lib/utils.ts +0 -783
  180. package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -340
  181. package/src/RedactoPrivacyCenter/locales/bho/translation.json +0 -340
  182. package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -340
  183. package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -340
  184. package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -340
  185. package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -354
  186. package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -340
  187. package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -340
  188. package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -343
  189. package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -340
  190. package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -340
  191. package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -340
  192. package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -340
  193. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -340
  194. package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -340
  195. package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -340
  196. package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -340
  197. package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -340
  198. package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -340
  199. package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -340
  200. package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -340
  201. package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -340
  202. package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -340
  203. package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -340
  204. package/src/RedactoPrivacyCenter/styles/applyBrandingTheme.ts +0 -66
  205. package/src/RedactoPrivacyCenter/styles/base.css +0 -117
  206. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +0 -3103
  207. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -814
  208. package/src/RedactoPrivacyCenter/styles/responsive.ts +0 -138
  209. package/src/RedactoPrivacyCenter/styles/variables.css +0 -96
  210. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +0 -387
  211. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +0 -468
  212. package/src/RedactoPrivacyCenter/table/index.ts +0 -2
  213. package/src/RedactoPrivacyCenter/types/images.d.ts +0 -29
  214. package/src/RedactoPrivacyCenter/ui/Footer.tsx +0 -69
  215. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +0 -54
  216. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +0 -93
  217. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +0 -47
  218. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -69
  219. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
  220. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
  221. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
  222. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
  223. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
  224. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
  225. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
  226. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
  227. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
  228. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
  229. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
  230. package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
  231. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
  232. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
  233. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
  234. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
  235. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
  236. package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
  237. package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
  238. package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
  239. package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
  240. package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
  241. package/src/index.ts +0 -19
  242. package/src/privacy-center.ts +0 -113
  243. package/src/shared/api-errors.ts +0 -180
  244. package/src/types/css.d.ts +0 -4
  245. package/src/types/images.d.ts +0 -19
  246. package/src/types/react-jsx.d.ts +0 -26
  247. package/tests/DataAvailabilityContext.test.tsx +0 -123
  248. package/tests/Form.test.tsx +0 -1287
  249. package/tests/ProductSelectionSection.test.tsx +0 -328
  250. package/tests/RequestSubmit.test.tsx +0 -135
  251. package/tests/consentClient.test.ts +0 -171
  252. package/tests/manageConsentServer.test.ts +0 -38
  253. package/tests/mocks.ts +0 -257
  254. package/tests/resolveContactFromJwt.test.ts +0 -44
  255. package/tests/setup.ts +0 -16
  256. package/tsconfig.json +0 -16
  257. package/tsup.config.ts +0 -31
  258. package/vitest.config.ts +0 -16
@@ -1,67 +0,0 @@
1
- import { useMemo } from 'react';
2
- import { useTranslation } from 'react-i18next';
3
- import { ConsentStatusEnum } from '../types';
4
- import { formatDateTime as formatDateTimeShared } from '../../utils/date';
5
-
6
- // Re-export shared date formatting
7
- export const formatDateTime = formatDateTimeShared;
8
-
9
- // Leading characters that spreadsheet apps (Excel/Sheets) may interpret as a
10
- // formula; values starting with these are prefixed with a quote to neutralize
11
- // CSV formula injection.
12
- const CSV_FORMULA_TRIGGERS = ['=', '+', '-', '@', '\t', '\r'];
13
-
14
- // Byte-order mark so Excel detects UTF-8 and renders localized labels correctly.
15
- const UTF8_BOM = '\uFEFF';
16
-
17
- export const useStatusOptions = () => {
18
- const { t } = useTranslation();
19
- return useMemo(
20
- () => [
21
- { label: t('statusActive'), value: ConsentStatusEnum.ACTIVE },
22
- { label: t('statusWithdrawn'), value: ConsentStatusEnum.WITHDRAWN },
23
- { label: t('statusExpired'), value: ConsentStatusEnum.EXPIRED },
24
- { label: t('statusDeclined'), value: ConsentStatusEnum.DECLINED },
25
- ],
26
- [t]
27
- );
28
- };
29
-
30
- // Rows must be pre-formatted display strings keyed by their (already localized)
31
- // column header. Each cell is written verbatim so the CSV matches the on-screen
32
- // table exactly; null/undefined become an empty cell rather than the text "null".
33
- export const exportTableToCSV = (rows: Record<string, string>[]) => {
34
- if (!rows || rows.length === 0) {
35
- return;
36
- }
37
-
38
- const escape = (value: string | null | undefined) => {
39
- const raw = value ?? '';
40
- // Defuse spreadsheet formula injection by prefixing risky leading chars.
41
- const safe =
42
- raw.length > 0 && CSV_FORMULA_TRIGGERS.includes(raw[0]) ? `'${raw}` : raw;
43
- return `"${safe.replace(/"/g, '""')}"`;
44
- };
45
-
46
- const columns = Object.keys(rows[0]);
47
- const headers = columns.map(escape).join(',');
48
- const csvRows = rows.map((row) =>
49
- columns.map((col) => escape(row[col])).join(',')
50
- );
51
-
52
- const csvContent = [headers, ...csvRows].join('\n');
53
-
54
- try {
55
- const blob = new Blob([UTF8_BOM, csvContent], { type: 'text/csv;charset=utf-8;' });
56
- const url = URL.createObjectURL(blob);
57
- const link = document.createElement('a');
58
- link.href = url;
59
- link.setAttribute('download', `consent-records.csv`);
60
- document.body.appendChild(link);
61
- link.click();
62
- document.body.removeChild(link);
63
- URL.revokeObjectURL(url);
64
- } catch (error) {
65
- console.error('Failed to export CSV:', error);
66
- }
67
- };
@@ -1,277 +0,0 @@
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
- import type { DocumentRequestStatus, DocumentRequestStatusInfo, NotificationCTA, NotificationType, NotificationCategory, IconCategory, FilterTab } from './types';
8
- import { IoPersonOutline, IoTimeOutline, IoDocumentOutline, IoShieldCheckmarkOutline, IoAlertCircleOutline, IoSettingsOutline } from 'react-icons/io5';
9
-
10
- export const useRequestTypeLabels = () => {
11
- const { t } = useTranslation();
12
-
13
- return {
14
- [RequestTypeEnum.ACCESS]: t('access'),
15
- [RequestTypeEnum.CORRECTION]: t('correction'),
16
- [RequestTypeEnum.ERASURE]: t('erasure'),
17
- [RequestTypeEnum.GRIEVANCE]: t('grievance'),
18
- [RequestTypeEnum.NOMINATION]: t('nomination'),
19
- } as Record<RequestTypeEnum, string>;
20
- };
21
-
22
- export const languageOptions = [
23
- { value: 'en', label: 'English' },
24
- { value: 'hi', label: 'हिन्दी (Hindi)' },
25
- { value: 'te', label: 'తెలుగు (Telugu)' },
26
- { value: 'mr', label: 'मराठी (Marathi)' },
27
- { value: 'ta', label: 'தமிழ் (Tamil)' },
28
- { value: 'ur', label: 'اردو (Urdu)' },
29
- { value: 'gu', label: 'ગુજરાતી (Gujarati)' },
30
- { value: 'kn', label: 'ಕನ್ನಡ (Kannada)' },
31
- { value: 'ml', label: 'മലയാളം (Malayalam)' },
32
- { value: 'pa', label: 'ਪੰਜਾਬੀ (Punjabi)' },
33
- { value: 'or', label: 'ଓଡ଼ିଆ (Odia)' },
34
- { value: 'as', label: 'অসমীয়া (Assamese)' },
35
- { value: 'bn', label: 'বাংলা (Bengali)' },
36
- { value: 'mai', label: 'मैथिली (Maithili)' },
37
- { value: 'ne', label: 'नेपाली (Nepali)' },
38
- { value: 'sd', label: 'سنڌي (Sindhi)' },
39
- { value: 'doi', label: 'डोगरी (Dogri)' },
40
- { value: 'mni-Mtei', label: 'ꯃꯩꯇꯩꯂꯣꯟ (Manipuri)' },
41
- { value: 'gom', label: 'कोंकणी (Goan Konkani)' },
42
- { value: 'sa', label: 'संस्कृतम् (Sanskrit)' },
43
- { value: 'bho', label: 'भोजपुरी (Bhojpuri)' },
44
- { value: 'brx', label: 'बड़ो (Bodo)' },
45
- { value: 'ks', label: 'كٲشُر (Kashmiri)' },
46
- { value: 'sat', label: 'ᱥᱟᱱᱛᱟᱲᱤ (Santali)' },
47
- ];
48
-
49
- export const useTimePeriodOptions = () => {
50
- const { t } = useTranslation();
51
-
52
- return [
53
- { value: '1', label: t('today') },
54
- { value: '7', label: t('last7Days') },
55
- { value: '30', label: t('last30Days') },
56
- { value: '90', label: t('last3Months') },
57
- ];
58
- };
59
-
60
- export const useGrievanceTabs = () => {
61
- const { t } = useTranslation();
62
-
63
- return [
64
- { id: GRIEVANCE_TAB_IDS.ALL, label: t('allRequests') },
65
- { id: GRIEVANCE_TAB_IDS.PROCESSING, label: t('processing') },
66
- { id: GRIEVANCE_TAB_IDS.COMPLETED, label: t('completed') },
67
- { id: GRIEVANCE_TAB_IDS.REJECTED, label: t('rejected') },
68
- ];
69
- };
70
-
71
- export type PageChromeConfig = {
72
- titleKey: string;
73
- descriptionKey: string;
74
- };
75
-
76
- export const PAGE_CHROME_BY_PAGE: Record<InternalPage, PageChromeConfig> = {
77
- 'consent-manager': {
78
- titleKey: 'manageConsent',
79
- descriptionKey: 'manageConsentSubtitle',
80
- },
81
- form: {
82
- titleKey: 'grievanceRequests',
83
- descriptionKey: 'grievanceSubtitle',
84
- },
85
- activity: {
86
- titleKey: 'activities',
87
- descriptionKey: 'activitiesSubtitle',
88
- },
89
- 'case-details': {
90
- titleKey: 'caseDetails',
91
- descriptionKey: 'yourPrivacyCenter',
92
- },
93
- notifications: {
94
- titleKey: 'notificationHub',
95
- descriptionKey: 'notificationHubSubtitle',
96
- },
97
- receipts: {
98
- titleKey: 'myReceipt',
99
- descriptionKey: 'myReceiptSubtitle',
100
- },
101
- };
102
-
103
- const HREF_TO_NAME_KEY: Record<string, string> = {
104
- 'consent-manager': 'consentManager',
105
- form: 'grievance',
106
- activity: 'activity',
107
- receipts: 'myReceipt',
108
- };
109
-
110
- export const useMenuItemsPC = (): MenuItem[] => {
111
- const { t } = useTranslation();
112
- return menuItemsPC.map((item) => ({
113
- ...item,
114
- name: t((item.href && HREF_TO_NAME_KEY[item.href]) ?? item.name),
115
- }));
116
- };
117
-
118
- // ─── Upload validation ────────────────────────────────────────────────────────
119
-
120
- export const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
121
-
122
- export const ALLOWED_MIME_TYPES = [
123
- 'application/pdf',
124
- 'image/jpeg',
125
- 'image/png',
126
- 'image/webp',
127
- 'application/msword',
128
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
129
- 'application/vnd.ms-excel',
130
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
131
- 'text/plain',
132
- 'text/csv',
133
- ];
134
-
135
- // ─── Status colors ───────────────────────────────────────────────────────────
136
-
137
- export const STATUS_COLORS = {
138
- success: { color: '#16a34a', bg: '#f0fdf4', border: '#bbf7d0' },
139
- error: { color: '#dc2626', bg: '#fef2f2', border: '#fecaca' },
140
- warning: { color: '#d97706', bg: '#fffbeb', border: '#fde68a' },
141
- info: { color: '#2563eb', bg: '#f8fbff', border: '#93c5fd' },
142
- infoDark: '#1d4ed8',
143
- infoBanner: { color: '#1d4ed8', bg: '#eff6ff', border: '#bfdbfe' },
144
- } as const;
145
-
146
- // ─── Case statuses ────────────────────────────────────────────────────────────
147
-
148
- export const TERMINAL_CASE_STATUSES = ['completed', 'rejected', 'declined', 'expired'] as const;
149
-
150
- export const CASE_FINALIZED_TOOLTIP_KEY = 'caseFinalizedMessagesTooltip';
151
- export const CASE_FINALIZED_TOOLTIP_FALLBACK = 'This case is finalized — messages can no longer be sent.';
152
-
153
- export const useCaseFinalizedTooltip = () => {
154
- const { t } = useTranslation();
155
- return t(CASE_FINALIZED_TOOLTIP_KEY, CASE_FINALIZED_TOOLTIP_FALLBACK);
156
- };
157
-
158
- // ─── Document request ─────────────────────────────────────────────────────────
159
-
160
- export const UPLOAD_ACTIVE_STATUSES: DocumentRequestStatus[] = ['pending', 'replacement_requested'];
161
-
162
- export const DOCUMENT_REQUEST_STATUS_LABEL: Record<DocumentRequestStatus, DocumentRequestStatusInfo> = {
163
- pending: { labelKey: 'docStatusPending', color: STATUS_COLORS.warning.color },
164
- under_review: { labelKey: 'docStatusUnderReview', color: STATUS_COLORS.info.color },
165
- approved: { labelKey: 'docStatusApproved', color: STATUS_COLORS.success.color },
166
- rejected: { labelKey: 'docStatusRejected', color: STATUS_COLORS.error.color },
167
- replacement_requested: { labelKey: 'docStatusReplacementRequested', color: STATUS_COLORS.warning.color },
168
- };
169
-
170
- export const ACTIVITY_DATE_FORMATS = {
171
- DISPLAY: 'MMM D, YYYY [at] h:mm A',
172
- TOOLTIP: 'MMMM D, YYYY [at] h:mm:ss A',
173
- DATE: 'MMM D, YYYY',
174
- TIME: 'h:mm A',
175
- } as const;
176
-
177
- export const ACTIVITY_PAGE_SIZE = 10;
178
-
179
-
180
- // ─── Token refresh ─────────────────────────────────────────────────────────
181
-
182
- // Backoff window for *transient* OTP-refresh failures (network / 5xx). After a
183
- // transient failure we wait at least MIN before the next attempt and grow the
184
- // window exponentially up to MAX, so a flaky connection can't turn the
185
- // proactive-refresh path into a request storm (incident 2026-06-22). Terminal
186
- // failures (expired / already-used token) are handled by the circuit breaker in
187
- // lib/utils.ts and are not retried at all.
188
- export const MIN_REFRESH_BACKOFF_MS = 30_000; // 30s
189
- export const MAX_REFRESH_BACKOFF_MS = 300_000; // 5m
190
-
191
- // Where the privacy center persists the refresh token: localStorage (origin-
192
- // scoped, no path matching) under a Redacto-namespaced key, so it is readable
193
- // regardless of the host app's basePath and never collides with a host's own
194
- // `refresh_token` cookie. LEGACY_REFRESH_TOKEN_COOKIE is the cookie name older
195
- // SDK versions wrote (at path=/privacy-center); only that path is ever cleared.
196
- export const REFRESH_TOKEN_STORAGE_KEY = 'redacto_pc_refresh_token';
197
- export const LEGACY_REFRESH_TOKEN_COOKIE = 'refresh_token';
198
-
199
- // ─── DSAR request form ─────────────────────────────────────────────────────
200
-
201
- // Max product groups requested from the Go ledger's user-consents when
202
- // sourcing the DSAR request-form product picker (Approach A). The ledger caps
203
- // user-consents page size at 100; the picker needs all of a principal's
204
- // groups, so we request the max. A principal with >100 product groups would
205
- // need group-level pagination (follow-up).
206
- export const FORM_PICKER_GROUP_LIMIT = 100;
207
-
208
- // ─── Notification Hub ──────────────────────────────────────────────────────
209
-
210
- export const POLL_INTERVAL = 30_000;
211
- export const NOTIFICATION_PAGE_SIZE = 10;
212
- export const NOTIFICATION_DROPDOWN_LIMIT = 5;
213
-
214
- export const TAB_TO_CATEGORY: Record<FilterTab, NotificationCategory | undefined> = {
215
- all: undefined,
216
- consent: 'consent',
217
- request: 'request',
218
- system: 'system',
219
- };
220
-
221
- export const TYPE_TO_ICON_CATEGORY: Record<NotificationType, IconCategory> = {
222
- guardian_verification_request: 'guardian',
223
- consent_expiry_warning: 'consent',
224
- new_consent_notice: 'system',
225
- consent_withdrawal_confirmation: 'withdrawal',
226
- data_request_status_update: 'access',
227
- case_message: 'access',
228
- grievance_status_update: 'grievance',
229
- consent_regrant_prompt: 'consent',
230
- };
231
-
232
- export const ICON_MAP: Record<IconCategory, typeof IoPersonOutline> = {
233
- guardian: IoPersonOutline,
234
- consent: IoTimeOutline,
235
- access: IoDocumentOutline,
236
- withdrawal: IoShieldCheckmarkOutline,
237
- grievance: IoAlertCircleOutline,
238
- system: IoSettingsOutline,
239
- };
240
-
241
- export const ICON_COLORS: Record<IconCategory, string> = {
242
- guardian: '#7c3aed',
243
- consent: '#ea580c',
244
- access: '#16a34a',
245
- withdrawal: '#2563eb',
246
- grievance: '#dc2626',
247
- system: '#6b7280',
248
- };
249
-
250
- export const CTA_VARIANT_CLASS: Record<NotificationCTA['style'], string> = {
251
- primary: 'pc-notification-cta--primary',
252
- danger: 'pc-notification-cta--danger',
253
- secondary: 'pc-notification-cta--secondary',
254
- };
255
-
256
- export const useNotificationFilterTabs = () => {
257
- const { t } = useTranslation();
258
- return [
259
- { key: 'all' as FilterTab, label: t('all') },
260
- { key: 'consent' as FilterTab, label: t('consent') },
261
- { key: 'request' as FilterTab, label: t('requests') },
262
- { key: 'system' as FilterTab, label: t('system') },
263
- ];
264
- };
265
-
266
- export const useNotificationStatLabels = () => {
267
- const { t } = useTranslation();
268
- return {
269
- total: t('total'),
270
- unread: t('unread'),
271
- action_needed: t('actionNeeded'),
272
- acknowledged: t('acknowledged'),
273
- };
274
- };
275
-
276
-
277
- export const CASE_DETAILS_PREFIX = '/case-details/';
@@ -1,81 +0,0 @@
1
- import dayjs from 'dayjs';
2
- import 'dayjs/locale/hi';
3
- import 'dayjs/locale/te';
4
- import 'dayjs/locale/mr';
5
- import 'dayjs/locale/ta';
6
- import 'dayjs/locale/ur';
7
- import 'dayjs/locale/gu';
8
- import 'dayjs/locale/kn';
9
- import 'dayjs/locale/ml';
10
- import 'dayjs/locale/pa-in';
11
- import 'dayjs/locale/ne';
12
- import 'dayjs/locale/sd';
13
- import 'dayjs/locale/bn';
14
- import 'dayjs/locale/gom-latn';
15
- import i18n from 'i18next';
16
- import LanguageDetector from 'i18next-browser-languagedetector';
17
- import { initReactI18next } from 'react-i18next';
18
- import translations from './locales';
19
-
20
- // Map app language codes to dayjs locale IDs.
21
- // Languages not listed here fall back to 'en'.
22
- const dayjsLocaleMap: Record<string, string> = {
23
- hi: 'hi',
24
- te: 'te',
25
- mr: 'mr',
26
- ta: 'ta',
27
- ur: 'ur',
28
- gu: 'gu',
29
- kn: 'kn',
30
- ml: 'ml',
31
- pa: 'pa-in',
32
- ne: 'ne',
33
- sd: 'sd',
34
- bn: 'bn',
35
- gom: 'gom-latn',
36
- };
37
-
38
- function syncDayjsLocale(lng: string) {
39
- dayjs.locale(dayjsLocaleMap[lng] || 'en');
40
- }
41
-
42
- // Convert translations to i18next resources format
43
- // i18next expects: { [language]: { [namespace]: { [key]: value } } }
44
- const resources: Record<string, Record<string, any>> = {};
45
- Object.keys(translations).forEach((lang) => {
46
- resources[lang] = translations[lang];
47
- });
48
-
49
- i18n
50
- .use(LanguageDetector)
51
- .use(initReactI18next)
52
- .init({
53
- resources,
54
- fallbackLng: 'en',
55
- defaultNS: 'translation',
56
- ns: ['translation'],
57
- debug: false,
58
- interpolation: {
59
- escapeValue: false,
60
- },
61
- detection: {
62
- order: ['sessionStorage', 'navigator', 'htmlTag'],
63
- caches: ['sessionStorage'],
64
- lookupSessionStorage: 'i18nextLng',
65
- convertDetectedLanguage: (lng: string) => {
66
- // Extract base language code (e.g. 'en-US' -> 'en') so it matches
67
- // our supported language keys, but preserve script subtags like 'mni-Mtei'.
68
- const base = lng.split('-')[0];
69
- if (base && resources[base]) return base;
70
- return lng;
71
- },
72
- },
73
- react: {
74
- useSuspense: false,
75
- },
76
- });
77
-
78
- i18n.on('languageChanged', syncDayjsLocale);
79
- syncDayjsLocale(i18n.language);
80
-
81
- export default i18n;
@@ -1,105 +0,0 @@
1
- // Static imports of all locale files for bundling
2
- import enTranslation from '../locales/en/translation.json';
3
- import asTranslation from '../locales/as/translation.json';
4
- import bnTranslation from '../locales/bn/translation.json';
5
- import bhoTranslation from '../locales/bho/translation.json';
6
- import brxTranslation from '../locales/brx/translation.json';
7
- import doiTranslation from '../locales/doi/translation.json';
8
- import gomTranslation from '../locales/gom/translation.json';
9
- import guTranslation from '../locales/gu/translation.json';
10
- import hiTranslation from '../locales/hi/translation.json';
11
- import knTranslation from '../locales/kn/translation.json';
12
- import ksTranslation from '../locales/ks/translation.json';
13
- import maiTranslation from '../locales/mai/translation.json';
14
- import mlTranslation from '../locales/ml/translation.json';
15
- import mniMteiTranslation from '../locales/mni-Mtei/translation.json';
16
- import mrTranslation from '../locales/mr/translation.json';
17
- import neTranslation from '../locales/ne/translation.json';
18
- import orTranslation from '../locales/or/translation.json';
19
- import paTranslation from '../locales/pa/translation.json';
20
- import saTranslation from '../locales/sa/translation.json';
21
- import satTranslation from '../locales/sat/translation.json';
22
- import sdTranslation from '../locales/sd/translation.json';
23
- import taTranslation from '../locales/ta/translation.json';
24
- import teTranslation from '../locales/te/translation.json';
25
- import urTranslation from '../locales/ur/translation.json';
26
-
27
- const activityFetchErrorTranslations: Record<string, string> = {
28
- en: 'Failed to fetch activity data',
29
- as: 'কাৰ্যকলাপৰ তথ্য আনিবলৈ ব্যৰ্থ',
30
- bn: 'কার্যকলাপের ডেটা আনতে ব্যর্থ',
31
- bho: 'गतिविधि डेटा लावे में विफल',
32
- brx: 'खामानि डाटा लाङो दिहुनायाव असफल',
33
- doi: 'गतिविधि डेटा लावै मे असफल',
34
- gom: 'क्रियाकलाप डेटा आणपांत अयशस्वी',
35
- gu: 'પ્રવૃત્તિ ડેટા મેળવવામાં નિષ્ફળ',
36
- hi: 'गतिविधि डेटा लाने में विफल',
37
- kn: 'ಚಟುವಟಿಕೆ ಡೇಟಾವನ್ನು ತರಲು ವಿಫಲ',
38
- ks: 'سرگرمی ڈیٹا حاصل کرنے میں ناکام',
39
- mai: 'गतिविधि डेटा लावै मे असफल',
40
- ml: 'പ്രവർത്തന ഡാറ്റ ലഭ്യമാക്കുന്നതിൽ പരാജയപ്പെട്ടു',
41
- 'mni-Mtei': 'ꯈꯨꯗꯝꯕꯤꯠ ꯗꯦꯇꯥ ꯐꯪꯉꯕꯗ ꯌꯥꯝꯅꯥ ꯋꯥꯏ꯫',
42
- mr: 'क्रियाकलाप डेटा आणण्यात अयशस्वी',
43
- ne: 'गतिविधि डेटा ल्याउन असफल',
44
- or: 'କାର୍ଯ୍ୟକଳାପ ତଥ୍ୟ ଆଣିବାରେ ବିଫଳ',
45
- pa: 'ਗਤੀਵਿਧੀ ਡਾਟਾ ਲਿਆਉਣ ਵਿੱਚ ਅਸਫਲ',
46
- sa: 'क्रियाकलाप-दत्तांशम् आने विफलम्',
47
- sat: 'ᱠᱟᱹᱢᱤ ᱰᱟᱴᱟ ᱟᱹᱜᱩ ᱨᱮ ᱵᱤᱯᱚᱠ',
48
- sd: 'سرگرمي جي ڊيٽا حاصل ڪرڻ ۾ ناڪام',
49
- ta: 'செயல்பாட்டு தரவை பெற முடியவில்லை',
50
- te: 'కార్యకలాప డేటాను తెచ్చుకోవడం విఫలమైంది',
51
- ur: 'سرگرمی کا ڈیٹا حاصل کرنے میں ناکام',
52
- };
53
-
54
- function withSharedActivityErrors(
55
- language: string,
56
- translation: Record<string, any>
57
- ) {
58
- return {
59
- ...translation,
60
- failedToFetchActivityData:
61
- activityFetchErrorTranslations[language] ??
62
- activityFetchErrorTranslations.en,
63
- };
64
- }
65
-
66
- // Map of language codes to translation objects
67
- const translations: Record<string, Record<string, any>> = {
68
- en: { translation: withSharedActivityErrors('en', enTranslation) },
69
- as: { translation: withSharedActivityErrors('as', asTranslation) },
70
- bn: { translation: withSharedActivityErrors('bn', bnTranslation) },
71
- bho: { translation: withSharedActivityErrors('bho', bhoTranslation) },
72
- brx: { translation: withSharedActivityErrors('brx', brxTranslation) },
73
- doi: { translation: withSharedActivityErrors('doi', doiTranslation) },
74
- gom: { translation: withSharedActivityErrors('gom', gomTranslation) },
75
- gu: { translation: withSharedActivityErrors('gu', guTranslation) },
76
- hi: { translation: withSharedActivityErrors('hi', hiTranslation) },
77
- kn: { translation: withSharedActivityErrors('kn', knTranslation) },
78
- ks: { translation: withSharedActivityErrors('ks', ksTranslation) },
79
- mai: { translation: withSharedActivityErrors('mai', maiTranslation) },
80
- ml: { translation: withSharedActivityErrors('ml', mlTranslation) },
81
- 'mni-Mtei': { translation: withSharedActivityErrors('mni-Mtei', mniMteiTranslation) },
82
- mr: { translation: withSharedActivityErrors('mr', mrTranslation) },
83
- ne: { translation: withSharedActivityErrors('ne', neTranslation) },
84
- or: { translation: withSharedActivityErrors('or', orTranslation) },
85
- pa: { translation: withSharedActivityErrors('pa', paTranslation) },
86
- sa: { translation: withSharedActivityErrors('sa', saTranslation) },
87
- sat: { translation: withSharedActivityErrors('sat', satTranslation) },
88
- sd: { translation: withSharedActivityErrors('sd', sdTranslation) },
89
- ta: { translation: withSharedActivityErrors('ta', taTranslation) },
90
- te: { translation: withSharedActivityErrors('te', teTranslation) },
91
- ur: { translation: withSharedActivityErrors('ur', urTranslation) },
92
- };
93
-
94
- export function getTranslation(language: string, namespace: string) {
95
- const langTranslations = translations[language];
96
- if (!langTranslations) {
97
- // Fallback to English if language not found
98
- const fallback = translations.en?.[namespace];
99
- return fallback || {};
100
- }
101
- const translation = langTranslations[namespace];
102
- return translation || {};
103
- }
104
-
105
- export default translations;
@@ -1,141 +0,0 @@
1
- import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
2
- import {
3
- fetchCaseHistory,
4
- getCaseMessages,
5
- sendCaseMessage,
6
- uploadCaseDocument,
7
- submitDocumentForRequest,
8
- type AuthContext,
9
- } from './api';
10
- import { useBaseUrl } from '../context/BaseUrlContext';
11
- import { useCurrentLanguage } from './useCurrentLanguage';
12
- import { isTerminalRefreshError } from '../api/fetcher';
13
- import type { SendCaseMessageInput, SubmitDocumentForRequestInput } from './types';
14
-
15
- export const useCaseHistory = (
16
- organizationId: string | undefined,
17
- workspaceId: string | undefined,
18
- contact: string | undefined,
19
- authContext?: AuthContext
20
- ) => {
21
- const { consentClient } = useBaseUrl();
22
- // Include accessToken in queryKey so queries refetch when tokens change
23
- // This ensures data is refetched with new tokens after refresh
24
- const accessToken = authContext?.accessToken;
25
- const { currentLanguage, langParam } = useCurrentLanguage();
26
-
27
- return useQuery({
28
- queryKey: ['caseHistory', organizationId, workspaceId, contact, accessToken, currentLanguage],
29
- queryFn: async () => {
30
- if (!organizationId || !workspaceId || !contact) {
31
- return [];
32
- }
33
- const response = await fetchCaseHistory(organizationId, workspaceId, contact, undefined, undefined, authContext, consentClient, langParam);
34
- return response?.data || [];
35
- },
36
- enabled: !!organizationId && !!workspaceId && !!contact && !!consentClient,
37
- // Don't retry terminal auth failures — retrying a dead token only adds load
38
- // (incident 2026-06-22). Transient failures get a single backed-off retry.
39
- retry: (failureCount, error) => !isTerminalRefreshError(error) && failureCount < 1,
40
- retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30_000),
41
- });
42
- };
43
-
44
- // ─── Case Communication ──────────────────────────────────────────────────────
45
-
46
- export const useCaseMessages = (
47
- organizationId: string | undefined,
48
- workspaceId: string | undefined,
49
- caseUuid: string | undefined,
50
- authContext?: AuthContext
51
- ) => {
52
- const { consentClient } = useBaseUrl();
53
- const accessToken = authContext?.accessToken;
54
-
55
- return useQuery({
56
- queryKey: ['caseMessages', organizationId, workspaceId, caseUuid, accessToken],
57
- queryFn: async () => {
58
- if (!organizationId || !workspaceId || !caseUuid) return [];
59
- const result = await getCaseMessages(organizationId, workspaceId, caseUuid, authContext, consentClient);
60
- if (result === null) throw new Error('Failed to fetch case messages');
61
- return result;
62
- },
63
- // Sort ascending (oldest → newest) regardless of server return order.
64
- // ISO 8601 strings sort correctly as strings, so we fall back to that
65
- // if Date parsing fails (avoids NaN comparisons leaving order undefined).
66
- select: (data) =>
67
- [...data].sort((a, b) => {
68
- const ta = new Date(a.created_at).getTime();
69
- const tb = new Date(b.created_at).getTime();
70
- if (isNaN(ta) || isNaN(tb)) return a.created_at < b.created_at ? -1 : 1;
71
- return ta - tb;
72
- }),
73
- enabled: !!organizationId && !!workspaceId && !!caseUuid && !!consentClient,
74
- // Don't retry terminal auth failures — retrying a dead token only adds load
75
- // (incident 2026-06-22). Transient failures get a single backed-off retry.
76
- retry: (failureCount, error) => !isTerminalRefreshError(error) && failureCount < 1,
77
- retryDelay: (attempt) => Math.min(1000 * 2 ** attempt, 30_000),
78
- });
79
- };
80
-
81
- export const useSendCaseMessage = (
82
- organizationId: string | undefined,
83
- workspaceId: string | undefined,
84
- caseUuid: string | undefined,
85
- authContext?: AuthContext
86
- ) => {
87
- const { consentClient } = useBaseUrl();
88
- const queryClient = useQueryClient();
89
-
90
- return useMutation({
91
- mutationFn: async ({ body, documentUuids }: SendCaseMessageInput) => {
92
- if (!organizationId || !workspaceId || !caseUuid) throw new Error('Missing params');
93
- const result = await sendCaseMessage(organizationId, workspaceId, caseUuid, body, documentUuids, authContext, consentClient);
94
- if (result === null) throw new Error('Send case message failed');
95
- return result;
96
- },
97
- onSuccess: () => {
98
- queryClient.invalidateQueries({ queryKey: ['caseMessages', organizationId, workspaceId, caseUuid] });
99
- },
100
- });
101
- };
102
-
103
- export const useUploadCaseDocument = (
104
- organizationId: string | undefined,
105
- workspaceId: string | undefined,
106
- caseUuid: string | undefined,
107
- authContext?: AuthContext
108
- ) => {
109
- const { consentClient } = useBaseUrl();
110
-
111
- return useMutation({
112
- mutationFn: async (file: File) => {
113
- if (!organizationId || !workspaceId || !caseUuid) throw new Error('Missing params');
114
- const result = await uploadCaseDocument(organizationId, workspaceId, caseUuid, file, authContext, consentClient);
115
- if (result === null) throw new Error('Upload case document failed');
116
- return result;
117
- },
118
- });
119
- };
120
-
121
- export const useSubmitDocumentForRequest = (
122
- organizationId: string | undefined,
123
- workspaceId: string | undefined,
124
- caseUuid: string | undefined,
125
- authContext?: AuthContext
126
- ) => {
127
- const { consentClient } = useBaseUrl();
128
- const queryClient = useQueryClient();
129
-
130
- return useMutation({
131
- mutationFn: async ({ requestEventUuid, documentUuid, body }: SubmitDocumentForRequestInput) => {
132
- if (!organizationId || !workspaceId || !caseUuid) throw new Error('Missing params');
133
- const result = await submitDocumentForRequest(organizationId, workspaceId, caseUuid, requestEventUuid, documentUuid, body, authContext, consentClient);
134
- if (result === null) throw new Error('Submit document for request failed');
135
- return result;
136
- },
137
- onSuccess: () => {
138
- queryClient.invalidateQueries({ queryKey: ['caseMessages', organizationId, workspaceId, caseUuid] });
139
- },
140
- });
141
- };