From a8c7476028c6e9dece5735715cee604fd00209f8 Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Thu, 26 Sep 2024 21:19:16 +0530 Subject: [PATCH 1/2] fixed add to collections --- .../CollectionContactList.tsx | 77 +++---------------- .../GroupCollectionList.test.tsx | 2 +- .../GroupCollections/GroupCollectionList.tsx | 68 +++------------- 3 files changed, 24 insertions(+), 123 deletions(-) diff --git a/src/containers/Collection/CollectionContact/CollectionContactList/CollectionContactList.tsx b/src/containers/Collection/CollectionContact/CollectionContactList/CollectionContactList.tsx index c7b5fc0be..601e9a3e1 100644 --- a/src/containers/Collection/CollectionContact/CollectionContactList/CollectionContactList.tsx +++ b/src/containers/Collection/CollectionContact/CollectionContactList/CollectionContactList.tsx @@ -1,25 +1,20 @@ -import { useEffect, useState } from 'react'; +import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useParams } from 'react-router-dom'; -import { - CONTACT_SEARCH_QUERY, - GET_CONTACTS_LIST, - GET_CONTACT_COUNT, -} from 'graphql/queries/Contact'; +import { CONTACT_SEARCH_QUERY, GET_CONTACT_COUNT } from 'graphql/queries/Contact'; import { UPDATE_COLLECTION_CONTACTS } from 'graphql/mutations/Collection'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; import DeleteIcon from 'assets/images/icons/Delete/Red.svg?react'; import CollectionIcon from 'assets/images/icons/Collection/Dark.svg?react'; import { List } from 'containers/List/List'; import styles from './CollectionContactList.module.css'; -import { useLazyQuery, useMutation } from '@apollo/client'; -import { setVariables } from 'common/constants'; -import { SearchDialogBox } from 'components/UI/SearchDialogBox/SearchDialogBox'; +import { useMutation } from '@apollo/client'; import { Button } from 'components/UI/Form/Button/Button'; import { getContactStatus, getDisplayName } from 'common/utils'; import { DialogBox } from 'components/UI/DialogBox/DialogBox'; import { setNotification } from 'common/notification'; +import AddToCollection from 'containers/Chat/ChatMessages/AddToCollection/AddToCollection'; export interface CollectionContactListProps { title: string; @@ -72,10 +67,9 @@ export const CollectionContactList = ({ }: CollectionContactListProps) => { const [addContactsDialogShow, setAddContactsDialogShow] = useState(false); const [removeContactsDialogShow, setRemoveContactsDialogShow] = useState(false); - const [contactSearchTerm, setContactSearchTerm] = useState(''); const [selectedContacts, setSelectedContact] = useState([]); const [contactsToRemove, setContactsToRemove] = useState([]); - const [contactOptions, setContactOptions] = useState([]); + const [updateCollection, setUpdateCollection] = useState(false); const { t } = useTranslation(); const params = useParams(); @@ -83,32 +77,8 @@ export const CollectionContactList = ({ const collectionId = params.id; let dialog; - const [getContacts, { data: contactsData }] = useLazyQuery(GET_CONTACTS_LIST, { - fetchPolicy: 'cache-and-network', - }); - const [updateCollectionContacts] = useMutation(UPDATE_COLLECTION_CONTACTS); - const handleCollectionAdd = (selectedContacts: any) => { - if (selectedContacts.length === 0) { - setAddContactsDialogShow(false); - } else { - updateCollectionContacts({ - variables: { - input: { - addContactIds: selectedContacts, - groupId: collectionId, - deleteContactIds: [], - }, - }, - onCompleted: () => { - setNotification(t('Contact has been added successfully to the collection.'), 'success'); - }, - }); - } - setAddContactsDialogShow(false); - }; - const handleCollectionRemove = () => { const idsToRemove = selectedContacts.map((collection: any) => collection.id); updateCollectionContacts({ @@ -121,6 +91,7 @@ export const CollectionContactList = ({ }, onCompleted: () => { setNotification(t('Contact has been removed successfully from the collection.'), 'success'); + setUpdateCollection(!updateCollection); }, }); setRemoveContactsDialogShow(false); @@ -132,36 +103,14 @@ export const CollectionContactList = ({ setSelectedContact(selectedContacts); }; - useEffect(() => { - if (contactsData) { - setContactOptions(contactsData.contacts); - } - }, [contactsData]); - if (addContactsDialogShow) { dialog = ( - setAddContactsDialogShow(false)} - options={contactOptions} - optionLabel="name" - additionalOptionLabel="phone" - asyncSearch - colorOk="primary" - buttonOk="Add" - disableClearable - searchLabel="Search contacts" - textFieldPlaceholder="Type here" - onChange={(value: any) => { - if (typeof value === 'string') { - setContactSearchTerm(value); - } + { + setUpdateCollection(!updateCollection); }} - selectedOptions={[]} - fullWidth={true} - showTags={false} - placeholder="Select contacts" /> ); } @@ -193,9 +142,6 @@ export const CollectionContactList = ({ color="primary" data-testid="addBtn" onClick={() => { - getContacts({ - variables: setVariables({ name: contactSearchTerm, excludeGroups: collectionId }, 50), - }); setAddContactsDialogShow(true); }} > @@ -245,6 +191,7 @@ export const CollectionContactList = ({ }} {...queries} {...columnAttributes} + refreshList={updateCollection} /> ); diff --git a/src/containers/WaGroups/GroupCollections/GroupCollectionList.test.tsx b/src/containers/WaGroups/GroupCollections/GroupCollectionList.test.tsx index 40d6a5646..a4c733e66 100644 --- a/src/containers/WaGroups/GroupCollections/GroupCollectionList.test.tsx +++ b/src/containers/WaGroups/GroupCollections/GroupCollectionList.test.tsx @@ -32,7 +32,7 @@ const mocks = [ countGroups, getGroupsCollectionList(getCollectionsVariables), getGroupsCollectionList(getCollectionsVariables), - getGroupsSearchQuery(setVariables({ excludeGroups: '1' }, 50)), + getGroupsSearchQuery(setVariables({ excludeGroups: '1', term: '' }, 50)), getGroupsSearchQuery(setVariables({ excludeGroups: '1' }, 50)), updateCollectionWaGroupQuery({ input: { addWaGroupIds: ['1'], groupId: '1', deleteWaGroupIds: [] }, diff --git a/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx b/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx index 24bd73d22..acc2a9b4a 100644 --- a/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx +++ b/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx @@ -13,13 +13,12 @@ import { List } from 'containers/List/List'; import styles from './GroupCollectionList.module.css'; import { GET_COLLECTION, GROUP_GET_COLLECTION } from 'graphql/queries/Collection'; -import { useLazyQuery, useMutation, useQuery } from '@apollo/client'; +import { useMutation, useQuery } from '@apollo/client'; import { useState } from 'react'; -import { setVariables } from 'common/constants'; import { setNotification } from 'common/notification'; -import { SearchDialogBox } from 'components/UI/SearchDialogBox/SearchDialogBox'; import { Button } from 'components/UI/Form/Button/Button'; import { DialogBox } from 'components/UI/DialogBox/DialogBox'; +import AddToCollection from 'containers/Chat/ChatMessages/AddToCollection/AddToCollection'; const getName = (label: string) => (
@@ -51,9 +50,9 @@ const columnAttributes = { export const GroupCollectionList = () => { const [addGroupsDialogShow, setAddGroupsDialogShow] = useState(false); const [removeGroupsDialogShow, setRemoveGroupsDialogShow] = useState(false); - const [groupSearchTerm, setGroupSearchTerm] = useState(''); const [selectedGroups, setSelectedGroup] = useState([]); const [groupsToRemove, setGroupsToRemove] = useState([]); + const [updateCollection, setUpdateCollection] = useState(false); const { t } = useTranslation(); const params = useParams(); @@ -63,32 +62,8 @@ export const GroupCollectionList = () => { fetchPolicy: 'cache-and-network', }); - const [getGroups, { data: groupsData }] = useLazyQuery(GET_WA_GROUPS, { - fetchPolicy: 'cache-and-network', - }); - const [updateCollectionGroups] = useMutation(UPDATE_COLLECTION_WA_GROUP); - const handleCollectionAdd = (selectedGroups: any) => { - if (selectedGroups.length === 0) { - setAddGroupsDialogShow(false); - } else { - updateCollectionGroups({ - variables: { - input: { - addWaGroupIds: selectedGroups, - groupId: collectionId, - deleteWaGroupIds: [], - }, - }, - onCompleted: () => { - setNotification(t('Group has been added successfully to the collection.'), 'success'); - }, - }); - } - setAddGroupsDialogShow(false); - }; - const handleCollectionRemove = () => { const idsToRemove = selectedGroups.map((collection: any) => collection.id); updateCollectionGroups({ @@ -101,6 +76,7 @@ export const GroupCollectionList = () => { }, onCompleted: () => { setNotification(t('Group has been removed successfully from the collection.'), 'success'); + setUpdateCollection(!updateCollection); }, }); setRemoveGroupsDialogShow(false); @@ -115,34 +91,14 @@ export const GroupCollectionList = () => { let dialog; if (addGroupsDialogShow) { - let groupsOptions: any = []; - if (groupsData) { - groupsOptions = groupsData.waGroups; - } - dialog = ( - setAddGroupsDialogShow(false)} - options={groupsOptions} - optionLabel="name" - additionalOptionLabel="phone" - asyncSearch - colorOk="primary" - buttonOk="Add" - disableClearable={true} - searchLabel="Search groups" - textFieldPlaceholder="Type here" - onChange={(value: any) => { - if (typeof value === 'string') { - setGroupSearchTerm(value); - } + { + setUpdateCollection(!updateCollection); }} - selectedOptions={[]} - fullWidth={true} - showTags={false} - placeholder="Select groups" /> ); } @@ -153,9 +109,6 @@ export const GroupCollectionList = () => { color="primary" data-testid="addBtn" onClick={() => { - getGroups({ - variables: setVariables({ excludeGroups: collectionId }, 50), - }); setAddGroupsDialogShow(true); }} > @@ -223,6 +176,7 @@ export const GroupCollectionList = () => { }} {...queries} {...columnAttributes} + refreshList={updateCollection} /> ); From d1c7480aa539bfe20f9c6ad1ff137cc58293746b Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Thu, 26 Sep 2024 21:30:23 +0530 Subject: [PATCH 2/2] deepscan fixes --- .../WaGroups/GroupCollections/GroupCollectionList.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx b/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx index acc2a9b4a..7417e6629 100644 --- a/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx +++ b/src/containers/WaGroups/GroupCollections/GroupCollectionList.tsx @@ -1,7 +1,7 @@ import { useTranslation } from 'react-i18next'; import { useParams } from 'react-router-dom'; -import { GET_GROUP_COUNT, GET_WA_GROUPS } from 'graphql/queries/WaGroups'; +import { GET_GROUP_COUNT } from 'graphql/queries/WaGroups'; import { UPDATE_COLLECTION_WA_GROUP, UPDATE_WA_GROUP_COLLECTION, @@ -93,7 +93,7 @@ export const GroupCollectionList = () => { if (addGroupsDialogShow) { dialog = ( {