Skip to content

Commit bdde4c7

Browse files
committed
Add privacy preference lookup functionality
1 parent fa0ef42 commit bdde4c7

File tree

4 files changed

+111
-9
lines changed

4 files changed

+111
-9
lines changed

clients/admin-ui/src/features/common/api.slice.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export const baseApi = createApi({
2525
"Classify Instances Systems",
2626
"Connection Type",
2727
"Consentable Items",
28+
"Consent Reporting",
29+
"Consent Reporting Export",
30+
"Current Privacy Preferences",
2831
"Custom Assets",
2932
"Custom Field Definition",
3033
"Custom Fields",
@@ -66,8 +69,6 @@ export const baseApi = createApi({
6669
"User",
6770
"Configuration Settings",
6871
"TCF Purpose Override",
69-
"Consent Reporting",
70-
"Consent Reporting Export",
7172
"OpenID Provider",
7273
],
7374
endpoints: () => ({}),

clients/admin-ui/src/features/consent-reporting/ConsentLookupModal.tsx

+48-5
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,67 @@
1+
import { getCoreRowModel, useReactTable } from "@tanstack/react-table";
12
import {
2-
AntFlex as Flex,
33
AntForm as Form,
44
AntInput as Input,
55
AntTypography as Typography,
6-
Button,
76
Modal,
87
ModalBody,
98
ModalCloseButton,
109
ModalContent,
1110
ModalHeader,
1211
ModalOverlay,
12+
useToast,
1313
} from "fidesui";
1414
import { useState } from "react";
1515

16+
import { PreferenceWithNoticeInformation } from "~/types/api";
17+
18+
import { getErrorMessage } from "../common/helpers";
19+
import { FidesTableV2 } from "../common/table/v2";
20+
import { useLazyGetCurrentPrivacyPreferencesQuery } from "./consent-reporting.slice";
21+
import useConsentLookupTableColumns from "./hooks/useConsentLookupTableColumns";
22+
1623
interface ConsentLookupModalProps {
1724
isOpen: boolean;
1825
onClose: () => void;
1926
}
2027

2128
const ConsentLookupModal = ({ isOpen, onClose }: ConsentLookupModalProps) => {
22-
const [showModal, setShowModal] = useState(false);
29+
const [isSearching, setIsSearching] = useState(false);
30+
const [searchResults, setSearchResults] = useState<
31+
PreferenceWithNoticeInformation[]
32+
>([]);
33+
const [getCurrentPrivacyPreferencesTrigger] =
34+
useLazyGetCurrentPrivacyPreferencesQuery();
35+
36+
const toast = useToast();
2337

24-
const handleSearch = (value: string) => {
25-
console.log("value", value);
38+
const handleSearch = async (search: string) => {
39+
setIsSearching(true);
40+
const { data, isError, error } = await getCurrentPrivacyPreferencesTrigger({
41+
search,
42+
});
43+
if (isError) {
44+
const errorMsg = getErrorMessage(
45+
error,
46+
`A problem occurred while looking up the preferences.`,
47+
);
48+
49+
toast({ status: "error", description: errorMsg });
50+
} else {
51+
setSearchResults(data?.preferences || []);
52+
}
53+
setIsSearching(false);
2654
};
2755

56+
const columns = useConsentLookupTableColumns();
57+
const tableInstance = useReactTable<PreferenceWithNoticeInformation>({
58+
getCoreRowModel: getCoreRowModel(),
59+
data: searchResults,
60+
columns,
61+
getRowId: (row) => `${row.privacy_notice_history_id}`,
62+
manualPagination: true,
63+
});
64+
2865
return (
2966
<Modal
3067
id="custom-field-modal-hello-world"
@@ -58,9 +95,15 @@ const ConsentLookupModal = ({ isOpen, onClose }: ConsentLookupModalProps) => {
5895
placeholder="Enter email, phone number, or device ID"
5996
enterButton="Search"
6097
onSearch={handleSearch}
98+
loading={isSearching}
6199
/>
62100
</Form.Item>
63101
</Form>
102+
<div className="mb-4">
103+
<FidesTableV2<PreferenceWithNoticeInformation>
104+
tableInstance={tableInstance}
105+
/>
106+
</div>
64107
</ModalBody>
65108
</ModalContent>
66109
</Modal>

clients/admin-ui/src/features/consent-reporting/consent-reporting.slice.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { baseApi } from "~/features/common/api.slice";
2-
import { Page_ConsentReportingSchema_ } from "~/types/api";
2+
import { Page_ConsentReportingSchema_, PreferencesSaved } from "~/types/api";
33

44
type DateRange = {
55
startDate?: string;
@@ -30,7 +30,20 @@ export function convertDateRangeToSearchParams({
3030

3131
export const consentReportingApi = baseApi.injectEndpoints({
3232
endpoints: (build) => ({
33-
downloadReport: build.query<any, DateRange>({
33+
getCurrentPrivacyPreferences: build.query<any, { search: string }>({
34+
query: ({ search }) => ({
35+
url: "current-privacy-preferences",
36+
params: {
37+
email: search,
38+
phone_number: search,
39+
fides_user_device_id: search,
40+
external_id: search,
41+
},
42+
}),
43+
providesTags: ["Current Privacy Preferences"],
44+
}),
45+
46+
downloadReport: build.query<PreferencesSaved, DateRange>({
3447
query: ({ startDate, endDate }) => {
3548
const params = {
3649
...convertDateRangeToSearchParams({ startDate, endDate }),
@@ -63,4 +76,5 @@ export const consentReportingApi = baseApi.injectEndpoints({
6376
export const {
6477
useLazyDownloadReportQuery,
6578
useGetAllHistoricalPrivacyPreferencesQuery,
79+
useLazyGetCurrentPrivacyPreferencesQuery,
6680
} = consentReportingApi;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { createColumnHelper } from "@tanstack/react-table";
2+
import { useMemo } from "react";
3+
4+
import { DefaultCell, DefaultHeaderCell } from "~/features/common/table/v2";
5+
import { PreferenceWithNoticeInformation } from "~/types/api";
6+
7+
const columnHelper = createColumnHelper<PreferenceWithNoticeInformation>();
8+
9+
const useConsentLookupTableColumns = () => {
10+
const columns = useMemo(
11+
() => [
12+
columnHelper.accessor((row) => row.notice_id, {
13+
id: "notice_id",
14+
cell: ({ getValue }) => <DefaultCell value={getValue()} />,
15+
header: (props) => <DefaultHeaderCell value="Notice Id" {...props} />,
16+
enableSorting: false,
17+
}),
18+
columnHelper.accessor((row) => row.notice_key, {
19+
id: "notice_key",
20+
cell: ({ getValue }) => <DefaultCell value={getValue()} />,
21+
header: (props) => <DefaultHeaderCell value="Notice Key" {...props} />,
22+
enableSorting: false,
23+
}),
24+
columnHelper.accessor((row) => row.preference, {
25+
id: "preference",
26+
cell: ({ getValue }) => <DefaultCell value={getValue()} />,
27+
header: (props) => <DefaultHeaderCell value="Preference" {...props} />,
28+
enableSorting: false,
29+
}),
30+
columnHelper.accessor((row) => row.privacy_notice_history_id, {
31+
id: "privacy_notice_history_id",
32+
cell: ({ getValue }) => <DefaultCell value={getValue()} />,
33+
header: (props) => (
34+
<DefaultHeaderCell value="Privacy Notice History Id" {...props} />
35+
),
36+
enableSorting: false,
37+
}),
38+
],
39+
[],
40+
);
41+
42+
return columns;
43+
};
44+
export default useConsentLookupTableColumns;

0 commit comments

Comments
 (0)