From 667d72279e59f9101fa3240b659018393ef8bda3 Mon Sep 17 00:00:00 2001 From: Mintu Date: Fri, 8 Dec 2023 22:55:42 +0530 Subject: [PATCH] Single search modal --- public/locales/en.json | 3 +- .../OrganizationPeople/OrganizationPeople.tsx | 56 +++++++------------ 2 files changed, 22 insertions(+), 37 deletions(-) diff --git a/public/locales/en.json b/public/locales/en.json index 72ad23c5cb..8527dc97b4 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -200,8 +200,7 @@ "users": "Users", "searchName": "Enter Name", "searchevent": "Enter Event", - "searchFirstName": "Enter First Name", - "searchLastName": "Enter Last Name" + "searchFullName": "Enter Full Name" }, "userListCard": { "joined": "Joined", diff --git a/src/screens/OrganizationPeople/OrganizationPeople.tsx b/src/screens/OrganizationPeople/OrganizationPeople.tsx index 9d33ae2833..f58211ddae 100644 --- a/src/screens/OrganizationPeople/OrganizationPeople.tsx +++ b/src/screens/OrganizationPeople/OrganizationPeople.tsx @@ -39,6 +39,8 @@ function organizationPeople(): JSX.Element { lastName_contains: '', }); + const [fullName, setFullName] = useState(''); + const { data: memberData, loading: memberLoading, @@ -104,22 +106,31 @@ function organizationPeople(): JSX.Element { } /* istanbul ignore next */ - const handleFirstNameSearchChange = (filterData: any): void => { + const handleFullNameSearchChange = (fullName: string): void => { /* istanbul ignore next */ + const [firstName, lastName] = fullName.split(' '); + + const newFilterData = { + firstName_contains: firstName ?? '', + lastName_contains: lastName ?? '', + }; + + setFilterData(newFilterData); + if (state === 0) { memberRefetch({ - ...filterData, + ...newFilterData, orgId: currentUrl, }); } else if (state === 1) { adminRefetch({ - ...filterData, + ...newFilterData, orgId: currentUrl, admin_for: currentUrl, }); } else { usersRefetch({ - ...filterData, + ...newFilterData, }); } }; @@ -140,8 +151,8 @@ function organizationPeople(): JSX.Element { setPage(0); }; - const debouncedHandleFirstNameSearchChange = debounce( - handleFirstNameSearchChange + const debouncedHandleFullNameSearchChange = debounce( + handleFullNameSearchChange ); return ( @@ -152,42 +163,17 @@ function organizationPeople(): JSX.Element {
{t('filterByName')}
- { - const { value } = e.target; - - const newFilterData = { - ...filterData, - firstName_contains: value?.trim(), - }; - - setFilterData(newFilterData); - debouncedHandleFirstNameSearchChange(newFilterData); - }} - /> { const { value } = e.target; - - const newFilterData = { - ...filterData, - lastName_contains: value?.trim(), - }; - - setFilterData(newFilterData); - debouncedHandleFirstNameSearchChange(newFilterData); + setFullName(value); + debouncedHandleFullNameSearchChange(value); }} />