diff --git a/plugin-hrm-form/src/components/CustomCRMContainer.tsx b/plugin-hrm-form/src/components/CustomCRMContainer.tsx index eed6a563f1..5a80960284 100644 --- a/plugin-hrm-form/src/components/CustomCRMContainer.tsx +++ b/plugin-hrm-form/src/components/CustomCRMContainer.tsx @@ -35,6 +35,7 @@ import { createContactAsyncAction } from '../states/contacts/saveContact'; import { getAseloFeatureFlags, getHrmConfig } from '../hrmConfig'; import { newContact } from '../states/contacts/contactState'; import { selectAnyContactIsSaving } from '../states/contacts/selectContactSaveStatus'; +import selectCurrentOfflineContact from '../states/contacts/selectCurrentOfflineContact'; type OwnProps = { task?: ITask; @@ -127,9 +128,7 @@ const mapStateToProps = (state: RootState) => { } = state; const { selectedTaskSid } = flex.view; const { isAddingOfflineContact } = routing; - const currentOfflineContact = Object.values(activeContacts.existingContacts).find( - contact => contact.savedContact.taskId === getOfflineContactTaskSid(), - ); + const currentOfflineContact = selectCurrentOfflineContact(state); const hasUnsavedChanges = Object.values(activeContacts.existingContacts).some( ({ savedContact, draftContact }) => !_.isEqual(savedContact, getUnsavedContact(savedContact, draftContact)), diff --git a/plugin-hrm-form/src/states/contacts/selectCurrentOfflineContact.ts b/plugin-hrm-form/src/states/contacts/selectCurrentOfflineContact.ts new file mode 100644 index 0000000000..ae2594bd67 --- /dev/null +++ b/plugin-hrm-form/src/states/contacts/selectCurrentOfflineContact.ts @@ -0,0 +1,27 @@ +/** + * Copyright (C) 2021-2023 Technology Matters + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published + * by the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +import { RootState } from '..'; +import { namespace } from '../storeNamespaces'; +import getOfflineContactTaskSid from './offlineContactTaskSid'; +import { ContactState } from './existingContacts'; + +const selectCurrentOfflineContact = ({ [namespace]: { activeContacts } }: RootState): ContactState | undefined => + Object.values(activeContacts.existingContacts).find( + contact => contact.savedContact?.taskId === getOfflineContactTaskSid(), + ); + +export default selectCurrentOfflineContact;