@redacto.io/consent-sdk-react 10.0.0-beta.11 → 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 (259) hide show
  1. package/NOTICE.md +17 -0
  2. package/README.md +67 -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 +613 -249
  11. package/dist/index.mjs +235 -85
  12. package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
  13. package/dist/types-6Aj7faxL.d.mts +57 -0
  14. package/dist/types-6Aj7faxL.d.ts +57 -0
  15. package/package.json +10 -1
  16. package/.turbo/turbo-build.log +0 -22
  17. package/.turbo/turbo-test.log +0 -203
  18. package/.turbo/turbo-verify-pack.log +0 -6
  19. package/CHANGELOG.md +0 -383
  20. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -934
  21. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2160
  22. package/src/RedactoNoticeAssisted/api/index.ts +0 -275
  23. package/src/RedactoNoticeAssisted/api/types.ts +0 -182
  24. package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
  25. package/src/RedactoNoticeAssisted/constants.ts +0 -51
  26. package/src/RedactoNoticeAssisted/i18n.ts +0 -1408
  27. package/src/RedactoNoticeAssisted/index.ts +0 -1
  28. package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
  29. package/src/RedactoNoticeAssisted/styles.ts +0 -730
  30. package/src/RedactoNoticeAssisted/types.ts +0 -26
  31. package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
  32. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1186
  33. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4299
  34. package/src/RedactoNoticeConsent/api/index.ts +0 -486
  35. package/src/RedactoNoticeConsent/api/sandbox.ts +0 -150
  36. package/src/RedactoNoticeConsent/api/types.ts +0 -505
  37. package/src/RedactoNoticeConsent/assets/redacto-logo.png +0 -0
  38. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +0 -602
  39. package/src/RedactoNoticeConsent/components/index.ts +0 -7
  40. package/src/RedactoNoticeConsent/constants.ts +0 -20
  41. package/src/RedactoNoticeConsent/index.ts +0 -1
  42. package/src/RedactoNoticeConsent/injectStyles.ts +0 -151
  43. package/src/RedactoNoticeConsent/language-codes.ts +0 -95
  44. package/src/RedactoNoticeConsent/services/storage.ts +0 -122
  45. package/src/RedactoNoticeConsent/styles.ts +0 -409
  46. package/src/RedactoNoticeConsent/types.ts +0 -80
  47. package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
  48. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
  49. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -709
  50. package/src/RedactoNoticeConsentInline/api/index.ts +0 -115
  51. package/src/RedactoNoticeConsentInline/api/notice-read-routing.test.ts +0 -72
  52. package/src/RedactoNoticeConsentInline/api/types.ts +0 -185
  53. package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
  54. package/src/RedactoNoticeConsentInline/index.ts +0 -1
  55. package/src/RedactoNoticeConsentInline/injectStyles.ts +0 -40
  56. package/src/RedactoNoticeConsentInline/styles.ts +0 -397
  57. package/src/RedactoNoticeConsentInline/types.ts +0 -51
  58. package/src/RedactoNoticeConsentInline/useMediaQuery.ts +0 -36
  59. package/src/RedactoPrivacyCenter/NotificationsPage.tsx +0 -182
  60. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +0 -19
  61. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +0 -156
  62. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +0 -17
  63. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +0 -79
  64. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +0 -36
  65. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +0 -177
  66. package/src/RedactoPrivacyCenter/PrivacyCenterMyReceiptPage.tsx +0 -26
  67. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +0 -93
  68. package/src/RedactoPrivacyCenter/api/actions.ts +0 -682
  69. package/src/RedactoPrivacyCenter/api/client.ts +0 -1003
  70. package/src/RedactoPrivacyCenter/api/config.ts +0 -33
  71. package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -275
  72. package/src/RedactoPrivacyCenter/api/orgBranding.ts +0 -16
  73. package/src/RedactoPrivacyCenter/api/upload.ts +0 -93
  74. package/src/RedactoPrivacyCenter/assets/character.svg +0 -31
  75. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +0 -9
  76. package/src/RedactoPrivacyCenter/assets/greenTick.svg +0 -4
  77. package/src/RedactoPrivacyCenter/assets/mail.svg +0 -3
  78. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +0 -9
  79. package/src/RedactoPrivacyCenter/assets/sentImg.svg +0 -9
  80. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +0 -9
  81. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +0 -252
  82. package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +0 -239
  83. package/src/RedactoPrivacyCenter/components/AppShell/AppShell.tsx +0 -268
  84. package/src/RedactoPrivacyCenter/components/AppShell/MobileNavDrawer.tsx +0 -218
  85. package/src/RedactoPrivacyCenter/components/AppShell/NavItem.tsx +0 -205
  86. package/src/RedactoPrivacyCenter/components/AppShell/PageHeader.tsx +0 -107
  87. package/src/RedactoPrivacyCenter/components/AppShell/SidebarNav.tsx +0 -100
  88. package/src/RedactoPrivacyCenter/components/AppShell/TopAppBar.tsx +0 -339
  89. package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +0 -245
  90. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useIsTruncated.ts +0 -28
  91. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useKeyboardShortcut.ts +0 -40
  92. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useSidebarState.ts +0 -62
  93. package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +0 -36
  94. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +0 -38
  95. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +0 -31
  96. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +0 -79
  97. package/src/RedactoPrivacyCenter/components/CaseDetails/FinalizedTooltipWrapper.tsx +0 -25
  98. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +0 -96
  99. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +0 -97
  100. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +0 -156
  101. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +0 -171
  102. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +0 -23
  103. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +0 -116
  104. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +0 -43
  105. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +0 -71
  106. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +0 -469
  107. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +0 -426
  108. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +0 -1199
  109. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -201
  110. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +0 -138
  111. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +0 -7
  112. package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +0 -179
  113. package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +0 -318
  114. package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +0 -333
  115. package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +0 -102
  116. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +0 -159
  117. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +0 -189
  118. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +0 -118
  119. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +0 -66
  120. package/src/RedactoPrivacyCenter/components/DataRequest/ProductSelectionSection.tsx +0 -222
  121. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +0 -331
  122. package/src/RedactoPrivacyCenter/components/Form.tsx +0 -1821
  123. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +0 -174
  124. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +0 -337
  125. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +0 -334
  126. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +0 -173
  127. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +0 -18
  128. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +0 -54
  129. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +0 -57
  130. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +0 -19
  131. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +0 -92
  132. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +0 -20
  133. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +0 -58
  134. package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +0 -10
  135. package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +0 -112
  136. package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +0 -27
  137. package/src/RedactoPrivacyCenter/components/Pagination.tsx +0 -140
  138. package/src/RedactoPrivacyCenter/components/PrivacyCenterEmptyState.tsx +0 -76
  139. package/src/RedactoPrivacyCenter/components/PrivacyCenterSessionExpired.tsx +0 -97
  140. package/src/RedactoPrivacyCenter/components/ReceiptsList.tsx +0 -454
  141. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +0 -270
  142. package/src/RedactoPrivacyCenter/components/SelectUser.tsx +0 -95
  143. package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -195
  144. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +0 -25
  145. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +0 -21
  146. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +0 -159
  147. package/src/RedactoPrivacyCenter/components/constant.ts +0 -52
  148. package/src/RedactoPrivacyCenter/components/groupHelpers.ts +0 -155
  149. package/src/RedactoPrivacyCenter/components/receiptColumns.tsx +0 -203
  150. package/src/RedactoPrivacyCenter/components/types.ts +0 -123
  151. package/src/RedactoPrivacyCenter/components/utils.tsx +0 -10
  152. package/src/RedactoPrivacyCenter/config/routes.ts +0 -9
  153. package/src/RedactoPrivacyCenter/config/table.ts +0 -25
  154. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +0 -252
  155. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +0 -47
  156. package/src/RedactoPrivacyCenter/context/BrandingContext.tsx +0 -52
  157. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +0 -92
  158. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +0 -181
  159. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +0 -11
  160. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +0 -96
  161. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +0 -30
  162. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +0 -80
  163. package/src/RedactoPrivacyCenter/context/ProfileSwitchContext.tsx +0 -15
  164. package/src/RedactoPrivacyCenter/context/types.ts +0 -57
  165. package/src/RedactoPrivacyCenter/lib/api.ts +0 -759
  166. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
  167. package/src/RedactoPrivacyCenter/lib/constants.ts +0 -283
  168. package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
  169. package/src/RedactoPrivacyCenter/lib/locales.ts +0 -102
  170. package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
  171. package/src/RedactoPrivacyCenter/lib/sandbox.ts +0 -104
  172. package/src/RedactoPrivacyCenter/lib/types.ts +0 -892
  173. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
  174. package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
  175. package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
  176. package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
  177. package/src/RedactoPrivacyCenter/lib/utils.ts +0 -798
  178. package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -340
  179. package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -340
  180. package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -340
  181. package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -340
  182. package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -355
  183. package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -340
  184. package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -340
  185. package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -343
  186. package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -340
  187. package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -340
  188. package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -340
  189. package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -340
  190. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -340
  191. package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -340
  192. package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -340
  193. package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -340
  194. package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -340
  195. package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -340
  196. package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -340
  197. package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -340
  198. package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -340
  199. package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -340
  200. package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -340
  201. package/src/RedactoPrivacyCenter/styles/applyBrandingTheme.ts +0 -66
  202. package/src/RedactoPrivacyCenter/styles/base.css +0 -117
  203. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +0 -3108
  204. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -831
  205. package/src/RedactoPrivacyCenter/styles/responsive.ts +0 -138
  206. package/src/RedactoPrivacyCenter/styles/variables.css +0 -96
  207. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +0 -387
  208. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +0 -468
  209. package/src/RedactoPrivacyCenter/table/index.ts +0 -2
  210. package/src/RedactoPrivacyCenter/types/images.d.ts +0 -29
  211. package/src/RedactoPrivacyCenter/ui/Footer.tsx +0 -69
  212. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +0 -54
  213. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +0 -93
  214. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +0 -47
  215. package/src/RedactoPrivacyCenter/ui/PCAvatar.test.tsx +0 -83
  216. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -93
  217. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
  218. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
  219. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
  220. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
  221. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
  222. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
  223. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
  224. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
  225. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
  226. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
  227. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
  228. package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
  229. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
  230. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
  231. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
  232. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
  233. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
  234. package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
  235. package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
  236. package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
  237. package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
  238. package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
  239. package/src/index.ts +0 -19
  240. package/src/privacy-center.ts +0 -113
  241. package/src/shared/api-errors.ts +0 -180
  242. package/src/shared/notice-consent-status.ts +0 -190
  243. package/src/shared/sandbox.ts +0 -6
  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 -1424
  249. package/tests/ProductSelectionSection.test.tsx +0 -328
  250. package/tests/RequestSubmit.test.tsx +0 -135
  251. package/tests/RevokeWarningMessage.test.tsx +0 -151
  252. package/tests/consentClient.test.ts +0 -217
  253. package/tests/manageConsentServer.test.ts +0 -38
  254. package/tests/mocks.ts +0 -257
  255. package/tests/resolveContactFromJwt.test.ts +0 -44
  256. package/tests/setup.ts +0 -16
  257. package/tsconfig.json +0 -16
  258. package/tsup.config.ts +0 -31
  259. package/vitest.config.ts +0 -16
@@ -1,1199 +0,0 @@
1
- import { useState, useEffect, useCallback, useMemo } from 'react';
2
- import { useTranslation } from 'react-i18next';
3
- import { PCInput, PCSelect, PCButton, PCText, PCModal, type SelectOption } from '../ui';
4
- import { Search, ArrowUpToLine, Filter, Circle } from 'lucide-react';
5
- import { pcStyles } from '../styles/pcStyles';
6
- import { AdvancedTable, AdvancedTablePagination } from '../table';
7
- import {
8
- getCoreRowModel,
9
- getExpandedRowModel,
10
- useReactTable,
11
- type ExpandedState,
12
- type PaginationState,
13
- type Row,
14
- type Updater,
15
- } from '@tanstack/react-table';
16
- import {
17
- fetchUserConsents,
18
- fetchGroupPurposes,
19
- manageConsent,
20
- } from '../lib/api';
21
- import { useOrganization } from '../context/OrganizationContext';
22
- import { useAuth } from '../context/AuthContext';
23
- import { useBaseUrl } from '../context/BaseUrlContext';
24
- import { usePageChrome } from '../context/PageChromeContext';
25
- import { ConsentStatusEnum } from '../lib/types';
26
- import type {
27
- ConsentAction,
28
- ConsentGroup,
29
- ConsentModalRecord,
30
- DisplayProductGroup,
31
- DisplayPurposeRow,
32
- PurposeItem,
33
- UserConsentDetail,
34
- } from '../lib/types';
35
- import { useCurrentLanguage } from '../lib/useCurrentLanguage';
36
- import { exportTableToCSV, useStatusOptions } from '../lib/consent-manager/utils';
37
- import { toast } from '../utils/toast';
38
- import { ConsentManagerTableSkeleton } from './ConsentManagerTableSkeleton';
39
- import { ModifyConsentModal } from './ModifyConsentModal';
40
- import { useConsentManagerGroupedColumns } from './ConsentManagerGroupedColumns';
41
- import { useConsentManagerColumns } from './ConsentManagerColumns';
42
- import { getStatusLabel, getGivenDateLabel, getValidTillLabel } from './ConsentManagerCells';
43
- import { ConsentManagerExpandedRow } from './ConsentManagerExpandedRow';
44
- import { ConsentManagerProductCards } from './ConsentManagerProductCards';
45
- import { ConsentManagerPurposeCards } from './ConsentManagerPurposeCards';
46
- import type {
47
- ConsentManagerProps,
48
- StatusFilterOption,
49
- ProductFilterOption,
50
- } from './types';
51
- import {
52
- SEARCH_DEBOUNCE_DELAY,
53
- DEFAULT_PAGE,
54
- DEFAULT_PAGE_SIZE,
55
- } from './ConsentManagerConstants';
56
-
57
- type ConsentViewMode = 'product' | 'purpose';
58
-
59
- export default function ConsentManager({ variant }: ConsentManagerProps) {
60
- const { t } = useTranslation();
61
- const statusOptions = useStatusOptions();
62
- const { organization } = useOrganization();
63
- const { accessToken, refreshToken, onError, updateTokens } = useAuth();
64
- const { consentClient } = useBaseUrl();
65
- const { setHeaderStatus } = usePageChrome();
66
- const organizationId = organization?.uuid;
67
- const workspaceId = organization?.workspaces[0]?.uuid;
68
- const contact = sessionStorage.getItem('email') || '';
69
-
70
- // Create auth context object for API calls - memoized to prevent infinite loops
71
- const authContext = useMemo(() => ({
72
- accessToken,
73
- refreshToken,
74
- onError,
75
- updateTokens,
76
- }), [accessToken, refreshToken, onError, updateTokens]);
77
-
78
- // Track language changes for localized API calls
79
- const { langParam } = useCurrentLanguage();
80
-
81
- // State management
82
- const [activeTab, setActiveTab] = useState<'direct' | 'nominated'>('direct');
83
- const [viewMode, setViewMode] = useState<ConsentViewMode>('product');
84
- const [consentDetail, setConsentDetail] = useState<UserConsentDetail | null>(null);
85
- const [consentGroups, setConsentGroups] = useState<DisplayProductGroup[]>([]);
86
- const [consentRows, setConsentRows] = useState<DisplayPurposeRow[]>([]);
87
- const [isLoading, setIsLoading] = useState(true);
88
- const [searchQuery, setSearchQuery] = useState('');
89
- const [debouncedSearch, setDebouncedSearch] = useState('');
90
- const [statusFilter, setStatusFilter] = useState<StatusFilterOption | null>(
91
- null
92
- );
93
- const [productFilter, setProductFilter] =
94
- useState<ProductFilterOption | null>(null);
95
- const [productOptions, setProductOptions] = useState<ProductFilterOption[]>(
96
- []
97
- );
98
- const [isModalOpen, setIsModalOpen] = useState(false);
99
- const [selectedRecord, setSelectedRecord] = useState<ConsentModalRecord | null>(
100
- null
101
- );
102
- const [exportModal, setExportModal] = useState(false);
103
- const [isManageLoading, setIsManageLoading] = useState(false);
104
- const [currentPage, setCurrentPage] = useState(DEFAULT_PAGE);
105
- const [pageSize, setPageSize] = useState(DEFAULT_PAGE_SIZE);
106
- const [expanded, setExpanded] = useState<ExpandedState>({});
107
- const [extraPurposesByKey, setExtraPurposesByKey] = useState<Record<string, PurposeItem[]>>({});
108
- const [hasMoreByKey, setHasMoreByKey] = useState<Record<string, boolean>>({});
109
- const [loadingMoreByKey, setLoadingMoreByKey] = useState<Record<string, boolean>>({});
110
- const composedSearchPlaceholder = useMemo(
111
- () => `${t('search')} ${t('consent')}, ${t('product')}, ${t('purpose')}...`,
112
- [t]
113
- );
114
- const allStatusOption = useMemo<StatusFilterOption>(
115
- () => ({
116
- label: `${t('all')} ${t('status')}`,
117
- value: '__all__',
118
- }),
119
- [t]
120
- );
121
- const allProductOption = useMemo<ProductFilterOption>(
122
- () => ({
123
- label: `${t('all')} ${t('product')}`,
124
- value: '__all__',
125
- }),
126
- [t]
127
- );
128
- const statusFilterOptions = useMemo<StatusFilterOption[]>(
129
- () => [allStatusOption, ...statusOptions],
130
- [allStatusOption, statusOptions]
131
- );
132
- const productFilterOptions = useMemo<ProductFilterOption[]>(
133
- () => [allProductOption, ...productOptions],
134
- [allProductOption, productOptions]
135
- );
136
- const statusSelectValue = statusFilter ?? allStatusOption;
137
- const productSelectValue = productFilter ?? allProductOption;
138
-
139
- // Sync selected status filter label when language changes
140
- useEffect(() => {
141
- if (statusFilter) {
142
- const updated = statusOptions.find(opt => opt.value === statusFilter.value);
143
- if (updated && updated.label !== statusFilter.label) {
144
- setStatusFilter(updated);
145
- }
146
- }
147
- }, [statusOptions, statusFilter]);
148
-
149
- // Sync selected product filter label when language changes
150
- useEffect(() => {
151
- if (productFilter) {
152
- const updated = productOptions.find(opt => opt.value === productFilter.value);
153
- if (updated && updated.label !== productFilter.label) {
154
- setProductFilter(updated);
155
- }
156
- }
157
- }, [productOptions, productFilter]);
158
-
159
- // Push user_status into the page header so it renders inline with the page title
160
- useEffect(() => {
161
- const status = consentDetail?.user_status;
162
- if (status === 'TRANSFERRED') {
163
- setHeaderStatus({ label: t('statusTransferred'), variant: 'warning' });
164
- } else if (status === 'ACTIVE') {
165
- setHeaderStatus({ label: t('statusActive'), variant: 'success' });
166
- } else {
167
- setHeaderStatus(null);
168
- }
169
- return () => setHeaderStatus(null);
170
- }, [consentDetail?.user_status, setHeaderStatus, t]);
171
-
172
- // Debounce search query
173
- useEffect(() => {
174
- const timer = setTimeout(() => {
175
- setDebouncedSearch(searchQuery);
176
- }, SEARCH_DEBOUNCE_DELAY);
177
- return () => clearTimeout(timer);
178
- }, [searchQuery]);
179
-
180
- const handleOpenModal = useCallback((record: ConsentModalRecord) => {
181
- setSelectedRecord(record);
182
- setIsModalOpen(true);
183
- }, []);
184
-
185
- const getCardKey = useCallback(
186
- (group: ConsentGroup): string =>
187
- group.nominator
188
- ? `nominated:${group.nominator.uuid}:${group.product_uuid}`
189
- : `direct:${group.product_uuid}`,
190
- []
191
- );
192
-
193
- const handleCloseModal = useCallback(() => {
194
- setIsModalOpen(false);
195
- setSelectedRecord(null);
196
- }, []);
197
-
198
- const matchesPurpose = useCallback(
199
- (
200
- purpose: PurposeItem,
201
- group: ConsentGroup,
202
- normalizedSearch: string,
203
- statusValue?: string
204
- ) => {
205
- const matchesSearch =
206
- !normalizedSearch ||
207
- [
208
- purpose.name,
209
- purpose.description,
210
- group.product_name,
211
- group.product_description,
212
- purpose.method,
213
- purpose.status,
214
- ]
215
- .filter(Boolean)
216
- .some((value) => String(value).toLowerCase().includes(normalizedSearch));
217
-
218
- const matchesStatus =
219
- !statusValue || purpose.status?.toLowerCase() === statusValue.toLowerCase();
220
-
221
- return matchesSearch && matchesStatus;
222
- },
223
- []
224
- );
225
-
226
- const buildDisplayGroups = useCallback(
227
- (
228
- groups: ConsentGroup[] | undefined,
229
- search: string,
230
- statusValue?: string,
231
- productUuid?: string
232
- ): DisplayProductGroup[] => {
233
- if (!groups || groups.length === 0) return [];
234
- const normalizedSearch = search.trim().toLowerCase();
235
-
236
- return groups.reduce<DisplayProductGroup[]>((acc, group) => {
237
- if (productUuid && group.product_uuid !== productUuid) {
238
- return acc;
239
- }
240
-
241
- const filteredPurposes = (group.purposes || []).filter((purpose) =>
242
- matchesPurpose(purpose, group, normalizedSearch, statusValue)
243
- );
244
-
245
- if (filteredPurposes.length === 0) {
246
- return acc;
247
- }
248
-
249
- const counts = filteredPurposes.reduce(
250
- (totals, purpose) => {
251
- const normalized = (typeof purpose.status === 'string' ? purpose.status : '').toUpperCase();
252
- switch (normalized) {
253
- case ConsentStatusEnum.ACTIVE:
254
- totals.active += 1;
255
- break;
256
- case ConsentStatusEnum.WITHDRAWN:
257
- case ConsentStatusEnum.REVOKED:
258
- totals.withdrawn += 1;
259
- break;
260
- case ConsentStatusEnum.EXPIRED:
261
- totals.expired += 1;
262
- break;
263
- case ConsentStatusEnum.DECLINED:
264
- totals.declined += 1;
265
- break;
266
- default:
267
- break;
268
- }
269
- return totals;
270
- },
271
- { active: 0, withdrawn: 0, expired: 0, declined: 0 }
272
- );
273
-
274
- const latestGivenDate = filteredPurposes.reduce<string | null>((latest, purpose) => {
275
- if (!purpose.given_date) return latest;
276
- if (!latest) return purpose.given_date;
277
- return new Date(purpose.given_date).getTime() > new Date(latest).getTime()
278
- ? purpose.given_date
279
- : latest;
280
- }, null);
281
-
282
- acc.push({
283
- ...group,
284
- purposes: filteredPurposes,
285
- active_purposes: counts.active,
286
- withdrawn_purposes: counts.withdrawn,
287
- expired_purposes: counts.expired,
288
- declined_purposes: counts.declined,
289
- latest_given_date: latestGivenDate,
290
- });
291
- return acc;
292
- }, []);
293
- },
294
- [matchesPurpose]
295
- );
296
-
297
- const flattenProductGroups = useCallback(
298
- (groups: ConsentGroup[] | undefined): DisplayPurposeRow[] => {
299
- if (!groups || groups.length === 0) return [];
300
- return groups.flatMap((group) =>
301
- (group.purposes || []).map((purpose) => ({
302
- ...purpose,
303
- product_uuid: group.product_uuid,
304
- product_name: group.product_name,
305
- product_description: group.product_description,
306
- nominator: group.nominator,
307
- }))
308
- );
309
- },
310
- []
311
- );
312
-
313
- const filterConsentRows = useCallback(
314
- (
315
- rows: DisplayPurposeRow[],
316
- search: string,
317
- statusValue?: string,
318
- productUuid?: string
319
- ): DisplayPurposeRow[] => {
320
- const normalizedSearch = search.trim().toLowerCase();
321
- return rows.filter((row) => {
322
- const matchesSearch =
323
- !normalizedSearch ||
324
- [
325
- row.name,
326
- row.description,
327
- row.product_name,
328
- row.product_description,
329
- row.method,
330
- row.status,
331
- ]
332
- .filter(Boolean)
333
- .some((value) =>
334
- String(value).toLowerCase().includes(normalizedSearch)
335
- );
336
-
337
- const matchesStatus =
338
- !statusValue || row.status?.toLowerCase() === statusValue.toLowerCase();
339
- const matchesProduct = !productUuid || row.product_uuid === productUuid;
340
-
341
- return matchesSearch && matchesStatus && matchesProduct;
342
- });
343
- },
344
- []
345
- );
346
-
347
- const buildProductOptionsFromGroups = useCallback(
348
- (groups: ConsentGroup[] | undefined) => {
349
- if (!groups || groups.length === 0) return [];
350
- const productMap = new Map<string, { label: string; value: string }>();
351
- groups.forEach((group) => {
352
- if (!productMap.has(group.product_uuid)) {
353
- productMap.set(group.product_uuid, {
354
- label: group.product_name,
355
- value: group.product_uuid,
356
- });
357
- }
358
- });
359
- return Array.from(productMap.values());
360
- },
361
- []
362
- );
363
-
364
- const groupedColumns = useConsentManagerGroupedColumns();
365
- const purposeColumns = useConsentManagerColumns({
366
- onOpenModal: handleOpenModal,
367
- });
368
-
369
- const groupedTableClassNames = useMemo(
370
- () => ({
371
- container: 'pc-consent-table-container',
372
- tableClassName: 'pc-consent-table',
373
- headerClassName: 'pc-consent-table-header',
374
- bodyClassName: 'pc-consent-table-body',
375
- rowClassName: 'pc-consent-table-row',
376
- cellClassName: 'pc-consent-table-cell',
377
- headerCellClassName: 'pc-consent-table-head-cell',
378
- expandedRowClassName: 'pc-consent-table-expanded-row',
379
- expandedCellClassName: 'pc-consent-table-expanded-cell',
380
- }),
381
- []
382
- );
383
-
384
- const purposeTableClassNames = useMemo(
385
- () => ({
386
- container: 'pc-consent-table-container',
387
- tableClassName: 'pc-consent-table pc-consent-table-purpose',
388
- headerClassName: 'pc-consent-table-header',
389
- bodyClassName: 'pc-consent-table-body',
390
- rowClassName: 'pc-consent-table-row',
391
- cellClassName: 'pc-consent-table-cell',
392
- headerCellClassName: 'pc-consent-table-head-cell',
393
- }),
394
- []
395
- );
396
-
397
- // Single data fetch function
398
- const fetchData = useCallback(async () => {
399
- if (!organizationId || !workspaceId) {
400
- return;
401
- }
402
-
403
- setIsLoading(true);
404
- try {
405
- const offset = (currentPage - 1) * pageSize;
406
- const searchParam = debouncedSearch.trim() || undefined;
407
- const statusParam = statusFilter?.value;
408
- const productUuidParam = productFilter?.value;
409
-
410
- const response = await fetchUserConsents({
411
- organizationId,
412
- workspaceId,
413
- offset: activeTab === 'direct' ? offset : undefined,
414
- limit: activeTab === 'direct' ? pageSize : undefined,
415
- nominatedOffset: activeTab === 'nominated' ? offset : undefined,
416
- nominatedLimit: activeTab === 'nominated' ? pageSize : undefined,
417
- search: searchParam,
418
- status: statusParam,
419
- product_uuid: productUuidParam,
420
- language: langParam,
421
- authContext,
422
- consentClient,
423
- });
424
-
425
- if (!response) {
426
- throw new Error('Failed to fetch consent data');
427
- }
428
-
429
- setConsentDetail(response);
430
- setExtraPurposesByKey({});
431
- setHasMoreByKey({});
432
- setLoadingMoreByKey({});
433
-
434
- const selectedGroups =
435
- activeTab === 'direct' ? response.direct : response.nominated;
436
- const displayGroups = buildDisplayGroups(
437
- selectedGroups,
438
- debouncedSearch,
439
- statusParam,
440
- productUuidParam
441
- );
442
- setConsentGroups(displayGroups);
443
- const flattenedRows = flattenProductGroups(selectedGroups);
444
- const filteredRows = filterConsentRows(
445
- flattenedRows,
446
- debouncedSearch,
447
- statusParam,
448
- productUuidParam
449
- );
450
- setConsentRows(filteredRows);
451
-
452
- // Only refresh the product filter options from an unfiltered fetch.
453
- // When a product filter is active the API returns rows for that one
454
- // product, so re-deriving options here would shrink the dropdown to
455
- // just the selected product (forcing the user to refresh to recover).
456
- if (!productFilter) {
457
- const combinedGroups = [
458
- ...(response.direct || []),
459
- ...(response.nominated || []),
460
- ];
461
- setProductOptions(buildProductOptionsFromGroups(combinedGroups));
462
- }
463
- } catch (error) {
464
- console.error(error);
465
- setConsentDetail(null);
466
- setConsentGroups([]);
467
- setConsentRows([]);
468
- setProductOptions([]);
469
- setExtraPurposesByKey({});
470
- setHasMoreByKey({});
471
- setLoadingMoreByKey({});
472
- toast.error(t('failedToFetchConsentData'));
473
- } finally {
474
- setIsLoading(false);
475
- }
476
- }, [
477
- organizationId,
478
- workspaceId,
479
- currentPage,
480
- pageSize,
481
- debouncedSearch,
482
- statusFilter?.value,
483
- productFilter?.value,
484
- activeTab,
485
- authContext,
486
- consentClient,
487
- langParam,
488
- buildDisplayGroups,
489
- flattenProductGroups,
490
- filterConsentRows,
491
- buildProductOptionsFromGroups,
492
- t,
493
- ]);
494
-
495
- // Single effect for data fetching
496
- useEffect(() => {
497
- fetchData();
498
- }, [fetchData]);
499
-
500
- const groupedPurposeCount = useMemo(
501
- () => consentGroups.reduce((sum, group) => sum + group.purposes.length, 0),
502
- [consentGroups]
503
- );
504
-
505
- const visibleConsentCount =
506
- viewMode === 'product' ? groupedPurposeCount : consentRows.length;
507
-
508
- const visibleProductCount = useMemo(() => {
509
- if (viewMode === 'product') {
510
- return consentGroups.length;
511
- }
512
- const productIds = new Set(
513
- consentRows.map((row) => row.product_uuid || row.product_name || '')
514
- );
515
- productIds.delete('');
516
- return productIds.size;
517
- }, [viewMode, consentGroups, consentRows]);
518
-
519
- const tableTotalCount = useMemo(() => {
520
- const pagination =
521
- activeTab === 'direct'
522
- ? consentDetail?.direct_pagination
523
- : consentDetail?.nominated_pagination;
524
- return pagination?.total_count ?? 0;
525
- }, [activeTab, consentDetail]);
526
-
527
- const tablePageCount = Math.ceil(tableTotalCount / pageSize) || 0;
528
-
529
- const handlePaginationChange = useCallback(
530
- (updater: Updater<PaginationState>) => {
531
- const next =
532
- typeof updater === 'function'
533
- ? updater({ pageIndex: currentPage - 1, pageSize })
534
- : updater;
535
- const nextPage = next.pageIndex + 1;
536
- const nextSize = next.pageSize;
537
- if (nextPage === currentPage && nextSize === pageSize) return;
538
- setCurrentPage(nextPage);
539
- setPageSize(nextSize);
540
- },
541
- [currentPage, pageSize]
542
- );
543
-
544
- const productTable = useReactTable<DisplayProductGroup>({
545
- data: consentGroups,
546
- columns: groupedColumns,
547
- getCoreRowModel: getCoreRowModel(),
548
- getExpandedRowModel: getExpandedRowModel(),
549
- getRowCanExpand: () => true,
550
- manualPagination: true,
551
- pageCount: tablePageCount,
552
- state: {
553
- pagination: {
554
- pageIndex: currentPage - 1,
555
- pageSize: pageSize,
556
- },
557
- expanded,
558
- },
559
- onExpandedChange: (updater) => {
560
- const next = typeof updater === 'function' ? updater(expanded) : updater;
561
- if (next === true) {
562
- setExpanded(next);
563
- return;
564
- }
565
- if (!next) {
566
- setExpanded({});
567
- return;
568
- }
569
-
570
- const nextMap = next as Record<string, boolean>;
571
- const nextOpenIds = Object.keys(nextMap).filter((rowId) => nextMap[rowId]);
572
- if (nextOpenIds.length <= 1) {
573
- setExpanded(nextOpenIds.length === 1 ? { [nextOpenIds[0]]: true } : {});
574
- return;
575
- }
576
-
577
- const prevMap =
578
- expanded && expanded !== true ? (expanded as Record<string, boolean>) : {};
579
- const newlyOpenedId =
580
- nextOpenIds.find((rowId) => !prevMap[rowId]) ??
581
- nextOpenIds[nextOpenIds.length - 1];
582
-
583
- setExpanded(newlyOpenedId ? { [newlyOpenedId]: true } : {});
584
- },
585
- onPaginationChange: (updater) => {
586
- handlePaginationChange(updater);
587
- setExpanded({});
588
- },
589
- meta: {
590
- onRowClick: (_row: DisplayProductGroup, tableRow?: Row<DisplayProductGroup>) => {
591
- tableRow?.toggleExpanded();
592
- },
593
- },
594
- });
595
-
596
- const purposeTable = useReactTable<DisplayPurposeRow>({
597
- data: consentRows,
598
- columns: purposeColumns,
599
- getCoreRowModel: getCoreRowModel(),
600
- manualPagination: true,
601
- pageCount: tablePageCount,
602
- state: {
603
- pagination: {
604
- pageIndex: currentPage - 1,
605
- pageSize: pageSize,
606
- },
607
- },
608
- onPaginationChange: handlePaginationChange,
609
- });
610
-
611
- const handleStatusFilterChange = (data: SelectOption | null) => {
612
- if (!data || String(data.value) === allStatusOption.value) {
613
- setStatusFilter(null);
614
- } else {
615
- setStatusFilter(data as StatusFilterOption);
616
- }
617
- setCurrentPage(DEFAULT_PAGE);
618
- setExpanded({});
619
- };
620
-
621
- const handleProductFilterChange = (data: SelectOption | null) => {
622
- if (!data || String(data.value) === allProductOption.value) {
623
- setProductFilter(null);
624
- } else {
625
- setProductFilter(data as ProductFilterOption);
626
- }
627
- setCurrentPage(DEFAULT_PAGE);
628
- setExpanded({});
629
- };
630
-
631
- const handleTabChange = (tab: 'direct' | 'nominated') => {
632
- setActiveTab(tab);
633
- setCurrentPage(DEFAULT_PAGE);
634
- setExpanded({});
635
- };
636
-
637
- const handleViewModeChange = (mode: ConsentViewMode) => {
638
- if (mode === viewMode) return;
639
- setViewMode(mode);
640
- setCurrentPage(DEFAULT_PAGE);
641
- setExpanded({});
642
- };
643
-
644
- const handleExport = useCallback(() => {
645
- // Build CSV rows whose cells exactly match the on-screen table: formatted
646
- // dates, translated status labels, and the "Until Withdrawal (no expiry)" /
647
- // "-" valid-till labels. Keys are the localized column headers.
648
- const toRow = (purpose: PurposeItem, productName: string | null) => ({
649
- [t('purpose')]: purpose.name,
650
- [t('descriptionLabel')]: purpose.description ?? '',
651
- [t('product')]: productName ?? '-',
652
- [t('status')]: getStatusLabel(String(purpose.status), t),
653
- [t('givenDate')]: getGivenDateLabel(purpose.given_date),
654
- [t('validTill')]: getValidTillLabel(purpose, t),
655
- [t('method')]: purpose.method ?? '',
656
- });
657
-
658
- const rows = viewMode === 'product'
659
- ? productTable.getRowModel().rows.flatMap((row) =>
660
- row.original.purposes.map((purpose) => toRow(purpose, row.original.product_name))
661
- )
662
- : purposeTable.getRowModel().rows.map((row) =>
663
- toRow(row.original, row.original.product_name)
664
- );
665
-
666
- exportTableToCSV(rows);
667
- setExportModal(false);
668
- }, [viewMode, productTable, purposeTable, t]);
669
-
670
- const handleLoadMorePurposes = useCallback(
671
- async (group: DisplayProductGroup) => {
672
- if (!organizationId || !workspaceId) return;
673
- const cardKey = getCardKey(group);
674
- if (loadingMoreByKey[cardKey]) return;
675
-
676
- const alreadyLoaded = extraPurposesByKey[cardKey]?.length ?? 0;
677
- const inlineCount = group.purposes.length;
678
- const offset = inlineCount + alreadyLoaded;
679
- const statusParam = statusFilter?.value;
680
- const searchParam = debouncedSearch.trim() || undefined;
681
-
682
- setLoadingMoreByKey((prev) => ({ ...prev, [cardKey]: true }));
683
- try {
684
- const result = await fetchGroupPurposes({
685
- organizationId,
686
- workspaceId,
687
- productUuid: group.product_uuid,
688
- offset,
689
- limit: 50,
690
- status: statusParam,
691
- search: searchParam,
692
- language: langParam,
693
- nominatorUuid: group.nominator?.uuid,
694
- authContext,
695
- consentClient,
696
- });
697
- if (!result) {
698
- throw new Error('Failed to load more purposes');
699
- }
700
- setExtraPurposesByKey((prev) => ({
701
- ...prev,
702
- [cardKey]: [...(prev[cardKey] ?? []), ...result.purposes],
703
- }));
704
- const fetchedTotal = offset + result.purposes.length;
705
- const hasMore = fetchedTotal < result.pagination.total_count;
706
- setHasMoreByKey((prev) => ({ ...prev, [cardKey]: hasMore }));
707
- } catch (error) {
708
- console.error('Failed to load more purposes:', error);
709
- toast.error(t('failedToFetchConsentData'));
710
- } finally {
711
- setLoadingMoreByKey((prev) => ({ ...prev, [cardKey]: false }));
712
- }
713
- },
714
- [
715
- organizationId,
716
- workspaceId,
717
- authContext,
718
- consentClient,
719
- langParam,
720
- statusFilter?.value,
721
- debouncedSearch,
722
- extraPurposesByKey,
723
- loadingMoreByKey,
724
- getCardKey,
725
- t,
726
- ]
727
- );
728
-
729
- const handleManageConsent = useCallback(
730
- async (
731
- purposeId: string,
732
- action: ConsentAction,
733
- nominatorContact?: string,
734
- dataElementUuids?: string[],
735
- productUuid?: string
736
- ) => {
737
- if (!organizationId || !workspaceId || !contact) {
738
- toast.error(t('missingInfoToManage'));
739
- return;
740
- }
741
-
742
- setIsManageLoading(true);
743
-
744
- const successMessages: Record<ConsentAction, string> = {
745
- revoke: t('consentRevokedSuccess'),
746
- regrant: t('consentRegrantedSuccess'),
747
- renew: t('consentRenewedSuccess'),
748
- };
749
-
750
- const errorMessages: Record<ConsentAction, string> = {
751
- revoke: t('unableToRevokeConsent'),
752
- regrant: t('unableToRegrantConsent'),
753
- renew: t('unableToRenewConsent'),
754
- };
755
-
756
- try {
757
- // The ledger's submit-consent needs the notice the purpose was consented
758
- // under, plus the purpose's data elements with their current selected
759
- // state — both live on the loaded consent record (selectedRecord).
760
- const noticeUuid = selectedRecord?.notice_uuid ?? undefined;
761
- const dataElements = (selectedRecord?.data_elements ?? []).map((el) => ({
762
- uuid: el.uuid,
763
- selected: el.selected,
764
- }));
765
-
766
- const response = await manageConsent({
767
- organizationId,
768
- workspaceId,
769
- purposeId,
770
- contact,
771
- action,
772
- authContext,
773
- consentClient,
774
- nominatorContact,
775
- dataElementUuids,
776
- productUuid,
777
- noticeUuid,
778
- dataElements,
779
- language: langParam,
780
- });
781
-
782
- if (response) {
783
- toast.success(successMessages[action]);
784
- await fetchData();
785
- } else {
786
- toast.error(errorMessages[action]);
787
- }
788
- } catch (error: any) {
789
- console.error(`Error ${action} consent:`, error);
790
- if (error?.code === 'NOMINATOR_NOT_FOUND') {
791
- toast.error(t('nominatorNotFound'));
792
- } else if (error?.code === 'NOMINEE_MUST_SPECIFY_NOMINATOR') {
793
- toast.error(t('nomineeMustSpecifyNominator'));
794
- } else {
795
- toast.error(errorMessages[action]);
796
- }
797
- } finally {
798
- setIsManageLoading(false);
799
- handleCloseModal();
800
- }
801
- },
802
- [organizationId, workspaceId, contact, fetchData, handleCloseModal, t, authContext, consentClient, selectedRecord, langParam]
803
- );
804
-
805
- const getVar = (varName: string): string => `var(${varName})`;
806
-
807
- const directBadge: number | '' =
808
- consentDetail?.status_summary?.direct_purposes ?? '';
809
-
810
- const nominatedBadge: number | '' =
811
- consentDetail?.status_summary?.nominated_purposes ?? '';
812
-
813
- const nominatorLabels = (consentDetail?.nominators || [])
814
- .map((n) => n.email?.trim() || n.org_user_id?.trim() || n.uuid?.trim() || '')
815
- .filter(Boolean);
816
- const summaryText = t('productsAndConsentsSummary', {
817
- products: visibleProductCount,
818
- consents: visibleConsentCount,
819
- });
820
-
821
- return (
822
- <div className="pc-consent-manager-surface" style={{ width: '100%' }}>
823
- <div
824
- className="pc-consent-shell-card"
825
- style={{
826
- backgroundColor: 'transparent',
827
- }}
828
- >
829
- {/* Tabs: My Consents / Managing + Product/Purpose toggle */}
830
- <div
831
- className="pc-consent-tabs-row"
832
- style={{
833
- display: 'flex',
834
- alignItems: 'center',
835
- justifyContent: 'space-between',
836
- gap: getVar('--pc-spacing-sm'),
837
- borderBottom: `1px solid ${getVar('--pc-border-color')}`,
838
- padding: '0.125rem 0 0.375rem',
839
- }}
840
- >
841
- <div className="pc-consent-tabs-left" style={{ display: 'flex', minWidth: 0 }}>
842
- <button
843
- type="button"
844
- onClick={() => handleTabChange('direct')}
845
- style={{
846
- display: 'flex',
847
- alignItems: 'center',
848
- gap: getVar('--pc-spacing-sm'),
849
- padding: `0.5rem ${getVar('--pc-spacing-sm')}`,
850
- fontSize: '0.75rem',
851
- fontWeight: 600,
852
- background: 'none',
853
- border: 'none',
854
- cursor: 'pointer',
855
- borderBottom: activeTab === 'direct' ? `2px solid ${getVar('--pc-primary')}` : '2px solid transparent',
856
- color: activeTab === 'direct' ? getVar('--pc-primary') : getVar('--pc-text-secondary'),
857
- transition: 'color 0.2s, border-color 0.2s',
858
- }}
859
- >
860
- {t('myConsents')}
861
- <span style={{
862
- borderRadius: '9999px',
863
- backgroundColor: getVar('--pc-bg-tertiary'),
864
- padding: '0.0625rem 0.375rem',
865
- fontSize: '0.6875rem',
866
- color: getVar('--pc-text-secondary'),
867
- }}>
868
- {directBadge}
869
- </span>
870
- </button>
871
- <button
872
- type="button"
873
- onClick={() => handleTabChange('nominated')}
874
- style={{
875
- display: 'flex',
876
- alignItems: 'center',
877
- gap: getVar('--pc-spacing-sm'),
878
- padding: `0.5rem ${getVar('--pc-spacing-sm')}`,
879
- fontSize: '0.75rem',
880
- fontWeight: 600,
881
- background: 'none',
882
- border: 'none',
883
- cursor: 'pointer',
884
- borderBottom: activeTab === 'nominated' ? `2px solid ${getVar('--pc-primary')}` : '2px solid transparent',
885
- color: activeTab === 'nominated' ? getVar('--pc-primary') : getVar('--pc-text-secondary'),
886
- transition: 'color 0.2s, border-color 0.2s',
887
- }}
888
- >
889
- {t('managing')}
890
- <span style={{
891
- borderRadius: '9999px',
892
- backgroundColor: getVar('--pc-bg-tertiary'),
893
- padding: '0.0625rem 0.375rem',
894
- fontSize: '0.6875rem',
895
- color: getVar('--pc-text-secondary'),
896
- }}>
897
- {nominatedBadge}
898
- </span>
899
- </button>
900
- </div>
901
-
902
- <div
903
- className="pc-consent-view-toggle"
904
- style={{
905
- marginLeft: 'auto',
906
- display: 'flex',
907
- alignItems: 'center',
908
- gap: getVar('--pc-spacing-sm'),
909
- paddingRight: getVar('--pc-spacing-sm'),
910
- }}
911
- >
912
- <PCText
913
- size="sm"
914
- color="secondary"
915
- className="pc-consent-view-toggle-label"
916
- style={{ margin: 0, fontSize: '0.75rem', fontWeight: 500 }}
917
- >
918
- {t('consentVisibility')}
919
- </PCText>
920
- <div
921
- className="pc-consent-view-toggle-group"
922
- style={{
923
- display: 'inline-flex',
924
- borderRadius: '9999px',
925
- backgroundColor: getVar('--pc-bg-secondary'),
926
- padding: '0.125rem',
927
- }}
928
- >
929
- <button
930
- type="button"
931
- className={`pc-consent-view-toggle-btn ${viewMode === 'product' ? 'is-active' : ''}`}
932
- onClick={() => handleViewModeChange('product')}
933
- style={{
934
- minWidth: '5.25rem',
935
- minHeight: '1.75rem',
936
- padding: '0.3125rem 0.75rem',
937
- border: 'none',
938
- backgroundColor:
939
- viewMode === 'product' ? getVar('--pc-primary') : 'transparent',
940
- color:
941
- viewMode === 'product'
942
- ? getVar('--pc-text-inverse')
943
- : getVar('--pc-text-secondary'),
944
- fontSize: '0.6875rem',
945
- fontWeight: 600,
946
- cursor: 'pointer',
947
- borderRadius: '9999px',
948
- transition: 'background-color 0.2s ease, color 0.2s ease',
949
- }}
950
- >
951
- {t('product')}
952
- </button>
953
- <button
954
- type="button"
955
- className={`pc-consent-view-toggle-btn ${viewMode === 'purpose' ? 'is-active' : ''}`}
956
- onClick={() => handleViewModeChange('purpose')}
957
- style={{
958
- minWidth: '5.25rem',
959
- minHeight: '1.75rem',
960
- padding: '0.3125rem 0.75rem',
961
- border: 'none',
962
- backgroundColor:
963
- viewMode === 'purpose' ? getVar('--pc-primary') : 'transparent',
964
- color:
965
- viewMode === 'purpose'
966
- ? getVar('--pc-text-inverse')
967
- : getVar('--pc-text-secondary'),
968
- fontSize: '0.6875rem',
969
- fontWeight: 600,
970
- cursor: 'pointer',
971
- borderRadius: '9999px',
972
- transition: 'background-color 0.2s ease, color 0.2s ease',
973
- }}
974
- >
975
- {t('purpose')}
976
- </button>
977
- </div>
978
- </div>
979
- </div>
980
-
981
- {activeTab === 'nominated' && nominatorLabels.length > 0 && (
982
- <PCText
983
- size="sm"
984
- color="secondary"
985
- style={{
986
- margin: 0,
987
- marginBottom: getVar('--pc-spacing-sm'),
988
- paddingLeft: getVar('--pc-spacing-lg'),
989
- paddingRight: getVar('--pc-spacing-lg'),
990
- }}
991
- >
992
- {t('managingConsentsFor')}{' '}
993
- <span style={{ fontWeight: 600, color: getVar('--pc-text-primary') }}>
994
- {nominatorLabels.join(', ')}
995
- </span>
996
- </PCText>
997
- )}
998
-
999
- {/* Filters Section: Search on left, filters and export on the right */}
1000
- <div style={{
1001
- display: 'flex',
1002
- flexDirection: 'column',
1003
- gap: getVar('--pc-spacing-sm'),
1004
- width: '100%',
1005
- padding: '0.75rem 0 0.625rem',
1006
- }} className="pc-filters-responsive">
1007
- <div style={{ width: '100%' }} className="pc-search-responsive">
1008
- <PCInput
1009
- type="search"
1010
- size="sm"
1011
- clearable
1012
- clearAriaLabel={t('clearInput')}
1013
- placeholder={composedSearchPlaceholder}
1014
- value={searchQuery}
1015
- onClear={() => {
1016
- setSearchQuery('');
1017
- setCurrentPage(DEFAULT_PAGE);
1018
- }}
1019
- prefix={<Search size={14} strokeWidth={1.8} />}
1020
- onChange={(e) => {
1021
- setSearchQuery(e.target.value);
1022
- setCurrentPage(DEFAULT_PAGE);
1023
- }}
1024
- style={{
1025
- width: '100%',
1026
- }}
1027
- />
1028
- </div>
1029
-
1030
- <div style={{
1031
- display: 'flex',
1032
- flexDirection: 'column',
1033
- gap: getVar('--pc-spacing-sm'),
1034
- width: '100%',
1035
- }} className="pc-filters-row-responsive">
1036
- <PCSelect
1037
- className="pc-filter-select"
1038
- size="sm"
1039
- placeholder={t('status')}
1040
- prefix={<Filter size={12} strokeWidth={1.8} />}
1041
- options={statusFilterOptions}
1042
- value={statusSelectValue}
1043
- onChange={handleStatusFilterChange}
1044
- showSelectedCheck
1045
- style={{
1046
- width: '100%',
1047
- }}
1048
- />
1049
- <PCSelect
1050
- className="pc-filter-select"
1051
- size="sm"
1052
- placeholder={t('product')}
1053
- prefix={<Circle size={10} strokeWidth={2} />}
1054
- options={productFilterOptions}
1055
- value={productSelectValue}
1056
- onChange={handleProductFilterChange}
1057
- showSelectedCheck
1058
- style={{
1059
- width: '100%',
1060
- }}
1061
- />
1062
- <PCText
1063
- size="sm"
1064
- color="secondary"
1065
- className="pc-filters-summary"
1066
- style={{
1067
- margin: 0,
1068
- whiteSpace: 'nowrap',
1069
- alignSelf: 'center',
1070
- }}
1071
- >
1072
- {summaryText}
1073
- </PCText>
1074
- <div className="pc-export-button-responsive">
1075
- <PCButton
1076
- size="sm"
1077
- variant="outline"
1078
- onClick={() => setExportModal(true)}
1079
- style={{
1080
- whiteSpace: 'nowrap',
1081
- width: '100%',
1082
- }}
1083
- >
1084
- <ArrowUpToLine size={13} />
1085
- <span>{t('export')}</span>
1086
- </PCButton>
1087
- </div>
1088
- </div>
1089
- </div>
1090
- {isLoading ? (
1091
- <ConsentManagerTableSkeleton />
1092
- ) : (
1093
- <>
1094
- <div className="pc-consent-desktop-view">
1095
- {viewMode === 'product' ? (
1096
- <AdvancedTable
1097
- table={productTable}
1098
- variant={variant}
1099
- classNames={groupedTableClassNames}
1100
- isLoading={isLoading}
1101
- expandedComponent={(row) => {
1102
- const cardKey = getCardKey(row.original);
1103
- return (
1104
- <ConsentManagerExpandedRow
1105
- group={row.original}
1106
- onModify={handleOpenModal}
1107
- extraPurposes={extraPurposesByKey[cardKey]}
1108
- hasMore={hasMoreByKey[cardKey] ?? row.original.has_more_purposes}
1109
- isLoadingMore={loadingMoreByKey[cardKey]}
1110
- onLoadMore={handleLoadMorePurposes}
1111
- />
1112
- );
1113
- }}
1114
- />
1115
- ) : (
1116
- <AdvancedTable
1117
- table={purposeTable}
1118
- variant={variant}
1119
- classNames={purposeTableClassNames}
1120
- isLoading={isLoading}
1121
- />
1122
- )}
1123
- </div>
1124
-
1125
- <div className="pc-consent-mobile-view">
1126
- {viewMode === 'product' ? (
1127
- <ConsentManagerProductCards
1128
- groups={consentGroups}
1129
- onModify={handleOpenModal}
1130
- extraPurposesByKey={extraPurposesByKey}
1131
- hasMoreByKey={hasMoreByKey}
1132
- loadingMoreByKey={loadingMoreByKey}
1133
- onLoadMore={handleLoadMorePurposes}
1134
- cardKeyFor={getCardKey}
1135
- />
1136
- ) : (
1137
- <ConsentManagerPurposeCards
1138
- rows={consentRows}
1139
- onModify={handleOpenModal}
1140
- />
1141
- )}
1142
- </div>
1143
- </>
1144
- )}
1145
-
1146
- {viewMode === 'product' && (
1147
- <div className="pc-consent-pagination-wrap">
1148
- <AdvancedTablePagination table={productTable} />
1149
- </div>
1150
- )}
1151
- </div>
1152
-
1153
- <PCModal
1154
- isOpen={exportModal}
1155
- onClose={() => setExportModal(false)}
1156
- size="sm"
1157
- closeAriaLabel={t('closeModal')}
1158
- title={
1159
- <div style={{ minWidth: 0, flex: 1, paddingRight: getVar('--pc-spacing-sm') }}>
1160
- <PCText size="base" weight="semibold" style={{ margin: 0, color: getVar('--pc-text-primary') }}>
1161
- {t('exportConsentData')}
1162
- </PCText>
1163
- <PCText
1164
- size="xs"
1165
- color="secondary"
1166
- style={{ marginTop: pcStyles.mtXs.marginTop, marginBottom: 0, lineHeight: 1.5 }}
1167
- >
1168
- {t('exportConsentDataSubtitle')}
1169
- </PCText>
1170
- </div>
1171
- }
1172
- footer={
1173
- <div className="pc-modal-footer-actions">
1174
- <PCButton variant="secondary" onClick={() => setExportModal(false)}>
1175
- {t('cancel')}
1176
- </PCButton>
1177
- <PCButton variant="primary" onClick={handleExport}>
1178
- {t('export')}
1179
- </PCButton>
1180
- </div>
1181
- }
1182
- >
1183
- <div style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: pcStyles.gapSm.gap }}>
1184
- <PCText size="sm" color="secondary" style={{ margin: 0, lineHeight: 1.6 }}>
1185
- {t('exportingIncludesFilters')}
1186
- </PCText>
1187
- </div>
1188
- </PCModal>
1189
-
1190
- <ModifyConsentModal
1191
- isOpen={isModalOpen}
1192
- onClose={handleCloseModal}
1193
- selectedRecord={selectedRecord}
1194
- isLoading={isManageLoading}
1195
- onManageConsent={handleManageConsent}
1196
- />
1197
- </div>
1198
- );
1199
- }