Skip to content

Commit

Permalink
feat: filter search name and updated expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jadeallencook committed Dec 1, 2023
1 parent 9d0395e commit 6b082e6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion interfaces/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export interface FiltersInterface {
driver: DriverKeyType | '';
stage: StageKeyType | '';
coordinator: string;
string: string;
searchQuery: string;
}
2 changes: 1 addition & 1 deletion src/contexts/DashboardContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const defaultFilters: FiltersInterface = {
driver: '',
stage: 'submitted',
coordinator: '',
string: '',
searchQuery: '',
};

export const log: (message: string) => void = (message) =>
Expand Down
2 changes: 1 addition & 1 deletion src/forms/AdvancedSearchForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const AdvancedSearchForm: StyledComponent = styled(
const [term, setTerm] = useState<string>('');
const handleSearch = (e) => {
setTerm(e.target.value);
setFilters({ ...filters, string: e.target.value });
setFilters({ ...filters, searchQuery: e.target.value });
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Dashboard/DonationsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DonationsPage = () => {
driver: '',
stage: 'submitted',
coordinator: '',
string: '',
searchQuery: '',
});
const handler = (id?: string, shouldRefetch?: boolean): void => {
setSelected(id);
Expand Down
9 changes: 5 additions & 4 deletions src/utils/filter-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
: {
Expand Down

0 comments on commit 6b082e6

Please sign in to comment.