diff --git a/interfaces/filters.ts b/interfaces/filters.ts index 03bb20c..06a78d7 100644 --- a/interfaces/filters.ts +++ b/interfaces/filters.ts @@ -9,5 +9,5 @@ export interface FiltersInterface { driver: DriverKeyType | ''; stage: StageKeyType | ''; coordinator: string; - string: string; + searchQuery: string; } diff --git a/src/contexts/DashboardContext.tsx b/src/contexts/DashboardContext.tsx index 9b4f9c1..e43a306 100644 --- a/src/contexts/DashboardContext.tsx +++ b/src/contexts/DashboardContext.tsx @@ -71,7 +71,7 @@ const defaultFilters: FiltersInterface = { driver: '', stage: 'submitted', coordinator: '', - string: '', + searchQuery: '', }; export const log: (message: string) => void = (message) => diff --git a/src/forms/AdvancedSearchForm/index.tsx b/src/forms/AdvancedSearchForm/index.tsx index 2f9a96c..9d04b1e 100644 --- a/src/forms/AdvancedSearchForm/index.tsx +++ b/src/forms/AdvancedSearchForm/index.tsx @@ -18,7 +18,7 @@ const AdvancedSearchForm: StyledComponent = styled( const [term, setTerm] = useState(''); const handleSearch = (e) => { setTerm(e.target.value); - setFilters({ ...filters, string: e.target.value }); + setFilters({ ...filters, searchQuery: e.target.value }); }; return ( diff --git a/src/pages/Dashboard/DonationsPage.tsx b/src/pages/Dashboard/DonationsPage.tsx index 2f17c84..c50eb68 100644 --- a/src/pages/Dashboard/DonationsPage.tsx +++ b/src/pages/Dashboard/DonationsPage.tsx @@ -21,7 +21,7 @@ const DonationsPage = () => { driver: '', stage: 'submitted', coordinator: '', - string: '', + searchQuery: '', }); const handler = (id?: string, shouldRefetch?: boolean): void => { setSelected(id); diff --git a/src/utils/filter-requests.ts b/src/utils/filter-requests.ts index a10e5de..7063ebb 100644 --- a/src/utils/filter-requests.ts +++ b/src/utils/filter-requests.ts @@ -7,14 +7,15 @@ const filterRequests = ( ) => { return Object.entries(requests).reduce((object, [id, request]) => { const { stage, location, language, driver, coordinator } = filters; - const string = filters.string?.toLowerCase().trim(); + const searchQuery = filters.searchQuery?.toLowerCase().trim(); return stage !== request.stage || (location && location !== request.location) || (language && language !== request.language) || (driver && driver !== request.driver) || - (string && - request.name.toLowerCase().trim().indexOf(string) && - request.email.toLowerCase().trim().indexOf(string)) || + (searchQuery && + request.name.toLowerCase().trim().indexOf(searchQuery) === -1 && + request.email.toLowerCase().trim().indexOf(searchQuery) === + -1) || (coordinator && coordinator !== request.coordinator) ? object : {