|
| 1 | +import { getCoreRowModel, useReactTable } from "@tanstack/react-table"; |
1 | 2 | import {
|
2 |
| - AntFlex as Flex, |
3 | 3 | AntForm as Form,
|
4 | 4 | AntInput as Input,
|
5 | 5 | AntTypography as Typography,
|
6 |
| - Button, |
7 | 6 | Modal,
|
8 | 7 | ModalBody,
|
9 | 8 | ModalCloseButton,
|
10 | 9 | ModalContent,
|
11 | 10 | ModalHeader,
|
12 | 11 | ModalOverlay,
|
| 12 | + useToast, |
13 | 13 | } from "fidesui";
|
14 | 14 | import { useState } from "react";
|
15 | 15 |
|
| 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 | + |
16 | 23 | interface ConsentLookupModalProps {
|
17 | 24 | isOpen: boolean;
|
18 | 25 | onClose: () => void;
|
19 | 26 | }
|
20 | 27 |
|
21 | 28 | 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(); |
23 | 37 |
|
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); |
26 | 54 | };
|
27 | 55 |
|
| 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 | + |
28 | 65 | return (
|
29 | 66 | <Modal
|
30 | 67 | id="custom-field-modal-hello-world"
|
@@ -58,9 +95,15 @@ const ConsentLookupModal = ({ isOpen, onClose }: ConsentLookupModalProps) => {
|
58 | 95 | placeholder="Enter email, phone number, or device ID"
|
59 | 96 | enterButton="Search"
|
60 | 97 | onSearch={handleSearch}
|
| 98 | + loading={isSearching} |
61 | 99 | />
|
62 | 100 | </Form.Item>
|
63 | 101 | </Form>
|
| 102 | + <div className="mb-4"> |
| 103 | + <FidesTableV2<PreferenceWithNoticeInformation> |
| 104 | + tableInstance={tableInstance} |
| 105 | + /> |
| 106 | + </div> |
64 | 107 | </ModalBody>
|
65 | 108 | </ModalContent>
|
66 | 109 | </Modal>
|
|
0 commit comments