@redacto.io/consent-sdk-react 3.4.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/LICENSE +176 -0
- package/dist/index.d.mts +51 -4
- package/dist/index.d.ts +51 -4
- package/dist/index.js +1912 -345
- package/dist/index.mjs +1911 -345
- package/dist/privacy-center.d.mts +566 -0
- package/dist/privacy-center.d.ts +566 -0
- package/dist/privacy-center.js +17174 -0
- package/dist/privacy-center.mjs +17136 -0
- package/package.json +47 -3
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.test.tsx +201 -118
- package/src/RedactoNoticeConsent/RedactoNoticeConsent.tsx +1194 -93
- package/src/RedactoNoticeConsent/api/index.ts +337 -246
- package/src/RedactoNoticeConsent/api/types.ts +140 -41
- package/src/RedactoNoticeConsent/components/DigiLockerCallback.tsx +602 -0
- package/src/RedactoNoticeConsent/components/index.ts +7 -0
- package/src/RedactoNoticeConsent/injectStyles.ts +11 -0
- package/src/RedactoNoticeConsent/language-codes.ts +61 -0
- package/src/RedactoNoticeConsent/services/storage.ts +122 -0
- package/src/RedactoNoticeConsent/types.ts +2 -0
- package/src/RedactoNoticeConsentInline/api/index.ts +26 -64
- package/src/RedactoNoticeConsentInline/api/types.ts +0 -25
- package/src/RedactoPrivacyCenter/PrivacyCenterActivityPage.tsx +19 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterConsentManagerPage.tsx +17 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterFormPage.tsx +79 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterHomePage.tsx +27 -0
- package/src/RedactoPrivacyCenter/PrivacyCenterLayout.tsx +142 -0
- package/src/RedactoPrivacyCenter/RedactoPrivacyCenter.tsx +51 -0
- package/src/RedactoPrivacyCenter/api/actions.ts +444 -0
- package/src/RedactoPrivacyCenter/api/client.ts +413 -0
- package/src/RedactoPrivacyCenter/api/config.ts +33 -0
- package/src/RedactoPrivacyCenter/api/fetcher.ts +181 -0
- package/src/RedactoPrivacyCenter/api/upload.ts +93 -0
- package/src/RedactoPrivacyCenter/assets/character.svg +31 -0
- package/src/RedactoPrivacyCenter/assets/fileAttach.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/greenTick.svg +4 -0
- package/src/RedactoPrivacyCenter/assets/mail.svg +3 -0
- package/src/RedactoPrivacyCenter/assets/poweredByRedacto.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/sentImg.svg +9 -0
- package/src/RedactoPrivacyCenter/assets/uploadFileIcon.svg +9 -0
- package/src/RedactoPrivacyCenter/components/ActivitiesList.tsx +272 -0
- package/src/RedactoPrivacyCenter/components/CaseDetailsModal.tsx +468 -0
- package/src/RedactoPrivacyCenter/components/CaseHistory.tsx +433 -0
- package/src/RedactoPrivacyCenter/components/ConsentManager.tsx +726 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerColumns.tsx +239 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerConstants.ts +7 -0
- package/src/RedactoPrivacyCenter/components/ConsentManagerTableSkeleton.tsx +155 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/CorrectionDataSection.tsx +189 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/GrievanceDataSection.tsx +118 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/NominationDataSection.tsx +66 -0
- package/src/RedactoPrivacyCenter/components/DataRequest/PurposeSelectionSection.tsx +305 -0
- package/src/RedactoPrivacyCenter/components/Form.tsx +1455 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTable.tsx +176 -0
- package/src/RedactoPrivacyCenter/components/GrievanceTablePagination.tsx +330 -0
- package/src/RedactoPrivacyCenter/components/ModifyConsentModal.tsx +329 -0
- package/src/RedactoPrivacyCenter/components/Pagination.tsx +140 -0
- package/src/RedactoPrivacyCenter/components/PrivacyCenterLayout.tsx +302 -0
- package/src/RedactoPrivacyCenter/components/RequestSubmit.tsx +218 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideBarPC.tsx +475 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/SideMenuPC.tsx +412 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/constants.tsx +42 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/menuItemsPC.tsx +1 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/types.ts +40 -0
- package/src/RedactoPrivacyCenter/components/SideMenuBarPC/utils.ts +38 -0
- package/src/RedactoPrivacyCenter/components/ThemeTransitionOverlay.tsx +85 -0
- package/src/RedactoPrivacyCenter/components/activitiesColumns.tsx +141 -0
- package/src/RedactoPrivacyCenter/components/caseHistoryColumns.tsx +179 -0
- package/src/RedactoPrivacyCenter/components/constant.ts +20 -0
- package/src/RedactoPrivacyCenter/components/types.ts +68 -0
- package/src/RedactoPrivacyCenter/components/utils.tsx +10 -0
- package/src/RedactoPrivacyCenter/config/routes.ts +9 -0
- package/src/RedactoPrivacyCenter/config/table.ts +25 -0
- package/src/RedactoPrivacyCenter/context/AuthContext.tsx +123 -0
- package/src/RedactoPrivacyCenter/context/BaseUrlContext.tsx +44 -0
- package/src/RedactoPrivacyCenter/context/LocaleContext.tsx +11 -0
- package/src/RedactoPrivacyCenter/context/NavigationContext.tsx +64 -0
- package/src/RedactoPrivacyCenter/context/OrganizationContext.tsx +30 -0
- package/src/RedactoPrivacyCenter/context/PageChromeContext.tsx +60 -0
- package/src/RedactoPrivacyCenter/context/theme.tsx +127 -0
- package/src/RedactoPrivacyCenter/lib/api.ts +468 -0
- package/src/RedactoPrivacyCenter/lib/consent-manager/utils.tsx +63 -0
- package/src/RedactoPrivacyCenter/lib/constants.ts +116 -0
- package/src/RedactoPrivacyCenter/lib/i18n.ts +81 -0
- package/src/RedactoPrivacyCenter/lib/locales.ts +105 -0
- package/src/RedactoPrivacyCenter/lib/queries.ts +30 -0
- package/src/RedactoPrivacyCenter/lib/types.ts +346 -0
- package/src/RedactoPrivacyCenter/lib/useCurrentLanguage.ts +37 -0
- package/src/RedactoPrivacyCenter/lib/utils.ts +625 -0
- package/src/RedactoPrivacyCenter/locales/as/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/bho/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/bn/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/brx/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/doi/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/en/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/gom/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/gu/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/hi/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/kn/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ks/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/mai/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ml/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/mni-Mtei/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/mr/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ne/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/or/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/pa/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/sa/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/sat/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/sd/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ta/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/te/translation.json +188 -0
- package/src/RedactoPrivacyCenter/locales/ur/translation.json +188 -0
- package/src/RedactoPrivacyCenter/styles/base.css +117 -0
- package/src/RedactoPrivacyCenter/styles/injectStyles.ts +1000 -0
- package/src/RedactoPrivacyCenter/styles/pcStyles.ts +819 -0
- package/src/RedactoPrivacyCenter/styles/responsive.ts +138 -0
- package/src/RedactoPrivacyCenter/styles/variables.css +133 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTable.tsx +365 -0
- package/src/RedactoPrivacyCenter/table/AdvancedTablePagination.tsx +479 -0
- package/src/RedactoPrivacyCenter/table/index.ts +2 -0
- package/src/RedactoPrivacyCenter/types/images.d.ts +29 -0
- package/src/RedactoPrivacyCenter/ui/Footer.tsx +73 -0
- package/src/RedactoPrivacyCenter/ui/FormBlockWrapper.tsx +54 -0
- package/src/RedactoPrivacyCenter/ui/PCAccordion.tsx +87 -0
- package/src/RedactoPrivacyCenter/ui/PCActionIcon.tsx +47 -0
- package/src/RedactoPrivacyCenter/ui/PCAvatar.tsx +69 -0
- package/src/RedactoPrivacyCenter/ui/PCBadge.tsx +48 -0
- package/src/RedactoPrivacyCenter/ui/PCButton.tsx +77 -0
- package/src/RedactoPrivacyCenter/ui/PCCheckbox.tsx +55 -0
- package/src/RedactoPrivacyCenter/ui/PCCollapse.tsx +97 -0
- package/src/RedactoPrivacyCenter/ui/PCEmpty.tsx +35 -0
- package/src/RedactoPrivacyCenter/ui/PCInput.tsx +128 -0
- package/src/RedactoPrivacyCenter/ui/PCLoader.tsx +30 -0
- package/src/RedactoPrivacyCenter/ui/PCModal.tsx +104 -0
- package/src/RedactoPrivacyCenter/ui/PCPopover.tsx +175 -0
- package/src/RedactoPrivacyCenter/ui/PCSelect.tsx +381 -0
- package/src/RedactoPrivacyCenter/ui/PCTable.tsx +137 -0
- package/src/RedactoPrivacyCenter/ui/PCText.tsx +39 -0
- package/src/RedactoPrivacyCenter/ui/PCTextarea.tsx +43 -0
- package/src/RedactoPrivacyCenter/ui/PCTitle.tsx +37 -0
- package/src/RedactoPrivacyCenter/ui/PCTooltip.tsx +119 -0
- package/src/RedactoPrivacyCenter/ui/SimpleBar.tsx +25 -0
- package/src/RedactoPrivacyCenter/ui/StatusBadge.tsx +55 -0
- package/src/RedactoPrivacyCenter/ui/ThemeToggle.tsx +70 -0
- package/src/RedactoPrivacyCenter/ui/index.ts +18 -0
- package/src/RedactoPrivacyCenter/utils/cn.ts +28 -0
- package/src/RedactoPrivacyCenter/utils/date.ts +48 -0
- package/src/RedactoPrivacyCenter/utils/status.ts +111 -0
- package/src/RedactoPrivacyCenter/utils/toast.ts +130 -0
- package/src/index.ts +10 -0
- package/src/privacy-center.ts +107 -0
- package/tsconfig.json +2 -0
- package/tsup.config.ts +16 -1
- package/src/utils/isLegacyApi.ts +0 -12
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { PCCheckbox } from '../../ui';
|
|
3
|
+
import { pcStyles } from '../../styles/pcStyles';
|
|
4
|
+
import type { GrievanceDataSectionProps } from '../../lib/types';
|
|
5
|
+
|
|
6
|
+
const getVar = (varName: string): string => `var(${varName})`;
|
|
7
|
+
|
|
8
|
+
export default function GrievanceDataSection({
|
|
9
|
+
grievanceOptions,
|
|
10
|
+
selectedGrievances,
|
|
11
|
+
setSelectedGrievances,
|
|
12
|
+
isTranslating = false,
|
|
13
|
+
}: GrievanceDataSectionProps & { isTranslating?: boolean }) {
|
|
14
|
+
const { t } = useTranslation();
|
|
15
|
+
|
|
16
|
+
// Map grievance values to translation keys
|
|
17
|
+
const getGrievanceTranslationKey = (value: string): string => {
|
|
18
|
+
const mapping: Record<string, string> = {
|
|
19
|
+
'consent_violation': 'consentViolation',
|
|
20
|
+
'unlawful_processing': 'unlawfulProcessing',
|
|
21
|
+
'data_breach': 'dataBreach',
|
|
22
|
+
};
|
|
23
|
+
return mapping[value] || value;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const handleSelectAll = (checked: boolean) => {
|
|
27
|
+
const updated: Record<string, boolean> = {};
|
|
28
|
+
grievanceOptions.forEach((opt) => {
|
|
29
|
+
updated[opt.value] = checked;
|
|
30
|
+
});
|
|
31
|
+
setSelectedGrievances(updated);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const handleGrievanceChange = (value: string, checked: boolean) => {
|
|
35
|
+
setSelectedGrievances((prev) => ({
|
|
36
|
+
...prev,
|
|
37
|
+
[value]: checked,
|
|
38
|
+
}));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const isAllSelected =
|
|
42
|
+
Object.keys(selectedGrievances).length > 0 &&
|
|
43
|
+
Object.values(selectedGrievances).every(Boolean);
|
|
44
|
+
|
|
45
|
+
if (isTranslating) {
|
|
46
|
+
return (
|
|
47
|
+
<div style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: getVar('--pc-spacing-sm') }}>
|
|
48
|
+
<div style={{ marginBottom: '0.375rem' }}>
|
|
49
|
+
<div style={{ height: '1rem', width: '8rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
50
|
+
</div>
|
|
51
|
+
<div style={{
|
|
52
|
+
backgroundColor: getVar('--pc-bg-secondary'),
|
|
53
|
+
borderRadius: pcStyles.borderRadiusMd,
|
|
54
|
+
padding: getVar('--pc-spacing-sm'),
|
|
55
|
+
border: `1px solid ${getVar('--pc-border-color')}`,
|
|
56
|
+
}}>
|
|
57
|
+
{[1, 2, 3].map((skeletonIndex) => (
|
|
58
|
+
<div key={skeletonIndex} style={{ marginBottom: skeletonIndex < 3 ? getVar('--pc-spacing-xs') : 0, ...pcStyles.flex, ...pcStyles.itemsCenter, ...pcStyles.gapSm }}>
|
|
59
|
+
<div style={{ height: '1rem', width: '1rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
60
|
+
<div style={{ height: '1rem', width: '10rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
61
|
+
</div>
|
|
62
|
+
))}
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: getVar('--pc-spacing-xs') }}>
|
|
70
|
+
<p style={{
|
|
71
|
+
margin: 0,
|
|
72
|
+
fontSize: pcStyles.textXs.fontSize,
|
|
73
|
+
color: getVar('--pc-text-secondary'),
|
|
74
|
+
}}>
|
|
75
|
+
{t('selectGrievance')}
|
|
76
|
+
</p>
|
|
77
|
+
<div style={{
|
|
78
|
+
backgroundColor: getVar('--pc-bg-secondary'),
|
|
79
|
+
borderRadius: pcStyles.borderRadiusMd,
|
|
80
|
+
padding: getVar('--pc-spacing-sm'),
|
|
81
|
+
border: `1px solid ${getVar('--pc-border-color')}`,
|
|
82
|
+
}}>
|
|
83
|
+
<PCCheckbox
|
|
84
|
+
label={t('selectAll')}
|
|
85
|
+
size="sm"
|
|
86
|
+
labelClassName="text-sm font-medium"
|
|
87
|
+
style={{ marginBottom: getVar('--pc-spacing-sm') }}
|
|
88
|
+
checked={isAllSelected}
|
|
89
|
+
onChange={(e) => handleSelectAll(e.target.checked)}
|
|
90
|
+
/>
|
|
91
|
+
<div style={{
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flexDirection: 'column',
|
|
94
|
+
gap: getVar('--pc-spacing-xs'),
|
|
95
|
+
}}>
|
|
96
|
+
{grievanceOptions.map((option) => {
|
|
97
|
+
// Translate the label using i18next based on the value
|
|
98
|
+
const translationKey = getGrievanceTranslationKey(option.value);
|
|
99
|
+
const translatedLabel = t(translationKey);
|
|
100
|
+
|
|
101
|
+
return (
|
|
102
|
+
<PCCheckbox
|
|
103
|
+
key={option.value}
|
|
104
|
+
label={translatedLabel}
|
|
105
|
+
size="sm"
|
|
106
|
+
labelClassName="text-sm capitalize"
|
|
107
|
+
checked={selectedGrievances[option.value]}
|
|
108
|
+
onChange={(e) =>
|
|
109
|
+
handleGrievanceChange(option.value, e.target.checked)
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
);
|
|
113
|
+
})}
|
|
114
|
+
</div>
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { PCInput } from '../../ui';
|
|
3
|
+
import { pcStyles } from '../../styles/pcStyles';
|
|
4
|
+
import type { NominationDataSectionProps } from '../../lib/types';
|
|
5
|
+
|
|
6
|
+
const getVar = (varName: string): string => `var(${varName})`;
|
|
7
|
+
|
|
8
|
+
export default function NominationDataSection({
|
|
9
|
+
nominationData,
|
|
10
|
+
setNominationData,
|
|
11
|
+
isTranslating = false,
|
|
12
|
+
}: NominationDataSectionProps) {
|
|
13
|
+
const { t } = useTranslation();
|
|
14
|
+
|
|
15
|
+
if (isTranslating) {
|
|
16
|
+
return (
|
|
17
|
+
<div style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: getVar('--pc-spacing-sm') }}>
|
|
18
|
+
{[1, 2].map((skeletonIndex) => (
|
|
19
|
+
<div key={skeletonIndex} style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: getVar('--pc-spacing-xs') }}>
|
|
20
|
+
<div style={{ height: '1rem', width: '8rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
21
|
+
<div style={{ height: '2.25rem', width: '100%', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
22
|
+
</div>
|
|
23
|
+
))}
|
|
24
|
+
</div>
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<div style={{ ...pcStyles.flex, ...pcStyles.flexCol, gap: getVar('--pc-spacing-sm') }}>
|
|
30
|
+
<p style={{
|
|
31
|
+
margin: 0,
|
|
32
|
+
fontSize: pcStyles.textXs.fontSize,
|
|
33
|
+
color: getVar('--pc-text-secondary'),
|
|
34
|
+
}}>
|
|
35
|
+
{t('enterNomineeDetails')}
|
|
36
|
+
</p>
|
|
37
|
+
<PCInput
|
|
38
|
+
label={
|
|
39
|
+
<span>
|
|
40
|
+
{t('nomineeEmail')}
|
|
41
|
+
<span style={{ color: getVar('--pc-error') }}>*</span>
|
|
42
|
+
</span>
|
|
43
|
+
}
|
|
44
|
+
placeholder={t('nomineeEmailPlaceholder')}
|
|
45
|
+
value={nominationData.nominee_email ?? ''}
|
|
46
|
+
onChange={(e) =>
|
|
47
|
+
setNominationData((prev) => ({
|
|
48
|
+
...prev,
|
|
49
|
+
nominee_email: e.target.value,
|
|
50
|
+
}))
|
|
51
|
+
}
|
|
52
|
+
/>
|
|
53
|
+
<PCInput
|
|
54
|
+
label={t('nomineeMobile')}
|
|
55
|
+
placeholder={t('nomineeMobilePlaceholder')}
|
|
56
|
+
value={nominationData.nominee_mobile ?? ''}
|
|
57
|
+
onChange={(e) =>
|
|
58
|
+
setNominationData((prev) => ({
|
|
59
|
+
...prev,
|
|
60
|
+
nominee_mobile: e.target.value,
|
|
61
|
+
}))
|
|
62
|
+
}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { PCCheckbox } from '../../ui';
|
|
2
|
+
import { pcStyles } from '../../styles/pcStyles';
|
|
3
|
+
import { ChevronDown } from 'lucide-react';
|
|
4
|
+
import { RequestTypeEnum } from '../../lib/types';
|
|
5
|
+
import type { Purpose, DataElement } from '../../lib/types';
|
|
6
|
+
import { cn } from '../../utils/cn';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { useEffect, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
const getVar = (varName: string): string => `var(${varName})`;
|
|
11
|
+
|
|
12
|
+
export default function PurposeSelectionSection({
|
|
13
|
+
purposes,
|
|
14
|
+
setPurposes,
|
|
15
|
+
requestType,
|
|
16
|
+
isTranslating = false,
|
|
17
|
+
}: {
|
|
18
|
+
purposes: Purpose[];
|
|
19
|
+
setPurposes: (values: Purpose[]) => void;
|
|
20
|
+
requestType: RequestTypeEnum;
|
|
21
|
+
isTranslating?: boolean;
|
|
22
|
+
}) {
|
|
23
|
+
const isAccess = requestType === RequestTypeEnum.ACCESS;
|
|
24
|
+
const isErasure = requestType === RequestTypeEnum.ERASURE;
|
|
25
|
+
|
|
26
|
+
const [selectAllChecked, setSelectAllChecked] = useState(false);
|
|
27
|
+
const [openIndexes, setOpenIndexes] = useState<number[]>([]);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setSelectAllChecked(false);
|
|
31
|
+
setOpenIndexes([]);
|
|
32
|
+
}, [requestType]);
|
|
33
|
+
|
|
34
|
+
const { t } = useTranslation();
|
|
35
|
+
|
|
36
|
+
const handleSelectAll = (checked: boolean) => {
|
|
37
|
+
setSelectAllChecked(checked);
|
|
38
|
+
const updated = purposes.map((p) => ({
|
|
39
|
+
...p,
|
|
40
|
+
data_elements: p.data_elements.map((de: DataElement) => ({
|
|
41
|
+
...de,
|
|
42
|
+
selected: checked, // Allow deselection for all elements, including required ones
|
|
43
|
+
})),
|
|
44
|
+
}));
|
|
45
|
+
setPurposes(updated);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
const allSelected = purposes.every((p) =>
|
|
50
|
+
p.data_elements.every((de) => de.selected)
|
|
51
|
+
);
|
|
52
|
+
setSelectAllChecked(allSelected);
|
|
53
|
+
}, [purposes, isAccess, isErasure]);
|
|
54
|
+
|
|
55
|
+
const handleDataElementChange = (
|
|
56
|
+
e: React.ChangeEvent<HTMLInputElement>,
|
|
57
|
+
purposeIndex: number,
|
|
58
|
+
dataElementIndex: number
|
|
59
|
+
) => {
|
|
60
|
+
// Allow deselection for all elements, including required ones
|
|
61
|
+
const updatedPurposes = purposes.map((purpose, pIdx) => {
|
|
62
|
+
if (pIdx !== purposeIndex) return purpose;
|
|
63
|
+
return {
|
|
64
|
+
...purpose,
|
|
65
|
+
data_elements: purpose.data_elements.map((de, deIdx) =>
|
|
66
|
+
deIdx === dataElementIndex
|
|
67
|
+
? { ...de, selected: e.target.checked }
|
|
68
|
+
: de
|
|
69
|
+
),
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
setPurposes(updatedPurposes);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const handlePurposeSelectAll = (purposeIndex: number, checked: boolean) => {
|
|
76
|
+
const updatedPurposes = purposes.map((purpose, pIdx) => {
|
|
77
|
+
if (pIdx !== purposeIndex) return purpose;
|
|
78
|
+
return {
|
|
79
|
+
...purpose,
|
|
80
|
+
data_elements: purpose.data_elements.map((de) => ({
|
|
81
|
+
...de,
|
|
82
|
+
selected: checked, // Always allow selection/deselection for all elements
|
|
83
|
+
})),
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
setPurposes(updatedPurposes);
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const toggleAccordion = (index: number) => {
|
|
90
|
+
setOpenIndexes((prev) =>
|
|
91
|
+
prev.includes(index) ? prev.filter((i) => i !== index) : [...prev, index]
|
|
92
|
+
);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
if (isTranslating) {
|
|
96
|
+
return (
|
|
97
|
+
<div>
|
|
98
|
+
<div style={{ paddingLeft: pcStyles.pxMd.paddingLeft, paddingRight: pcStyles.pxMd.paddingRight, marginBottom: pcStyles.mbMd.marginBottom }}>
|
|
99
|
+
<div style={{ height: '1rem', width: '8rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary'), marginBottom: '0.375rem' }}></div>
|
|
100
|
+
{!isErasure && (
|
|
101
|
+
<div style={{ height: '1rem', width: '6rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
102
|
+
)}
|
|
103
|
+
</div>
|
|
104
|
+
{[1, 2, 3].map((skeletonIndex) => (
|
|
105
|
+
<div
|
|
106
|
+
key={skeletonIndex}
|
|
107
|
+
style={{
|
|
108
|
+
borderBottom: `1px solid ${getVar('--pc-border-color')}`,
|
|
109
|
+
backgroundColor: getVar('--pc-bg-secondary'),
|
|
110
|
+
borderRadius: pcStyles.borderRadiusMd,
|
|
111
|
+
overflow: 'hidden',
|
|
112
|
+
}}
|
|
113
|
+
>
|
|
114
|
+
<div style={{
|
|
115
|
+
...pcStyles.flex,
|
|
116
|
+
width: '100%',
|
|
117
|
+
...pcStyles.itemsCenter,
|
|
118
|
+
...pcStyles.justifyBetween,
|
|
119
|
+
padding: getVar('--pc-spacing-md'),
|
|
120
|
+
}}>
|
|
121
|
+
<div style={{ ...pcStyles.flex, ...pcStyles.itemsCenter, ...pcStyles.gapSm }}>
|
|
122
|
+
<div style={{ height: '1rem', width: '1rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
123
|
+
<div style={{ height: '1rem', width: '10rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
124
|
+
</div>
|
|
125
|
+
<div style={{ height: '1.25rem', width: '1.25rem', animation: 'pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite', borderRadius: pcStyles.borderRadiusMd, backgroundColor: getVar('--pc-bg-tertiary') }}></div>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
))}
|
|
129
|
+
</div>
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div>
|
|
135
|
+
<div style={{
|
|
136
|
+
paddingLeft: pcStyles.pxMd.paddingLeft,
|
|
137
|
+
paddingRight: pcStyles.pxMd.paddingRight,
|
|
138
|
+
marginBottom: pcStyles.mbMd.marginBottom
|
|
139
|
+
}}>
|
|
140
|
+
<p style={{
|
|
141
|
+
marginBottom: '0.375rem',
|
|
142
|
+
fontSize: pcStyles.textXs.fontSize,
|
|
143
|
+
color: getVar('--pc-text-secondary'),
|
|
144
|
+
}}>
|
|
145
|
+
{requestType === RequestTypeEnum.ACCESS
|
|
146
|
+
? t('whatDataToAccess')
|
|
147
|
+
: t('whatDataToDelete')}
|
|
148
|
+
</p>
|
|
149
|
+
{!isErasure && (
|
|
150
|
+
<PCCheckbox
|
|
151
|
+
label={t('selectAll')}
|
|
152
|
+
size="sm"
|
|
153
|
+
checked={selectAllChecked}
|
|
154
|
+
onChange={(e) => handleSelectAll(e.target.checked)}
|
|
155
|
+
style={{
|
|
156
|
+
accentColor: getVar('--pc-primary'),
|
|
157
|
+
}}
|
|
158
|
+
labelClassName="text-sm font-medium"
|
|
159
|
+
/>
|
|
160
|
+
)}
|
|
161
|
+
</div>
|
|
162
|
+
|
|
163
|
+
{purposes.map((item, index) => {
|
|
164
|
+
const isOpen = openIndexes.includes(index);
|
|
165
|
+
const areAllDataElementsSelected = item.data_elements.every(
|
|
166
|
+
(de) => de.selected
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<div
|
|
171
|
+
key={item.uuid}
|
|
172
|
+
style={{
|
|
173
|
+
borderBottom: `1px solid ${getVar('--pc-border-color')}`,
|
|
174
|
+
backgroundColor: getVar('--pc-bg-secondary'),
|
|
175
|
+
borderRadius: pcStyles.borderRadiusMd,
|
|
176
|
+
overflow: 'hidden',
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
<div style={{
|
|
180
|
+
...pcStyles.flex,
|
|
181
|
+
width: '100%',
|
|
182
|
+
...pcStyles.itemsCenter,
|
|
183
|
+
...pcStyles.justifyBetween,
|
|
184
|
+
padding: getVar('--pc-spacing-md'),
|
|
185
|
+
fontSize: pcStyles.textSm.fontSize,
|
|
186
|
+
fontWeight: pcStyles.fontWeightSemibold.fontWeight,
|
|
187
|
+
textTransform: 'capitalize',
|
|
188
|
+
color: getVar('--pc-text-primary'),
|
|
189
|
+
}}>
|
|
190
|
+
<PCCheckbox
|
|
191
|
+
size="sm"
|
|
192
|
+
labelClassName="text-sm font-medium capitalize"
|
|
193
|
+
checked={areAllDataElementsSelected}
|
|
194
|
+
label={item.name}
|
|
195
|
+
onChange={(e) => {
|
|
196
|
+
e.stopPropagation();
|
|
197
|
+
handlePurposeSelectAll(index, e.target.checked);
|
|
198
|
+
}}
|
|
199
|
+
onClick={(e) => e.stopPropagation()}
|
|
200
|
+
style={{
|
|
201
|
+
accentColor: getVar('--pc-primary'),
|
|
202
|
+
}}
|
|
203
|
+
/>
|
|
204
|
+
|
|
205
|
+
<button
|
|
206
|
+
type="button"
|
|
207
|
+
onClick={() => toggleAccordion(index)}
|
|
208
|
+
style={{
|
|
209
|
+
marginLeft: pcStyles.mLg.marginLeft,
|
|
210
|
+
color: getVar('--pc-text-secondary'),
|
|
211
|
+
background: 'none',
|
|
212
|
+
border: 'none',
|
|
213
|
+
cursor: 'pointer',
|
|
214
|
+
padding: 0,
|
|
215
|
+
flexShrink: 0,
|
|
216
|
+
}}
|
|
217
|
+
>
|
|
218
|
+
<ChevronDown
|
|
219
|
+
size={20}
|
|
220
|
+
style={{
|
|
221
|
+
transform: isOpen ? 'rotate(180deg)' : 'rotate(0deg)',
|
|
222
|
+
transition: 'transform 0.3s',
|
|
223
|
+
}}
|
|
224
|
+
/>
|
|
225
|
+
</button>
|
|
226
|
+
</div>
|
|
227
|
+
|
|
228
|
+
{isOpen && (
|
|
229
|
+
<div style={{
|
|
230
|
+
paddingTop: 0,
|
|
231
|
+
paddingLeft: getVar('--pc-spacing-2xl'),
|
|
232
|
+
paddingRight: getVar('--pc-spacing-md'),
|
|
233
|
+
paddingBottom: getVar('--pc-spacing-md'),
|
|
234
|
+
}} className="pc-padding-responsive">
|
|
235
|
+
{item.data_elements && item.data_elements.length > 0 ? (
|
|
236
|
+
<>
|
|
237
|
+
<p style={{
|
|
238
|
+
marginTop: getVar('--pc-spacing-sm'),
|
|
239
|
+
marginBottom: getVar('--pc-spacing-sm'),
|
|
240
|
+
fontSize: pcStyles.textSm.fontSize,
|
|
241
|
+
fontWeight: pcStyles.fontWeightMedium.fontWeight,
|
|
242
|
+
color: getVar('--pc-text-primary'),
|
|
243
|
+
}}>
|
|
244
|
+
{t('dataCollected')}
|
|
245
|
+
</p>
|
|
246
|
+
<div style={{
|
|
247
|
+
display: 'grid',
|
|
248
|
+
gridTemplateColumns: 'repeat(1, 1fr)',
|
|
249
|
+
gap: getVar('--pc-spacing-xs'),
|
|
250
|
+
}} className="pc-grid-responsive">
|
|
251
|
+
{item.data_elements
|
|
252
|
+
.filter((de: DataElement) => {
|
|
253
|
+
// For ACCESS and ERASURE, show all data elements regardless of given_consent
|
|
254
|
+
// The backend should handle consent validation
|
|
255
|
+
return de !== null && de !== undefined;
|
|
256
|
+
})
|
|
257
|
+
.map((de: DataElement, originalIndex: number) => {
|
|
258
|
+
// Find the original index in the unfiltered array for proper state updates
|
|
259
|
+
const actualIndex = item.data_elements.findIndex(
|
|
260
|
+
(el) => el.uuid === de.uuid
|
|
261
|
+
);
|
|
262
|
+
return (
|
|
263
|
+
<PCCheckbox
|
|
264
|
+
key={de.uuid}
|
|
265
|
+
size="sm"
|
|
266
|
+
checked={de.selected}
|
|
267
|
+
onChange={(e) =>
|
|
268
|
+
handleDataElementChange(e, index, actualIndex)
|
|
269
|
+
}
|
|
270
|
+
labelClassName="text-sm capitalize"
|
|
271
|
+
label={de.name}
|
|
272
|
+
style={{
|
|
273
|
+
accentColor: getVar('--pc-primary'),
|
|
274
|
+
}}
|
|
275
|
+
/>
|
|
276
|
+
);
|
|
277
|
+
})}
|
|
278
|
+
</div>
|
|
279
|
+
{item.data_elements.filter(
|
|
280
|
+
(de: DataElement) => de !== null && de !== undefined
|
|
281
|
+
).length === 0 && (
|
|
282
|
+
<p style={{
|
|
283
|
+
fontSize: pcStyles.textSm.fontSize,
|
|
284
|
+
color: getVar('--pc-text-secondary'),
|
|
285
|
+
}}>
|
|
286
|
+
{t('noDataElementsAvailable') || 'No data elements available'}
|
|
287
|
+
</p>
|
|
288
|
+
)}
|
|
289
|
+
</>
|
|
290
|
+
) : (
|
|
291
|
+
<p style={{
|
|
292
|
+
fontSize: pcStyles.textSm.fontSize,
|
|
293
|
+
color: getVar('--pc-text-secondary'),
|
|
294
|
+
}}>
|
|
295
|
+
{t('noDataElementsAvailable') || 'No data elements available'}
|
|
296
|
+
</p>
|
|
297
|
+
)}
|
|
298
|
+
</div>
|
|
299
|
+
)}
|
|
300
|
+
</div>
|
|
301
|
+
);
|
|
302
|
+
})}
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
}
|