@redacto.io/consent-sdk-react 10.0.0-beta.9 → 10.0.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 (264) hide show
  1. package/NOTICE.md +17 -0
  2. package/README.md +141 -3
  3. package/dist/chunk-FEGTW73Q.mjs +182 -0
  4. package/dist/fonts.d.mts +35 -0
  5. package/dist/fonts.d.ts +35 -0
  6. package/dist/fonts.js +183 -0
  7. package/dist/fonts.mjs +10 -0
  8. package/dist/index.d.mts +12 -1
  9. package/dist/index.d.ts +12 -1
  10. package/dist/index.js +724 -365
  11. package/dist/index.mjs +346 -201
  12. package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
  13. package/dist/privacy-center.d.mts +0 -1
  14. package/dist/privacy-center.d.ts +0 -1
  15. package/dist/privacy-center.js +2 -66
  16. package/dist/privacy-center.mjs +2 -66
  17. package/dist/types-6Aj7faxL.d.mts +57 -0
  18. package/dist/types-6Aj7faxL.d.ts +57 -0
  19. package/package.json +10 -1
  20. package/.turbo/turbo-build.log +0 -22
  21. package/.turbo/turbo-test.log +0 -203
  22. package/.turbo/turbo-verify-pack.log +0 -6
  23. package/CHANGELOG.md +0 -353
  24. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -934
  25. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2160
  26. package/src/RedactoNoticeAssisted/api/index.ts +0 -275
  27. package/src/RedactoNoticeAssisted/api/types.ts +0 -182
  28. package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
  29. package/src/RedactoNoticeAssisted/constants.ts +0 -51
  30. package/src/RedactoNoticeAssisted/i18n.ts +0 -1408
  31. package/src/RedactoNoticeAssisted/index.ts +0 -1
  32. package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
  33. package/src/RedactoNoticeAssisted/styles.ts +0 -730
  34. package/src/RedactoNoticeAssisted/types.ts +0 -26
  35. package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
  36. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1152
  37. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4308
  38. package/src/RedactoNoticeConsent/api/index.ts +0 -542
  39. package/src/RedactoNoticeConsent/api/sandbox.ts +0 -150
  40. package/src/RedactoNoticeConsent/api/types.ts +0 -515
  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 -95
  48. package/src/RedactoNoticeConsent/services/storage.ts +0 -122
  49. package/src/RedactoNoticeConsent/styles.ts +0 -409
  50. package/src/RedactoNoticeConsent/types.ts +0 -80
  51. package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
  52. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
  53. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -687
  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 -93
  71. package/src/RedactoPrivacyCenter/api/actions.ts +0 -695
  72. package/src/RedactoPrivacyCenter/api/client.ts +0 -1003
  73. package/src/RedactoPrivacyCenter/api/config.ts +0 -33
  74. package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -275
  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 -268
  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 -245
  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 -1206
  112. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -218
  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 -1821
  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 -95
  146. package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -195
  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 -155
  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 -252
  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 -57
  168. package/src/RedactoPrivacyCenter/lib/api.ts +0 -759
  169. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
  170. package/src/RedactoPrivacyCenter/lib/constants.ts +0 -283
  171. package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
  172. package/src/RedactoPrivacyCenter/lib/locales.ts +0 -102
  173. package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
  174. package/src/RedactoPrivacyCenter/lib/sandbox.ts +0 -104
  175. package/src/RedactoPrivacyCenter/lib/types.ts +0 -896
  176. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
  177. package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
  178. package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
  179. package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
  180. package/src/RedactoPrivacyCenter/lib/utils.ts +0 -798
  181. package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -342
  182. package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -342
  183. package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -342
  184. package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -342
  185. package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -357
  186. package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -342
  187. package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -342
  188. package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -345
  189. package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -342
  190. package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -342
  191. package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -342
  192. package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -342
  193. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -342
  194. package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -342
  195. package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -342
  196. package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -342
  197. package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -342
  198. package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -342
  199. package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -342
  200. package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -342
  201. package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -342
  202. package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -342
  203. package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -342
  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 -3108
  207. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -831
  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.test.tsx +0 -83
  219. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -93
  220. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
  221. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
  222. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
  223. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
  224. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
  225. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
  226. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
  227. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
  228. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
  229. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
  230. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
  231. package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
  232. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
  233. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
  234. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
  235. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
  236. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
  237. package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
  238. package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
  239. package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
  240. package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
  241. package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
  242. package/src/index.ts +0 -19
  243. package/src/privacy-center.ts +0 -113
  244. package/src/shared/api-errors.ts +0 -180
  245. package/src/shared/notice-consent-status.ts +0 -190
  246. package/src/shared/sandbox.ts +0 -6
  247. package/src/types/css.d.ts +0 -4
  248. package/src/types/images.d.ts +0 -19
  249. package/src/types/react-jsx.d.ts +0 -26
  250. package/tests/DataAvailabilityContext.test.tsx +0 -123
  251. package/tests/Form.test.tsx +0 -1424
  252. package/tests/ManageConsentErrorMapping.test.tsx +0 -85
  253. package/tests/ProductSelectionSection.test.tsx +0 -328
  254. package/tests/RequestSubmit.test.tsx +0 -135
  255. package/tests/RevocablePurpose.test.tsx +0 -146
  256. package/tests/RevokeWarningMessage.test.tsx +0 -151
  257. package/tests/consentClient.test.ts +0 -217
  258. package/tests/manageConsentServer.test.ts +0 -38
  259. package/tests/mocks.ts +0 -257
  260. package/tests/resolveContactFromJwt.test.ts +0 -44
  261. package/tests/setup.ts +0 -16
  262. package/tsconfig.json +0 -16
  263. package/tsup.config.ts +0 -31
  264. 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,283 +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: 'brx', label: 'बड़ो (Bodo)' },
44
- { value: 'ks', label: 'كٲشُر (Kashmiri)' },
45
- { value: 'sat', label: 'ᱥᱟᱱᱛᱟᱲᱤ (Santali)' },
46
- ];
47
-
48
- export const useTimePeriodOptions = () => {
49
- const { t } = useTranslation();
50
-
51
- return [
52
- { value: '1', label: t('today') },
53
- { value: '7', label: t('last7Days') },
54
- { value: '30', label: t('last30Days') },
55
- { value: '90', label: t('last3Months') },
56
- ];
57
- };
58
-
59
- export const useGrievanceTabs = () => {
60
- const { t } = useTranslation();
61
-
62
- return [
63
- { id: GRIEVANCE_TAB_IDS.ALL, label: t('allRequests') },
64
- { id: GRIEVANCE_TAB_IDS.PROCESSING, label: t('processing') },
65
- { id: GRIEVANCE_TAB_IDS.COMPLETED, label: t('completed') },
66
- { id: GRIEVANCE_TAB_IDS.REJECTED, label: t('rejected') },
67
- ];
68
- };
69
-
70
- export type PageChromeConfig = {
71
- titleKey: string;
72
- descriptionKey: string;
73
- };
74
-
75
- export const PAGE_CHROME_BY_PAGE: Record<InternalPage, PageChromeConfig> = {
76
- 'consent-manager': {
77
- titleKey: 'manageConsent',
78
- descriptionKey: 'manageConsentSubtitle',
79
- },
80
- form: {
81
- titleKey: 'grievanceRequests',
82
- descriptionKey: 'grievanceSubtitle',
83
- },
84
- activity: {
85
- titleKey: 'activities',
86
- descriptionKey: 'activitiesSubtitle',
87
- },
88
- 'case-details': {
89
- titleKey: 'caseDetails',
90
- descriptionKey: 'yourPrivacyCenter',
91
- },
92
- notifications: {
93
- titleKey: 'notificationHub',
94
- descriptionKey: 'notificationHubSubtitle',
95
- },
96
- receipts: {
97
- titleKey: 'myReceipt',
98
- descriptionKey: 'myReceiptSubtitle',
99
- },
100
- };
101
-
102
- const HREF_TO_NAME_KEY: Record<string, string> = {
103
- 'consent-manager': 'consentManager',
104
- form: 'grievance',
105
- activity: 'activity',
106
- receipts: 'myReceipt',
107
- };
108
-
109
- export const useMenuItemsPC = (): MenuItem[] => {
110
- const { t } = useTranslation();
111
- return menuItemsPC.map((item) => ({
112
- ...item,
113
- name: t((item.href && HREF_TO_NAME_KEY[item.href]) ?? item.name),
114
- }));
115
- };
116
-
117
- // ─── Upload validation ────────────────────────────────────────────────────────
118
-
119
- export const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10 MB
120
-
121
- export const ALLOWED_MIME_TYPES = [
122
- 'application/pdf',
123
- 'image/jpeg',
124
- 'image/png',
125
- 'image/webp',
126
- 'application/msword',
127
- 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
128
- 'application/vnd.ms-excel',
129
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
130
- 'text/plain',
131
- 'text/csv',
132
- ];
133
-
134
- // ─── Status colors ───────────────────────────────────────────────────────────
135
-
136
- export const STATUS_COLORS = {
137
- success: { color: '#16a34a', bg: '#f0fdf4', border: '#bbf7d0' },
138
- error: { color: '#dc2626', bg: '#fef2f2', border: '#fecaca' },
139
- warning: { color: '#d97706', bg: '#fffbeb', border: '#fde68a' },
140
- info: { color: '#2563eb', bg: '#f8fbff', border: '#93c5fd' },
141
- infoDark: '#1d4ed8',
142
- infoBanner: { color: '#1d4ed8', bg: '#eff6ff', border: '#bfdbfe' },
143
- } as const;
144
-
145
- // ─── Case statuses ────────────────────────────────────────────────────────────
146
-
147
- export const TERMINAL_CASE_STATUSES = ['completed', 'rejected', 'declined', 'expired'] as const;
148
-
149
- export const CASE_FINALIZED_TOOLTIP_KEY = 'caseFinalizedMessagesTooltip';
150
- export const CASE_FINALIZED_TOOLTIP_FALLBACK = 'This case is finalized — messages can no longer be sent.';
151
-
152
- export const useCaseFinalizedTooltip = () => {
153
- const { t } = useTranslation();
154
- return t(CASE_FINALIZED_TOOLTIP_KEY, CASE_FINALIZED_TOOLTIP_FALLBACK);
155
- };
156
-
157
- // ─── Document request ─────────────────────────────────────────────────────────
158
-
159
- export const UPLOAD_ACTIVE_STATUSES: DocumentRequestStatus[] = ['pending', 'replacement_requested'];
160
-
161
- export const DOCUMENT_REQUEST_STATUS_LABEL: Record<DocumentRequestStatus, DocumentRequestStatusInfo> = {
162
- pending: { labelKey: 'docStatusPending', color: STATUS_COLORS.warning.color },
163
- under_review: { labelKey: 'docStatusUnderReview', color: STATUS_COLORS.info.color },
164
- approved: { labelKey: 'docStatusApproved', color: STATUS_COLORS.success.color },
165
- rejected: { labelKey: 'docStatusRejected', color: STATUS_COLORS.error.color },
166
- replacement_requested: { labelKey: 'docStatusReplacementRequested', color: STATUS_COLORS.warning.color },
167
- };
168
-
169
- export const ACTIVITY_DATE_FORMATS = {
170
- DISPLAY: 'MMM D, YYYY [at] h:mm A',
171
- TOOLTIP: 'MMMM D, YYYY [at] h:mm:ss A',
172
- DATE: 'MMM D, YYYY',
173
- TIME: 'h:mm A',
174
- } as const;
175
-
176
- export const ACTIVITY_PAGE_SIZE = 10;
177
-
178
-
179
- // ─── Token refresh ─────────────────────────────────────────────────────────
180
-
181
- // Backoff window for *transient* OTP-refresh failures (network / 5xx). After a
182
- // transient failure we wait at least MIN before the next attempt and grow the
183
- // window exponentially up to MAX, so a flaky connection can't turn the
184
- // proactive-refresh path into a request storm (incident 2026-06-22). Terminal
185
- // failures (expired / already-used token) are handled by the circuit breaker in
186
- // lib/utils.ts and are not retried at all.
187
- export const MIN_REFRESH_BACKOFF_MS = 30_000; // 30s
188
- export const MAX_REFRESH_BACKOFF_MS = 300_000; // 5m
189
-
190
- // Where the privacy center persists the refresh token: localStorage (origin-
191
- // scoped, no path matching) under a Redacto-namespaced key, so it is readable
192
- // regardless of the host app's basePath and never collides with a host's own
193
- // `refresh_token` cookie. LEGACY_REFRESH_TOKEN_COOKIE is the cookie name older
194
- // SDK versions wrote (at path=/privacy-center); only that path is ever cleared.
195
- export const REFRESH_TOKEN_STORAGE_KEY = 'redacto_pc_refresh_token';
196
- export const LEGACY_REFRESH_TOKEN_COOKIE = 'refresh_token';
197
-
198
- // ─── DSAR request form ─────────────────────────────────────────────────────
199
-
200
- // Max product groups requested from user-consents when sourcing the DSAR
201
- // request-form product picker (Approach A). The Go ledger caps user-consents
202
- // page size at 100; the picker needs all of a principal's groups, so we
203
- // request the max. A principal with >100 product groups would need
204
- // group-level pagination (follow-up).
205
- export const FORM_PICKER_GROUP_LIMIT = 100;
206
-
207
- // Sentinel `product_uuid` of the synthetic product group the DSAR picker
208
- // builds from a backend's legacy flat `purposes` list (pre-grouping Python
209
- // deployments, and the popup / case-management contexts that cannot read
210
- // user-consents). It is a client-side construct with no server counterpart,
211
- // so a case raised from it must be submitted without a product anchor.
212
- export const LEGACY_PRODUCT_GROUP_UUID = '__legacy_flat_purposes__';
213
-
214
- // ─── Notification Hub ──────────────────────────────────────────────────────
215
-
216
- export const POLL_INTERVAL = 30_000;
217
- export const NOTIFICATION_PAGE_SIZE = 10;
218
- export const NOTIFICATION_DROPDOWN_LIMIT = 5;
219
-
220
- export const TAB_TO_CATEGORY: Record<FilterTab, NotificationCategory | undefined> = {
221
- all: undefined,
222
- consent: 'consent',
223
- request: 'request',
224
- system: 'system',
225
- };
226
-
227
- export const TYPE_TO_ICON_CATEGORY: Record<NotificationType, IconCategory> = {
228
- guardian_verification_request: 'guardian',
229
- consent_expiry_warning: 'consent',
230
- new_consent_notice: 'system',
231
- consent_withdrawal_confirmation: 'withdrawal',
232
- data_request_status_update: 'access',
233
- case_message: 'access',
234
- grievance_status_update: 'grievance',
235
- consent_regrant_prompt: 'consent',
236
- };
237
-
238
- export const ICON_MAP: Record<IconCategory, typeof IoPersonOutline> = {
239
- guardian: IoPersonOutline,
240
- consent: IoTimeOutline,
241
- access: IoDocumentOutline,
242
- withdrawal: IoShieldCheckmarkOutline,
243
- grievance: IoAlertCircleOutline,
244
- system: IoSettingsOutline,
245
- };
246
-
247
- export const ICON_COLORS: Record<IconCategory, string> = {
248
- guardian: '#7c3aed',
249
- consent: '#ea580c',
250
- access: '#16a34a',
251
- withdrawal: '#2563eb',
252
- grievance: '#dc2626',
253
- system: '#6b7280',
254
- };
255
-
256
- export const CTA_VARIANT_CLASS: Record<NotificationCTA['style'], string> = {
257
- primary: 'pc-notification-cta--primary',
258
- danger: 'pc-notification-cta--danger',
259
- secondary: 'pc-notification-cta--secondary',
260
- };
261
-
262
- export const useNotificationFilterTabs = () => {
263
- const { t } = useTranslation();
264
- return [
265
- { key: 'all' as FilterTab, label: t('all') },
266
- { key: 'consent' as FilterTab, label: t('consent') },
267
- { key: 'request' as FilterTab, label: t('requests') },
268
- { key: 'system' as FilterTab, label: t('system') },
269
- ];
270
- };
271
-
272
- export const useNotificationStatLabels = () => {
273
- const { t } = useTranslation();
274
- return {
275
- total: t('total'),
276
- unread: t('unread'),
277
- action_needed: t('actionNeeded'),
278
- acknowledged: t('acknowledged'),
279
- };
280
- };
281
-
282
-
283
- 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,102 +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 brxTranslation from '../locales/brx/translation.json';
6
- import doiTranslation from '../locales/doi/translation.json';
7
- import gomTranslation from '../locales/gom/translation.json';
8
- import guTranslation from '../locales/gu/translation.json';
9
- import hiTranslation from '../locales/hi/translation.json';
10
- import knTranslation from '../locales/kn/translation.json';
11
- import ksTranslation from '../locales/ks/translation.json';
12
- import maiTranslation from '../locales/mai/translation.json';
13
- import mlTranslation from '../locales/ml/translation.json';
14
- import mniMteiTranslation from '../locales/mni-Mtei/translation.json';
15
- import mrTranslation from '../locales/mr/translation.json';
16
- import neTranslation from '../locales/ne/translation.json';
17
- import orTranslation from '../locales/or/translation.json';
18
- import paTranslation from '../locales/pa/translation.json';
19
- import saTranslation from '../locales/sa/translation.json';
20
- import satTranslation from '../locales/sat/translation.json';
21
- import sdTranslation from '../locales/sd/translation.json';
22
- import taTranslation from '../locales/ta/translation.json';
23
- import teTranslation from '../locales/te/translation.json';
24
- import urTranslation from '../locales/ur/translation.json';
25
-
26
- const activityFetchErrorTranslations: Record<string, string> = {
27
- en: 'Failed to fetch activity data',
28
- as: 'কাৰ্যকলাপৰ তথ্য আনিবলৈ ব্যৰ্থ',
29
- bn: 'কার্যকলাপের ডেটা আনতে ব্যর্থ',
30
- brx: 'खामानि डाटा लाङो दिहुनायाव असफल',
31
- doi: 'गतिविधि डेटा लावै मे असफल',
32
- gom: 'क्रियाकलाप डेटा आणपांत अयशस्वी',
33
- gu: 'પ્રવૃત્તિ ડેટા મેળવવામાં નિષ્ફળ',
34
- hi: 'गतिविधि डेटा लाने में विफल',
35
- kn: 'ಚಟುವಟಿಕೆ ಡೇಟಾವನ್ನು ತರಲು ವಿಫಲ',
36
- ks: 'سرگرمی ڈیٹا حاصل کرنے میں ناکام',
37
- mai: 'गतिविधि डेटा लावै मे असफल',
38
- ml: 'പ്രവർത്തന ഡാറ്റ ലഭ്യമാക്കുന്നതിൽ പരാജയപ്പെട്ടു',
39
- 'mni-Mtei': 'ꯈꯨꯗꯝꯕꯤꯠ ꯗꯦꯇꯥ ꯐꯪꯉꯕꯗ ꯌꯥꯝꯅꯥ ꯋꯥꯏ꯫',
40
- mr: 'क्रियाकलाप डेटा आणण्यात अयशस्वी',
41
- ne: 'गतिविधि डेटा ल्याउन असफल',
42
- or: 'କାର୍ଯ୍ୟକଳାପ ତଥ୍ୟ ଆଣିବାରେ ବିଫଳ',
43
- pa: 'ਗਤੀਵਿਧੀ ਡਾਟਾ ਲਿਆਉਣ ਵਿੱਚ ਅਸਫਲ',
44
- sa: 'क्रियाकलाप-दत्तांशम् आने विफलम्',
45
- sat: 'ᱠᱟᱹᱢᱤ ᱰᱟᱴᱟ ᱟᱹᱜᱩ ᱨᱮ ᱵᱤᱯᱚᱠ',
46
- sd: 'سرگرمي جي ڊيٽا حاصل ڪرڻ ۾ ناڪام',
47
- ta: 'செயல்பாட்டு தரவை பெற முடியவில்லை',
48
- te: 'కార్యకలాప డేటాను తెచ్చుకోవడం విఫలమైంది',
49
- ur: 'سرگرمی کا ڈیٹا حاصل کرنے میں ناکام',
50
- };
51
-
52
- function withSharedActivityErrors(
53
- language: string,
54
- translation: Record<string, any>
55
- ) {
56
- return {
57
- ...translation,
58
- failedToFetchActivityData:
59
- activityFetchErrorTranslations[language] ??
60
- activityFetchErrorTranslations.en,
61
- };
62
- }
63
-
64
- // Map of language codes to translation objects
65
- const translations: Record<string, Record<string, any>> = {
66
- en: { translation: withSharedActivityErrors('en', enTranslation) },
67
- as: { translation: withSharedActivityErrors('as', asTranslation) },
68
- bn: { translation: withSharedActivityErrors('bn', bnTranslation) },
69
- brx: { translation: withSharedActivityErrors('brx', brxTranslation) },
70
- doi: { translation: withSharedActivityErrors('doi', doiTranslation) },
71
- gom: { translation: withSharedActivityErrors('gom', gomTranslation) },
72
- gu: { translation: withSharedActivityErrors('gu', guTranslation) },
73
- hi: { translation: withSharedActivityErrors('hi', hiTranslation) },
74
- kn: { translation: withSharedActivityErrors('kn', knTranslation) },
75
- ks: { translation: withSharedActivityErrors('ks', ksTranslation) },
76
- mai: { translation: withSharedActivityErrors('mai', maiTranslation) },
77
- ml: { translation: withSharedActivityErrors('ml', mlTranslation) },
78
- 'mni-Mtei': { translation: withSharedActivityErrors('mni-Mtei', mniMteiTranslation) },
79
- mr: { translation: withSharedActivityErrors('mr', mrTranslation) },
80
- ne: { translation: withSharedActivityErrors('ne', neTranslation) },
81
- or: { translation: withSharedActivityErrors('or', orTranslation) },
82
- pa: { translation: withSharedActivityErrors('pa', paTranslation) },
83
- sa: { translation: withSharedActivityErrors('sa', saTranslation) },
84
- sat: { translation: withSharedActivityErrors('sat', satTranslation) },
85
- sd: { translation: withSharedActivityErrors('sd', sdTranslation) },
86
- ta: { translation: withSharedActivityErrors('ta', taTranslation) },
87
- te: { translation: withSharedActivityErrors('te', teTranslation) },
88
- ur: { translation: withSharedActivityErrors('ur', urTranslation) },
89
- };
90
-
91
- export function getTranslation(language: string, namespace: string) {
92
- const langTranslations = translations[language];
93
- if (!langTranslations) {
94
- // Fallback to English if language not found
95
- const fallback = translations.en?.[namespace];
96
- return fallback || {};
97
- }
98
- const translation = langTranslations[namespace];
99
- return translation || {};
100
- }
101
-
102
- 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
- };