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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (258) hide show
  1. package/NOTICE.md +17 -0
  2. package/README.md +145 -3
  3. package/dist/chunk-FEGTW73Q.mjs +182 -0
  4. package/dist/{chunk-6A665OPR.mjs → chunk-OGL6OC3A.mjs} +4 -0
  5. package/dist/fonts.d.mts +35 -0
  6. package/dist/fonts.d.ts +35 -0
  7. package/dist/fonts.js +183 -0
  8. package/dist/fonts.mjs +10 -0
  9. package/dist/index.d.mts +44 -5
  10. package/dist/index.d.ts +44 -5
  11. package/dist/index.js +950 -476
  12. package/dist/index.mjs +572 -314
  13. package/dist/montserrat.generated-NBTECYRW.mjs +22 -0
  14. package/dist/privacy-center.d.mts +55 -12
  15. package/dist/privacy-center.d.ts +55 -12
  16. package/dist/privacy-center.js +848 -950
  17. package/dist/privacy-center.mjs +698 -802
  18. package/dist/types-6Aj7faxL.d.mts +57 -0
  19. package/dist/types-6Aj7faxL.d.ts +57 -0
  20. package/package.json +10 -1
  21. package/.turbo/turbo-build.log +0 -22
  22. package/.turbo/turbo-test.log +0 -203
  23. package/.turbo/turbo-verify-pack.log +0 -6
  24. package/CHANGELOG.md +0 -274
  25. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.test.tsx +0 -847
  26. package/src/RedactoNoticeAssisted/RedactoNoticeAssisted.tsx +0 -2133
  27. package/src/RedactoNoticeAssisted/api/index.ts +0 -269
  28. package/src/RedactoNoticeAssisted/api/types.ts +0 -180
  29. package/src/RedactoNoticeAssisted/assets/redacto-logo.png +0 -0
  30. package/src/RedactoNoticeAssisted/constants.ts +0 -51
  31. package/src/RedactoNoticeAssisted/i18n.ts +0 -1463
  32. package/src/RedactoNoticeAssisted/index.ts +0 -1
  33. package/src/RedactoNoticeAssisted/injectStyles.ts +0 -251
  34. package/src/RedactoNoticeAssisted/styles.ts +0 -730
  35. package/src/RedactoNoticeAssisted/types.ts +0 -24
  36. package/src/RedactoNoticeAssisted/useMediaQuery.ts +0 -36
  37. package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +0 -1152
  38. package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +0 -4258
  39. package/src/RedactoNoticeConsent/api/index.ts +0 -573
  40. package/src/RedactoNoticeConsent/api/types.ts +0 -490
  41. package/src/RedactoNoticeConsent/assets/redacto-logo.png +0 -0
  42. package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +0 -602
  43. package/src/RedactoNoticeConsent/components/index.ts +0 -7
  44. package/src/RedactoNoticeConsent/constants.ts +0 -20
  45. package/src/RedactoNoticeConsent/index.ts +0 -1
  46. package/src/RedactoNoticeConsent/injectStyles.ts +0 -151
  47. package/src/RedactoNoticeConsent/language-codes.ts +0 -97
  48. package/src/RedactoNoticeConsent/services/storage.ts +0 -122
  49. package/src/RedactoNoticeConsent/styles.ts +0 -409
  50. package/src/RedactoNoticeConsent/types.ts +0 -54
  51. package/src/RedactoNoticeConsent/useMediaQuery.ts +0 -36
  52. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.test.tsx +0 -369
  53. package/src/RedactoNoticeConsentInline/RedactoNoticeConsentInline.tsx +0 -629
  54. package/src/RedactoNoticeConsentInline/api/index.ts +0 -106
  55. package/src/RedactoNoticeConsentInline/api/types.ts +0 -183
  56. package/src/RedactoNoticeConsentInline/assets/redacto-logo.png +0 -0
  57. package/src/RedactoNoticeConsentInline/index.ts +0 -1
  58. package/src/RedactoNoticeConsentInline/injectStyles.ts +0 -40
  59. package/src/RedactoNoticeConsentInline/styles.ts +0 -397
  60. package/src/RedactoNoticeConsentInline/types.ts +0 -51
  61. package/src/RedactoNoticeConsentInline/useMediaQuery.ts +0 -36
  62. package/src/RedactoPrivacyCenter/NotificationsPage.tsx +0 -182
  63. package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +0 -19
  64. package/src/RedactoPrivacyCenter/PrivacyCenterCaseDetailsPage.tsx +0 -156
  65. package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +0 -17
  66. package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +0 -79
  67. package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +0 -36
  68. package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +0 -177
  69. package/src/RedactoPrivacyCenter/PrivacyCenterMyReceiptPage.tsx +0 -26
  70. package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +0 -58
  71. package/src/RedactoPrivacyCenter/api/actions.ts +0 -680
  72. package/src/RedactoPrivacyCenter/api/client.ts +0 -906
  73. package/src/RedactoPrivacyCenter/api/config.ts +0 -33
  74. package/src/RedactoPrivacyCenter/api/fetcher.ts +0 -260
  75. package/src/RedactoPrivacyCenter/api/orgBranding.ts +0 -16
  76. package/src/RedactoPrivacyCenter/api/upload.ts +0 -93
  77. package/src/RedactoPrivacyCenter/assets/character.svg +0 -31
  78. package/src/RedactoPrivacyCenter/assets/fileAttach.svg +0 -9
  79. package/src/RedactoPrivacyCenter/assets/greenTick.svg +0 -4
  80. package/src/RedactoPrivacyCenter/assets/mail.svg +0 -3
  81. package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +0 -9
  82. package/src/RedactoPrivacyCenter/assets/sentImg.svg +0 -9
  83. package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +0 -9
  84. package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +0 -252
  85. package/src/RedactoPrivacyCenter/components/ActivityTimeline.tsx +0 -239
  86. package/src/RedactoPrivacyCenter/components/AppShell/AppShell.tsx +0 -240
  87. package/src/RedactoPrivacyCenter/components/AppShell/MobileNavDrawer.tsx +0 -218
  88. package/src/RedactoPrivacyCenter/components/AppShell/NavItem.tsx +0 -205
  89. package/src/RedactoPrivacyCenter/components/AppShell/PageHeader.tsx +0 -107
  90. package/src/RedactoPrivacyCenter/components/AppShell/SidebarNav.tsx +0 -100
  91. package/src/RedactoPrivacyCenter/components/AppShell/TopAppBar.tsx +0 -339
  92. package/src/RedactoPrivacyCenter/components/AppShell/UserMenu.tsx +0 -243
  93. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useIsTruncated.ts +0 -28
  94. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useKeyboardShortcut.ts +0 -40
  95. package/src/RedactoPrivacyCenter/components/AppShell/hooks/useSidebarState.ts +0 -62
  96. package/src/RedactoPrivacyCenter/components/AppShell/usePrivacyCenterExitAction.ts +0 -36
  97. package/src/RedactoPrivacyCenter/components/CaseDetails/AttachmentCard.tsx +0 -38
  98. package/src/RedactoPrivacyCenter/components/CaseDetails/ChatBubble.tsx +0 -31
  99. package/src/RedactoPrivacyCenter/components/CaseDetails/DocumentRequestCard.tsx +0 -79
  100. package/src/RedactoPrivacyCenter/components/CaseDetails/FinalizedTooltipWrapper.tsx +0 -25
  101. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageComposer.tsx +0 -96
  102. package/src/RedactoPrivacyCenter/components/CaseDetails/MessageItem.tsx +0 -97
  103. package/src/RedactoPrivacyCenter/components/CaseDetails/MessagesTab.tsx +0 -156
  104. package/src/RedactoPrivacyCenter/components/CaseDetails/RequestDetailsTab.tsx +0 -171
  105. package/src/RedactoPrivacyCenter/components/CaseDetails/StatusEvent.tsx +0 -23
  106. package/src/RedactoPrivacyCenter/components/CaseDetails/useFileUpload.ts +0 -116
  107. package/src/RedactoPrivacyCenter/components/CaseDetails/useMessagePolling.ts +0 -43
  108. package/src/RedactoPrivacyCenter/components/CaseDetails/utils.ts +0 -71
  109. package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +0 -469
  110. package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +0 -426
  111. package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +0 -1198
  112. package/src/RedactoPrivacyCenter/components/ConsentManagerCells.tsx +0 -201
  113. package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +0 -138
  114. package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +0 -7
  115. package/src/RedactoPrivacyCenter/components/ConsentManagerExpandedRow.tsx +0 -179
  116. package/src/RedactoPrivacyCenter/components/ConsentManagerGroupedColumns.tsx +0 -318
  117. package/src/RedactoPrivacyCenter/components/ConsentManagerProductCards.tsx +0 -333
  118. package/src/RedactoPrivacyCenter/components/ConsentManagerPurposeCards.tsx +0 -102
  119. package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +0 -159
  120. package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +0 -189
  121. package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +0 -118
  122. package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +0 -66
  123. package/src/RedactoPrivacyCenter/components/DataRequest/ProductSelectionSection.tsx +0 -222
  124. package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +0 -331
  125. package/src/RedactoPrivacyCenter/components/Form.tsx +0 -1796
  126. package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +0 -174
  127. package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +0 -337
  128. package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +0 -334
  129. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationBell.tsx +0 -173
  130. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationCTAButton.tsx +0 -18
  131. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdown.tsx +0 -54
  132. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationDropdownItem.tsx +0 -57
  133. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationIcon.tsx +0 -19
  134. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationListPanel.tsx +0 -92
  135. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRefreshButton.tsx +0 -20
  136. package/src/RedactoPrivacyCenter/components/NotificationHub/NotificationRow.tsx +0 -58
  137. package/src/RedactoPrivacyCenter/components/NotificationHub/StatCard.tsx +0 -10
  138. package/src/RedactoPrivacyCenter/components/NotificationHub/useNotificationActions.ts +0 -112
  139. package/src/RedactoPrivacyCenter/components/NotificationHub/utils.ts +0 -27
  140. package/src/RedactoPrivacyCenter/components/Pagination.tsx +0 -140
  141. package/src/RedactoPrivacyCenter/components/PrivacyCenterEmptyState.tsx +0 -76
  142. package/src/RedactoPrivacyCenter/components/PrivacyCenterSessionExpired.tsx +0 -97
  143. package/src/RedactoPrivacyCenter/components/ReceiptsList.tsx +0 -454
  144. package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +0 -270
  145. package/src/RedactoPrivacyCenter/components/SelectUser.tsx +0 -83
  146. package/src/RedactoPrivacyCenter/components/SelectUserGate.tsx +0 -193
  147. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +0 -25
  148. package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +0 -21
  149. package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +0 -159
  150. package/src/RedactoPrivacyCenter/components/constant.ts +0 -52
  151. package/src/RedactoPrivacyCenter/components/groupHelpers.ts +0 -119
  152. package/src/RedactoPrivacyCenter/components/receiptColumns.tsx +0 -203
  153. package/src/RedactoPrivacyCenter/components/types.ts +0 -123
  154. package/src/RedactoPrivacyCenter/components/utils.tsx +0 -10
  155. package/src/RedactoPrivacyCenter/config/routes.ts +0 -9
  156. package/src/RedactoPrivacyCenter/config/table.ts +0 -25
  157. package/src/RedactoPrivacyCenter/context/AuthContext.tsx +0 -160
  158. package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +0 -47
  159. package/src/RedactoPrivacyCenter/context/BrandingContext.tsx +0 -52
  160. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.session-expired.test.tsx +0 -92
  161. package/src/RedactoPrivacyCenter/context/DataAvailabilityContext.tsx +0 -181
  162. package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +0 -11
  163. package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +0 -96
  164. package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +0 -30
  165. package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +0 -80
  166. package/src/RedactoPrivacyCenter/context/ProfileSwitchContext.tsx +0 -15
  167. package/src/RedactoPrivacyCenter/context/types.ts +0 -19
  168. package/src/RedactoPrivacyCenter/lib/api.ts +0 -756
  169. package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +0 -67
  170. package/src/RedactoPrivacyCenter/lib/constants.ts +0 -277
  171. package/src/RedactoPrivacyCenter/lib/i18n.ts +0 -81
  172. package/src/RedactoPrivacyCenter/lib/locales.ts +0 -105
  173. package/src/RedactoPrivacyCenter/lib/queries.ts +0 -141
  174. package/src/RedactoPrivacyCenter/lib/types.ts +0 -868
  175. package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +0 -37
  176. package/src/RedactoPrivacyCenter/lib/utils.refresh-circuit.test.ts +0 -127
  177. package/src/RedactoPrivacyCenter/lib/utils.refresh-storage.test.ts +0 -85
  178. package/src/RedactoPrivacyCenter/lib/utils.session-expired.test.ts +0 -109
  179. package/src/RedactoPrivacyCenter/lib/utils.ts +0 -783
  180. package/src/RedactoPrivacyCenter/locales/as/translation.json +0 -340
  181. package/src/RedactoPrivacyCenter/locales/bho/translation.json +0 -340
  182. package/src/RedactoPrivacyCenter/locales/bn/translation.json +0 -340
  183. package/src/RedactoPrivacyCenter/locales/brx/translation.json +0 -340
  184. package/src/RedactoPrivacyCenter/locales/doi/translation.json +0 -340
  185. package/src/RedactoPrivacyCenter/locales/en/translation.json +0 -354
  186. package/src/RedactoPrivacyCenter/locales/gom/translation.json +0 -340
  187. package/src/RedactoPrivacyCenter/locales/gu/translation.json +0 -340
  188. package/src/RedactoPrivacyCenter/locales/hi/translation.json +0 -343
  189. package/src/RedactoPrivacyCenter/locales/kn/translation.json +0 -340
  190. package/src/RedactoPrivacyCenter/locales/ks/translation.json +0 -340
  191. package/src/RedactoPrivacyCenter/locales/mai/translation.json +0 -340
  192. package/src/RedactoPrivacyCenter/locales/ml/translation.json +0 -340
  193. package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +0 -340
  194. package/src/RedactoPrivacyCenter/locales/mr/translation.json +0 -340
  195. package/src/RedactoPrivacyCenter/locales/ne/translation.json +0 -340
  196. package/src/RedactoPrivacyCenter/locales/or/translation.json +0 -340
  197. package/src/RedactoPrivacyCenter/locales/pa/translation.json +0 -340
  198. package/src/RedactoPrivacyCenter/locales/sa/translation.json +0 -340
  199. package/src/RedactoPrivacyCenter/locales/sat/translation.json +0 -340
  200. package/src/RedactoPrivacyCenter/locales/sd/translation.json +0 -340
  201. package/src/RedactoPrivacyCenter/locales/ta/translation.json +0 -340
  202. package/src/RedactoPrivacyCenter/locales/te/translation.json +0 -340
  203. package/src/RedactoPrivacyCenter/locales/ur/translation.json +0 -340
  204. package/src/RedactoPrivacyCenter/styles/applyBrandingTheme.ts +0 -66
  205. package/src/RedactoPrivacyCenter/styles/base.css +0 -117
  206. package/src/RedactoPrivacyCenter/styles/injectStyles.ts +0 -3103
  207. package/src/RedactoPrivacyCenter/styles/pcStyles.ts +0 -814
  208. package/src/RedactoPrivacyCenter/styles/responsive.ts +0 -138
  209. package/src/RedactoPrivacyCenter/styles/variables.css +0 -96
  210. package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +0 -387
  211. package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +0 -468
  212. package/src/RedactoPrivacyCenter/table/index.ts +0 -2
  213. package/src/RedactoPrivacyCenter/types/images.d.ts +0 -29
  214. package/src/RedactoPrivacyCenter/ui/Footer.tsx +0 -69
  215. package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +0 -54
  216. package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +0 -93
  217. package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +0 -47
  218. package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +0 -69
  219. package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +0 -48
  220. package/src/RedactoPrivacyCenter/ui/PCButton.tsx +0 -77
  221. package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +0 -55
  222. package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +0 -107
  223. package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +0 -35
  224. package/src/RedactoPrivacyCenter/ui/PCInput.tsx +0 -132
  225. package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +0 -31
  226. package/src/RedactoPrivacyCenter/ui/PCModal.tsx +0 -106
  227. package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +0 -206
  228. package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +0 -433
  229. package/src/RedactoPrivacyCenter/ui/PCTable.tsx +0 -149
  230. package/src/RedactoPrivacyCenter/ui/PCText.tsx +0 -41
  231. package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +0 -43
  232. package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +0 -37
  233. package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +0 -121
  234. package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +0 -25
  235. package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +0 -53
  236. package/src/RedactoPrivacyCenter/ui/index.ts +0 -18
  237. package/src/RedactoPrivacyCenter/utils/cn.ts +0 -28
  238. package/src/RedactoPrivacyCenter/utils/date.ts +0 -48
  239. package/src/RedactoPrivacyCenter/utils/status.ts +0 -111
  240. package/src/RedactoPrivacyCenter/utils/toast.ts +0 -130
  241. package/src/index.ts +0 -19
  242. package/src/privacy-center.ts +0 -113
  243. package/src/shared/api-errors.ts +0 -180
  244. package/src/types/css.d.ts +0 -4
  245. package/src/types/images.d.ts +0 -19
  246. package/src/types/react-jsx.d.ts +0 -26
  247. package/tests/DataAvailabilityContext.test.tsx +0 -123
  248. package/tests/Form.test.tsx +0 -1287
  249. package/tests/ProductSelectionSection.test.tsx +0 -328
  250. package/tests/RequestSubmit.test.tsx +0 -135
  251. package/tests/consentClient.test.ts +0 -171
  252. package/tests/manageConsentServer.test.ts +0 -38
  253. package/tests/mocks.ts +0 -257
  254. package/tests/resolveContactFromJwt.test.ts +0 -44
  255. package/tests/setup.ts +0 -16
  256. package/tsconfig.json +0 -16
  257. package/tsup.config.ts +0 -31
  258. package/vitest.config.ts +0 -16
@@ -1,1198 +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
- });
780
-
781
- if (response) {
782
- toast.success(successMessages[action]);
783
- await fetchData();
784
- } else {
785
- toast.error(errorMessages[action]);
786
- }
787
- } catch (error: any) {
788
- console.error(`Error ${action} consent:`, error);
789
- if (error?.code === 'NOMINATOR_NOT_FOUND') {
790
- toast.error(t('nominatorNotFound'));
791
- } else if (error?.code === 'NOMINEE_MUST_SPECIFY_NOMINATOR') {
792
- toast.error(t('nomineeMustSpecifyNominator'));
793
- } else {
794
- toast.error(errorMessages[action]);
795
- }
796
- } finally {
797
- setIsManageLoading(false);
798
- handleCloseModal();
799
- }
800
- },
801
- [organizationId, workspaceId, contact, fetchData, handleCloseModal, t, authContext, consentClient, selectedRecord]
802
- );
803
-
804
- const getVar = (varName: string): string => `var(${varName})`;
805
-
806
- const directBadge: number | '' =
807
- consentDetail?.status_summary?.direct_purposes ?? '';
808
-
809
- const nominatedBadge: number | '' =
810
- consentDetail?.status_summary?.nominated_purposes ?? '';
811
-
812
- const nominatorLabels = (consentDetail?.nominators || [])
813
- .map((n) => n.email?.trim() || n.org_user_id?.trim() || n.uuid?.trim() || '')
814
- .filter(Boolean);
815
- const summaryText = t('productsAndConsentsSummary', {
816
- products: visibleProductCount,
817
- consents: visibleConsentCount,
818
- });
819
-
820
- return (
821
- <div className="pc-consent-manager-surface" style={{ width: '100%' }}>
822
- <div
823
- className="pc-consent-shell-card"
824
- style={{
825
- backgroundColor: 'transparent',
826
- }}
827
- >
828
- {/* Tabs: My Consents / Managing + Product/Purpose toggle */}
829
- <div
830
- className="pc-consent-tabs-row"
831
- style={{
832
- display: 'flex',
833
- alignItems: 'center',
834
- justifyContent: 'space-between',
835
- gap: getVar('--pc-spacing-sm'),
836
- borderBottom: `1px solid ${getVar('--pc-border-color')}`,
837
- padding: '0.125rem 0 0.375rem',
838
- }}
839
- >
840
- <div className="pc-consent-tabs-left" style={{ display: 'flex', minWidth: 0 }}>
841
- <button
842
- type="button"
843
- onClick={() => handleTabChange('direct')}
844
- style={{
845
- display: 'flex',
846
- alignItems: 'center',
847
- gap: getVar('--pc-spacing-sm'),
848
- padding: `0.5rem ${getVar('--pc-spacing-sm')}`,
849
- fontSize: '0.75rem',
850
- fontWeight: 600,
851
- background: 'none',
852
- border: 'none',
853
- cursor: 'pointer',
854
- borderBottom: activeTab === 'direct' ? `2px solid ${getVar('--pc-primary')}` : '2px solid transparent',
855
- color: activeTab === 'direct' ? getVar('--pc-primary') : getVar('--pc-text-secondary'),
856
- transition: 'color 0.2s, border-color 0.2s',
857
- }}
858
- >
859
- {t('myConsents')}
860
- <span style={{
861
- borderRadius: '9999px',
862
- backgroundColor: getVar('--pc-bg-tertiary'),
863
- padding: '0.0625rem 0.375rem',
864
- fontSize: '0.6875rem',
865
- color: getVar('--pc-text-secondary'),
866
- }}>
867
- {directBadge}
868
- </span>
869
- </button>
870
- <button
871
- type="button"
872
- onClick={() => handleTabChange('nominated')}
873
- style={{
874
- display: 'flex',
875
- alignItems: 'center',
876
- gap: getVar('--pc-spacing-sm'),
877
- padding: `0.5rem ${getVar('--pc-spacing-sm')}`,
878
- fontSize: '0.75rem',
879
- fontWeight: 600,
880
- background: 'none',
881
- border: 'none',
882
- cursor: 'pointer',
883
- borderBottom: activeTab === 'nominated' ? `2px solid ${getVar('--pc-primary')}` : '2px solid transparent',
884
- color: activeTab === 'nominated' ? getVar('--pc-primary') : getVar('--pc-text-secondary'),
885
- transition: 'color 0.2s, border-color 0.2s',
886
- }}
887
- >
888
- {t('managing')}
889
- <span style={{
890
- borderRadius: '9999px',
891
- backgroundColor: getVar('--pc-bg-tertiary'),
892
- padding: '0.0625rem 0.375rem',
893
- fontSize: '0.6875rem',
894
- color: getVar('--pc-text-secondary'),
895
- }}>
896
- {nominatedBadge}
897
- </span>
898
- </button>
899
- </div>
900
-
901
- <div
902
- className="pc-consent-view-toggle"
903
- style={{
904
- marginLeft: 'auto',
905
- display: 'flex',
906
- alignItems: 'center',
907
- gap: getVar('--pc-spacing-sm'),
908
- paddingRight: getVar('--pc-spacing-sm'),
909
- }}
910
- >
911
- <PCText
912
- size="sm"
913
- color="secondary"
914
- className="pc-consent-view-toggle-label"
915
- style={{ margin: 0, fontSize: '0.75rem', fontWeight: 500 }}
916
- >
917
- {t('consentVisibility')}
918
- </PCText>
919
- <div
920
- className="pc-consent-view-toggle-group"
921
- style={{
922
- display: 'inline-flex',
923
- borderRadius: '9999px',
924
- backgroundColor: getVar('--pc-bg-secondary'),
925
- padding: '0.125rem',
926
- }}
927
- >
928
- <button
929
- type="button"
930
- className={`pc-consent-view-toggle-btn ${viewMode === 'product' ? 'is-active' : ''}`}
931
- onClick={() => handleViewModeChange('product')}
932
- style={{
933
- minWidth: '5.25rem',
934
- minHeight: '1.75rem',
935
- padding: '0.3125rem 0.75rem',
936
- border: 'none',
937
- backgroundColor:
938
- viewMode === 'product' ? getVar('--pc-primary') : 'transparent',
939
- color:
940
- viewMode === 'product'
941
- ? getVar('--pc-text-inverse')
942
- : getVar('--pc-text-secondary'),
943
- fontSize: '0.6875rem',
944
- fontWeight: 600,
945
- cursor: 'pointer',
946
- borderRadius: '9999px',
947
- transition: 'background-color 0.2s ease, color 0.2s ease',
948
- }}
949
- >
950
- {t('product')}
951
- </button>
952
- <button
953
- type="button"
954
- className={`pc-consent-view-toggle-btn ${viewMode === 'purpose' ? 'is-active' : ''}`}
955
- onClick={() => handleViewModeChange('purpose')}
956
- style={{
957
- minWidth: '5.25rem',
958
- minHeight: '1.75rem',
959
- padding: '0.3125rem 0.75rem',
960
- border: 'none',
961
- backgroundColor:
962
- viewMode === 'purpose' ? getVar('--pc-primary') : 'transparent',
963
- color:
964
- viewMode === 'purpose'
965
- ? getVar('--pc-text-inverse')
966
- : getVar('--pc-text-secondary'),
967
- fontSize: '0.6875rem',
968
- fontWeight: 600,
969
- cursor: 'pointer',
970
- borderRadius: '9999px',
971
- transition: 'background-color 0.2s ease, color 0.2s ease',
972
- }}
973
- >
974
- {t('purpose')}
975
- </button>
976
- </div>
977
- </div>
978
- </div>
979
-
980
- {activeTab === 'nominated' && nominatorLabels.length > 0 && (
981
- <PCText
982
- size="sm"
983
- color="secondary"
984
- style={{
985
- margin: 0,
986
- marginBottom: getVar('--pc-spacing-sm'),
987
- paddingLeft: getVar('--pc-spacing-lg'),
988
- paddingRight: getVar('--pc-spacing-lg'),
989
- }}
990
- >
991
- {t('managingConsentsFor')}{' '}
992
- <span style={{ fontWeight: 600, color: getVar('--pc-text-primary') }}>
993
- {nominatorLabels.join(', ')}
994
- </span>
995
- </PCText>
996
- )}
997
-
998
- {/* Filters Section: Search on left, filters and export on the right */}
999
- <div style={{
1000
- display: 'flex',
1001
- flexDirection: 'column',
1002
- gap: getVar('--pc-spacing-sm'),
1003
- width: '100%',
1004
- padding: '0.75rem 0 0.625rem',
1005
- }} className="pc-filters-responsive">
1006
- <div style={{ width: '100%' }} className="pc-search-responsive">
1007
- <PCInput
1008
- type="search"
1009
- size="sm"
1010
- clearable
1011
- clearAriaLabel={t('clearInput')}
1012
- placeholder={composedSearchPlaceholder}
1013
- value={searchQuery}
1014
- onClear={() => {
1015
- setSearchQuery('');
1016
- setCurrentPage(DEFAULT_PAGE);
1017
- }}
1018
- prefix={<Search size={14} strokeWidth={1.8} />}
1019
- onChange={(e) => {
1020
- setSearchQuery(e.target.value);
1021
- setCurrentPage(DEFAULT_PAGE);
1022
- }}
1023
- style={{
1024
- width: '100%',
1025
- }}
1026
- />
1027
- </div>
1028
-
1029
- <div style={{
1030
- display: 'flex',
1031
- flexDirection: 'column',
1032
- gap: getVar('--pc-spacing-sm'),
1033
- width: '100%',
1034
- }} className="pc-filters-row-responsive">
1035
- <PCSelect
1036
- className="pc-filter-select"
1037
- size="sm"
1038
- placeholder={t('status')}
1039
- prefix={<Filter size={12} strokeWidth={1.8} />}
1040
- options={statusFilterOptions}
1041
- value={statusSelectValue}
1042
- onChange={handleStatusFilterChange}
1043
- showSelectedCheck
1044
- style={{
1045
- width: '100%',
1046
- }}
1047
- />
1048
- <PCSelect
1049
- className="pc-filter-select"
1050
- size="sm"
1051
- placeholder={t('product')}
1052
- prefix={<Circle size={10} strokeWidth={2} />}
1053
- options={productFilterOptions}
1054
- value={productSelectValue}
1055
- onChange={handleProductFilterChange}
1056
- showSelectedCheck
1057
- style={{
1058
- width: '100%',
1059
- }}
1060
- />
1061
- <PCText
1062
- size="sm"
1063
- color="secondary"
1064
- className="pc-filters-summary"
1065
- style={{
1066
- margin: 0,
1067
- whiteSpace: 'nowrap',
1068
- alignSelf: 'center',
1069
- }}
1070
- >
1071
- {summaryText}
1072
- </PCText>
1073
- <div className="pc-export-button-responsive">
1074
- <PCButton
1075
- size="sm"
1076
- variant="outline"
1077
- onClick={() => setExportModal(true)}
1078
- style={{
1079
- whiteSpace: 'nowrap',
1080
- width: '100%',
1081
- }}
1082
- >
1083
- <ArrowUpToLine size={13} />
1084
- <span>{t('export')}</span>
1085
- </PCButton>
1086
- </div>
1087
- </div>
1088
- </div>
1089
- {isLoading ? (
1090
- <ConsentManagerTableSkeleton />
1091
- ) : (
1092
- <>
1093
- <div className="pc-consent-desktop-view">
1094
- {viewMode === 'product' ? (
1095
- <AdvancedTable
1096
- table={productTable}
1097
- variant={variant}
1098
- classNames={groupedTableClassNames}
1099
- isLoading={isLoading}
1100
- expandedComponent={(row) => {
1101
- const cardKey = getCardKey(row.original);
1102
- return (
1103
- <ConsentManagerExpandedRow
1104
- group={row.original}
1105
- onModify={handleOpenModal}
1106
- extraPurposes={extraPurposesByKey[cardKey]}
1107
- hasMore={hasMoreByKey[cardKey] ?? row.original.has_more_purposes}
1108
- isLoadingMore={loadingMoreByKey[cardKey]}
1109
- onLoadMore={handleLoadMorePurposes}
1110
- />
1111
- );
1112
- }}
1113
- />
1114
- ) : (
1115
- <AdvancedTable
1116
- table={purposeTable}
1117
- variant={variant}
1118
- classNames={purposeTableClassNames}
1119
- isLoading={isLoading}
1120
- />
1121
- )}
1122
- </div>
1123
-
1124
- <div className="pc-consent-mobile-view">
1125
- {viewMode === 'product' ? (
1126
- <ConsentManagerProductCards
1127
- groups={consentGroups}
1128
- onModify={handleOpenModal}
1129
- extraPurposesByKey={extraPurposesByKey}
1130
- hasMoreByKey={hasMoreByKey}
1131
- loadingMoreByKey={loadingMoreByKey}
1132
- onLoadMore={handleLoadMorePurposes}
1133
- cardKeyFor={getCardKey}
1134
- />
1135
- ) : (
1136
- <ConsentManagerPurposeCards
1137
- rows={consentRows}
1138
- onModify={handleOpenModal}
1139
- />
1140
- )}
1141
- </div>
1142
- </>
1143
- )}
1144
-
1145
- {viewMode === 'product' && (
1146
- <div className="pc-consent-pagination-wrap">
1147
- <AdvancedTablePagination table={productTable} />
1148
- </div>
1149
- )}
1150
- </div>
1151
-
1152
- <PCModal
1153
- isOpen={exportModal}
1154
- onClose={() => setExportModal(false)}
1155
- size="sm"
1156
- closeAriaLabel={t('closeModal')}
1157
- title={
1158
- <div style={{ minWidth: 0, flex: 1, paddingRight: getVar('--pc-spacing-sm') }}>
1159
- <PCText size="base" weight="semibold" style={{ margin: 0, color: getVar('--pc-text-primary') }}>
1160
- {t('exportConsentData')}
1161
- </PCText>
1162
- <PCText
1163
- size="xs"
1164
- color="secondary"
1165
- style={{ marginTop: pcStyles.mtXs.marginTop, marginBottom: 0, lineHeight: 1.5 }}
1166
- >
1167
- {t('exportConsentDataSubtitle')}
1168
- </PCText>
1169
- </div>
1170
- }
1171
- footer={
1172
- <div className="pc-modal-footer-actions">
1173
- <PCButton variant="secondary" onClick={() => setExportModal(false)}>
1174
- {t('cancel')}
1175
- </PCButton>
1176
- <PCButton variant="primary" onClick={handleExport}>
1177
- {t('export')}
1178
- </PCButton>
1179
- </div>
1180
- }
1181
- >
1182
- <div style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: pcStyles.gapSm.gap }}>
1183
- <PCText size="sm" color="secondary" style={{ margin: 0, lineHeight: 1.6 }}>
1184
- {t('exportingIncludesFilters')}
1185
- </PCText>
1186
- </div>
1187
- </PCModal>
1188
-
1189
- <ModifyConsentModal
1190
- isOpen={isModalOpen}
1191
- onClose={handleCloseModal}
1192
- selectedRecord={selectedRecord}
1193
- isLoading={isManageLoading}
1194
- onManageConsent={handleManageConsent}
1195
- />
1196
- </div>
1197
- );
1198
- }