@@ -7,21 +7,18 @@ import {
77 Pagination ,
88 Skeleton ,
99 Spin ,
10- useMessage ,
1110} from "fidesui" ;
1211import React , { useEffect , useMemo } from "react" ;
1312
1413import { BulkActionsDropdown } from "~/features/common/BulkActionsDropdown" ;
1514import { useSelection } from "~/features/common/hooks/useSelection" ;
1615import { ResultsSelectedCount } from "~/features/common/ResultsSelectedCount" ;
17- import {
18- useLazyDownloadPrivacyRequestCsvV2Query ,
19- useSearchPrivacyRequestsQuery ,
20- } from "~/features/privacy-requests/privacy-requests.slice" ;
16+ import { useSearchPrivacyRequestsQuery } from "~/features/privacy-requests/privacy-requests.slice" ;
2117import { PrivacyRequestResponse } from "~/types/api" ;
2218
2319import { useAntPagination } from "../../common/pagination/useAntPagination" ;
2420import { DuplicateRequestsButton } from "./DuplicateRequestsButton" ;
21+ import useDownloadPrivacyRequestReport from "./hooks/useDownloadPrivacyRequestReport" ;
2522import { usePrivacyRequestBulkActions } from "./hooks/usePrivacyRequestBulkActions" ;
2623import usePrivacyRequestsFilters from "./hooks/usePrivacyRequestsFilters" ;
2724import { ListItem } from "./list-item/ListItem" ;
@@ -34,8 +31,6 @@ export const PrivacyRequestsDashboard = () => {
3431 pagination,
3532 } ) ;
3633
37- const messageApi = useMessage ( ) ;
38-
3934 const { data, isLoading, isFetching, refetch } =
4035 useSearchPrivacyRequestsQuery ( {
4136 ...filterQueryParams ,
@@ -70,23 +65,8 @@ export const PrivacyRequestsDashboard = () => {
7065 clearSelectedIds ( ) ;
7166 } , [ requests , clearSelectedIds ] ) ;
7267
73- const [ downloadReport ] = useLazyDownloadPrivacyRequestCsvV2Query ( ) ;
74-
75- const handleExport = async ( ) => {
76- let messageStr ;
77- try {
78- await downloadReport ( filterQueryParams ) ;
79- } catch ( error ) {
80- if ( error instanceof Error ) {
81- messageStr = error . message ;
82- } else {
83- messageStr = "Unknown error occurred" ;
84- }
85- }
86- if ( messageStr ) {
87- messageApi . error ( messageStr , 5000 ) ;
88- }
89- } ;
68+ const { downloadReport, isDownloadingReport } =
69+ useDownloadPrivacyRequestReport ( ) ;
9070
9171 const { bulkActionMenuItems } = usePrivacyRequestBulkActions ( {
9272 requests,
@@ -143,7 +123,8 @@ export const PrivacyRequestsDashboard = () => {
143123 aria-label = "Export report"
144124 data-testid = "export-btn"
145125 icon = { < Icons . Download /> }
146- onClick = { handleExport }
126+ onClick = { ( ) => downloadReport ( filterQueryParams ) }
127+ loading = { isDownloadingReport }
147128 />
148129 </ Flex >
149130 </ Flex >
0 commit comments