From 75b427ec8e7edb3a04e3f6ed1b483840ecbb4cea Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Sun, 8 Sep 2024 18:47:53 +0530 Subject: [PATCH 1/7] fixed multiple profile --- src/containers/Form/FormLayout.tsx | 8 +++++++- .../Profile/Contact/ContactProfile.tsx | 4 +--- src/containers/Profile/Profile.tsx | 14 ++++++-------- src/graphql/queries/Contact.ts | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/containers/Form/FormLayout.tsx b/src/containers/Form/FormLayout.tsx index bb3b2769a..327740452 100644 --- a/src/containers/Form/FormLayout.tsx +++ b/src/containers/Form/FormLayout.tsx @@ -179,6 +179,12 @@ export const FormLayout = ({ } }, [advanceSearch]); + useEffect(() => { + if (entityId) { + refetch(); + } + }, [entityId]); + const capitalListItemName = listItemName[0].toUpperCase() + listItemName.slice(1); let item: any = null; @@ -221,7 +227,7 @@ export const FormLayout = ({ variables = params.type ? { shortcode: params.type } : false; } - const { loading, error } = useQuery(getItemQuery, { + const { loading, error, refetch } = useQuery(getItemQuery, { variables, skip: !itemId, fetchPolicy: getQueryFetchPolicy, diff --git a/src/containers/Profile/Contact/ContactProfile.tsx b/src/containers/Profile/Contact/ContactProfile.tsx index 2662793a2..2c0956593 100644 --- a/src/containers/Profile/Contact/ContactProfile.tsx +++ b/src/containers/Profile/Contact/ContactProfile.tsx @@ -23,12 +23,10 @@ export const ContactProfile = () => { const [showProfileSection, setShowProfileSection] = useState('profile'); const { t } = useTranslation(); - const isContactProfileEnabled = getOrganizationServices('contactProfileEnabled'); const { loading, data } = useQuery(GET_CONTACT_DETAILS, { variables: { id: params.id } }); const { loading: profileLoading, data: profileData } = useQuery(GET_CONTACT_PROFILES, { variables: { filter: { contactId: params.id } }, - skip: !isContactProfileEnabled, fetchPolicy: 'network-only', }); @@ -54,7 +52,7 @@ export const ContactProfile = () => { let selectedProfile; - if (isContactProfileEnabled && profileData && profileData.profiles.length > 0) { + if (profileData && profileData.profiles.length > 0) { selectedProfile = profileData.profiles.filter( (profile: any) => profile.id === selectedProfileId ); diff --git a/src/containers/Profile/Profile.tsx b/src/containers/Profile/Profile.tsx index 5f78fab6c..88c57c376 100644 --- a/src/containers/Profile/Profile.tsx +++ b/src/containers/Profile/Profile.tsx @@ -9,7 +9,7 @@ import { CONTACT_STATUS, PROVIDER_STATUS } from 'common/constants'; import { FormLayout } from 'containers/Form/FormLayout'; import { Input } from 'components/UI/Form/Input/Input'; import { Loading } from 'components/UI/Layout/Loading/Loading'; -import { GET_CONTACT } from 'graphql/queries/Contact'; +import { GET_CONTACT, GET_PROFILE } from 'graphql/queries/Contact'; import { CREATE_CONTACT, UPDATE_CONTACT, @@ -17,7 +17,6 @@ import { DELETE_CONTACT_PROFILE, } from 'graphql/mutations/Contact'; import { GET_CURRENT_USER } from 'graphql/queries/User'; -import { getOrganizationServices } from 'services/AuthService'; import { getDisplayName, isSimulator } from 'common/utils'; import { AutoComplete } from 'components/UI/Form/AutoComplete/AutoComplete'; @@ -43,11 +42,10 @@ export const Profile = ({ const [languageId, setLanguageId] = useState(''); const [hideRemoveBtn, setHideRemoveBtn] = useState(false); const { t } = useTranslation(); - const isContactProfileEnabled = getOrganizationServices('contactProfileEnabled'); const hasMultipleProfiles = multiProfileAttributes?.selectedProfile; const queries = { - getItemQuery: GET_CONTACT, + getItemQuery: hasMultipleProfiles ? GET_PROFILE : GET_CONTACT, createItemQuery: CREATE_CONTACT, updateItemQuery: UPDATE_CONTACT, deleteItemQuery: hasMultipleProfiles ? DELETE_CONTACT_PROFILE : DELETE_CONTACT, @@ -58,16 +56,16 @@ export const Profile = ({ const { data, loading } = useQuery(GET_CURRENT_USER); const updateName = () => { - if (!isContactProfileEnabled || !hasMultipleProfiles) { + if (!hasMultipleProfiles) { return; } - const { selectedProfile } = multiProfileAttributes; + const { selectedProfile, selectedProfileId } = multiProfileAttributes; if (!selectedProfile) { return; } - if (selectedProfile.id === multiProfileAttributes.activeProfileId) { + if (selectedProfileId === multiProfileAttributes.activeProfileId) { setName(`${selectedProfile.name} (currently active)`); } else { setName(selectedProfile.name); @@ -199,7 +197,7 @@ export const Profile = ({ dialogMessage={dialogMessage} formFields={formFields} redirectionLink={redirectionLink} - listItem="contact" + listItem={hasMultipleProfiles ? 'profile' : 'contact'} icon={profileIcon} afterDelete={afterDelete} type={type} diff --git a/src/graphql/queries/Contact.ts b/src/graphql/queries/Contact.ts index 498e99c2e..c5ea5196b 100644 --- a/src/graphql/queries/Contact.ts +++ b/src/graphql/queries/Contact.ts @@ -172,3 +172,20 @@ export const GET_CONTACT_PROFILES = gql` } } `; + +export const GET_PROFILE = gql` + query getContact($id: ID!) { + profile(id: $id) { + profile { + id + name + fields + type + language { + label + id + } + } + } + } +`; From 5764119608ccae758a151bb328d43d02ce2bf9f2 Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Sun, 8 Sep 2024 19:02:06 +0530 Subject: [PATCH 2/7] fixed test cases --- .../Profile/Contact/ContactProfile.test.tsx | 5 +--- .../Profile/Contact/ContactProfile.tsx | 1 - src/mocks/Contact.tsx | 28 +++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/containers/Profile/Contact/ContactProfile.test.tsx b/src/containers/Profile/Contact/ContactProfile.test.tsx index 83d453d49..346562a0d 100644 --- a/src/containers/Profile/Contact/ContactProfile.test.tsx +++ b/src/containers/Profile/Contact/ContactProfile.test.tsx @@ -28,9 +28,6 @@ describe('contact profile', () => { test('contact profile should render', async () => { const { getByText, getAllByRole } = render(contactProfile); - await waitFor(() => { - expect(getByText('Profile')).toBeInTheDocument(); - }); await waitFor(() => { expect(getByText('Loading...')).toBeInTheDocument(); @@ -42,7 +39,7 @@ describe('contact profile', () => { // shows N/A when no name await waitFor(() => { - expect(getAllByRole('textbox')[0]).toHaveValue('N/A'); + expect(getAllByRole('textbox')[0]).toHaveValue('profile name 2'); }); }); }); diff --git a/src/containers/Profile/Contact/ContactProfile.tsx b/src/containers/Profile/Contact/ContactProfile.tsx index 2c0956593..211b9ee38 100644 --- a/src/containers/Profile/Contact/ContactProfile.tsx +++ b/src/containers/Profile/Contact/ContactProfile.tsx @@ -7,7 +7,6 @@ import { useTranslation } from 'react-i18next'; import CollapseIcon from '../../../assets/images/icons/Collapse.svg?react'; import ExpandIcon from '../../../assets/images/icons/Expand.svg?react'; import { getContactStatus, getDisplayName } from 'common/utils'; -import { getOrganizationServices } from 'services/AuthService'; import { GET_CONTACT_DETAILS, GET_CONTACT_PROFILES } from 'graphql/queries/Contact'; import { Loading } from 'components/UI/Layout/Loading/Loading'; import { AvatarDisplay } from 'components/UI/AvatarDisplay/AvatarDisplay'; diff --git a/src/mocks/Contact.tsx b/src/mocks/Contact.tsx index 1f86cc9b5..c4a0e2b9c 100644 --- a/src/mocks/Contact.tsx +++ b/src/mocks/Contact.tsx @@ -9,6 +9,7 @@ import { GET_CONTACT_PROFILES, GET_COLLECTION_CONTACTS, GET_CONTACTS_LIST, + GET_PROFILE, } from 'graphql/queries/Contact'; import { addFlowToContactQuery } from 'mocks/Flow'; import { getOrganizationLanguagesQuery, getOrganizationQuery } from 'mocks/Organization'; @@ -507,6 +508,32 @@ export const getContactProfiles = { }, }; +export const getProfileMock = { + request: { + query: GET_PROFILE, + variables: { + id: '1', + }, + }, + result: { + data: { + profile: { + profile: { + fields: + '{"role":{"value":"Parent","type":"string","label":"role","inserted_at":"2024-09-08T12:14:25.625321Z"},"name":{"value":"profile name 2","type":"string","label":"Name","inserted_at":"2024-09-08T12:14:25.619652Z"}}', + id: '3', + language: { + id: '1', + label: 'English', + }, + name: 'profile name 2', + type: 'Parent', + }, + }, + }, + }, +}; + export const LOGGED_IN_USER_MOCK = [ getCurrentUserQuery, getCurrentUserQuery, @@ -516,6 +543,7 @@ export const LOGGED_IN_USER_MOCK = [ getOrganizationLanguagesQuery, getOrganizationLanguagesQuery, getContactQuery, + getProfileMock, addFlowToContactQuery, clearMessagesQuery, ...getOrganizationQuery, From 8a665c4a9faa9cf8b88ff57edd93661c6a4c66c9 Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Sun, 8 Sep 2024 20:19:34 +0530 Subject: [PATCH 3/7] added test cases --- .../Profile/Contact/ContactProfile.test.tsx | 61 +++++--- .../Profile/Contact/ContactProfile.tsx | 1 + src/graphql/queries/Contact.ts | 2 +- src/mocks/Contact.tsx | 131 +++++++++++------- 4 files changed, 131 insertions(+), 64 deletions(-) diff --git a/src/containers/Profile/Contact/ContactProfile.test.tsx b/src/containers/Profile/Contact/ContactProfile.test.tsx index 346562a0d..59d8077ac 100644 --- a/src/containers/Profile/Contact/ContactProfile.test.tsx +++ b/src/containers/Profile/Contact/ContactProfile.test.tsx @@ -1,27 +1,20 @@ -import { render, waitFor } from '@testing-library/react'; +import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { MockedProvider } from '@apollo/client/testing'; -import { vi } from 'vitest'; -import { LOGGED_IN_USER_MOCK } from 'mocks/Contact'; +import { LOGGED_IN_USER_MOCK, multiple_profile_mock } from 'mocks/Contact'; import { ContactProfile } from './ContactProfile'; import { mocks as historyMock } from './ContactHistory/ContactHistory.test'; -import { MemoryRouter } from 'react-router-dom'; - -vi.mock('react-router-dom', async () => { - const actual: any = await vi.importActual('react-router-dom'); - return { - ...actual, - useParams: () => ({ id: '1' }), - }; -}); +import { MemoryRouter, Route, Routes } from 'react-router-dom'; -describe('contact profile', () => { +describe('contact profile with single profile', () => { const mocks = [...LOGGED_IN_USER_MOCK, ...historyMock]; const contactProfile = ( - + - + + } /> + ); @@ -39,7 +32,43 @@ describe('contact profile', () => { // shows N/A when no name await waitFor(() => { - expect(getAllByRole('textbox')[0]).toHaveValue('profile name 2'); + expect(getAllByRole('textbox')[0]).toHaveValue('N/A'); + }); + }); +}); + +describe('contact profile with no profiles', () => { + const wrapper = ( + + + + } /> + + + + ); + + test('should switch profile', async () => { + render(wrapper); + + await waitFor(() => { + expect(screen.getByText('Contact Profile')).toBeInTheDocument(); + }); + + await waitFor(() => { + expect(screen.getByText('Loading...')).toBeInTheDocument(); + }); + + //should show active profile first + await waitFor(() => { + expect(screen.getAllByRole('textbox')[0]).toHaveValue('profile name 2'); + }); + + fireEvent.click(screen.getAllByTestId('profileHeader')[1]); + + //should show active profile first + await waitFor(() => { + expect(screen.getAllByRole('textbox')[0]).toHaveValue('profile name 1'); }); }); }); diff --git a/src/containers/Profile/Contact/ContactProfile.tsx b/src/containers/Profile/Contact/ContactProfile.tsx index 211b9ee38..d44ed1f55 100644 --- a/src/containers/Profile/Contact/ContactProfile.tsx +++ b/src/containers/Profile/Contact/ContactProfile.tsx @@ -102,6 +102,7 @@ export const ContactProfile = () => { return (
{ setSelectedProfileId(`${id}`); diff --git a/src/graphql/queries/Contact.ts b/src/graphql/queries/Contact.ts index c5ea5196b..07d6dae94 100644 --- a/src/graphql/queries/Contact.ts +++ b/src/graphql/queries/Contact.ts @@ -174,7 +174,7 @@ export const GET_CONTACT_PROFILES = gql` `; export const GET_PROFILE = gql` - query getContact($id: ID!) { + query getProfile($id: ID!) { profile(id: $id) { profile { id diff --git a/src/mocks/Contact.tsx b/src/mocks/Contact.tsx index c4a0e2b9c..2eb63f2e3 100644 --- a/src/mocks/Contact.tsx +++ b/src/mocks/Contact.tsx @@ -68,7 +68,7 @@ export const updateContactCollectionQuery = { }, }; -export const getContactSampleQuery = (variables: any) => { +export const getContactSampleQuery = (variables: any, contactDetails?: any) => { return { request: { query: GET_CONTACT, @@ -88,6 +88,7 @@ export const getContactSampleQuery = (variables: any) => { bspStatus: 'SESSION_AND_HSM', settings: {}, fields: '{}', + ...contactDetails, }, }, }, @@ -96,6 +97,52 @@ export const getContactSampleQuery = (variables: any) => { }; export const getContactQuery = getContactSampleQuery({ id: '1' }); +export const getContactWithMultipleQueries = getContactSampleQuery( + { id: '2' }, + { + activeProfile: { + __typename: 'Profile', + id: '3', + }, + } +); + +export const getMultipleProfiles = { + request: { + query: GET_CONTACT_PROFILES, + variables: { + filter: { contactId: '2' }, + }, + }, + result: { + data: { + profiles: [ + { + fields: + '{"role":{"value":"Student","type":"string","label":"role","inserted_at":"2024-09-08T12:13:37.192507Z"},"name":{"value":"profile name 1","type":"string","label":"Name","inserted_at":"2024-09-08T12:13:37.151339Z"},"age_group":{"value":"19 or above","type":"string","label":"Age Group","inserted_at":"2024-09-08T12:12:45.907810Z"}}', + id: '2', + language: { + id: '1', + }, + name: 'profile name 1', + type: 'Student', + }, + { + __typename: 'Profile', + fields: + '{"role":{"value":"Parent","type":"string","label":"role","inserted_at":"2024-09-08T12:14:25.625321Z"},"name":{"value":"profile name 2","type":"string","label":"Name","inserted_at":"2024-09-08T12:14:25.619652Z"}}', + id: '3', + language: { + __typename: 'Language', + id: '1', + }, + name: 'profile name 2', + type: 'Parent', + }, + ], + }, + }, +}; export const clearMessagesQuery = { request: { @@ -116,10 +163,10 @@ export const clearMessagesQuery = { const date = new Date(); -export const getContactDetailsQuery = (attributes: any = {}) => ({ +export const getContactDetailsQuery = (id: string, attributes: any = {}) => ({ request: { query: GET_CONTACT_DETAILS, - variables: { id: '1' }, + variables: { id }, }, result: { data: { @@ -472,87 +519,77 @@ export const getContactProfiles = { }, result: { data: { - profiles: [ - { - fields: - '{"school":{"value":"Central","type":"string","label":"school","inserted_at":"2022-08-29T09:09:06.606859Z"},"role":{"value":"Teaccher","type":"string","label":"role","inserted_at":"2022-08-29T09:09:06.600165Z"},"name":{"value":"Shamoon","type":"string","label":"Name","inserted_at":"2022-08-29T09:09:06.590965Z"},"age":{"value":"11 to 14","type":"string","label":"age","inserted_at":"2022-08-29T09:09:06.614903Z"}}', - id: '2', - language: { - id: '1', - }, - name: 'Shamoon', - type: 'Teaccher', - }, - { - fields: - '{"school":{"value":"killer school","type":"string","label":"school","inserted_at":"2022-08-29T09:09:29.520346Z"},"role":{"value":"student","type":"string","label":"role","inserted_at":"2022-08-29T09:09:29.512350Z"},"name":{"value":"Killer","type":"string","label":"Name","inserted_at":"2022-08-29T09:09:29.506118Z"},"age":{"value":"Less than 10","type":"string","label":"age","inserted_at":"2022-08-29T09:09:29.527986Z"}}', - id: '3', - language: { - id: '2', - }, - name: 'Killer', - type: 'student', - }, - { - fields: - '{"school":{"value":"Central","type":"string","label":"school","inserted_at":"2022-08-30T08:36:30.895214Z"},"role":{"value":"Businessman","type":"string","label":"role","inserted_at":"2022-08-30T08:36:30.888247Z"},"name":{"value":"sambhar","type":"string","label":"Name","inserted_at":"2022-08-30T08:36:30.881465Z"},"age":{"value":"19 or above","type":"string","label":"age","inserted_at":"2022-08-30T08:36:30.903089Z"}}', - id: '4', - language: { - id: '1', - }, - name: 'sambhar', - type: 'Businessman', - }, - ], + profiles: [], }, }, }; -export const getProfileMock = { +export const getProfileMock = (id: string, profileDetails?: any) => ({ request: { query: GET_PROFILE, variables: { - id: '1', + id, }, }, result: { data: { profile: { profile: { - fields: - '{"role":{"value":"Parent","type":"string","label":"role","inserted_at":"2024-09-08T12:14:25.625321Z"},"name":{"value":"profile name 2","type":"string","label":"Name","inserted_at":"2024-09-08T12:14:25.619652Z"}}', - id: '3', + fields: '{}', + id, language: { id: '1', label: 'English', }, - name: 'profile name 2', - type: 'Parent', + ...profileDetails, }, }, }, }, -}; +}); export const LOGGED_IN_USER_MOCK = [ getCurrentUserQuery, getCurrentUserQuery, getContactProfiles, - getContactDetailsQuery(), - getContactDetailsQuery(), + getContactDetailsQuery('1'), + getContactDetailsQuery('1'), getOrganizationLanguagesQuery, getOrganizationLanguagesQuery, getContactQuery, - getProfileMock, + getProfileMock('1', {}), addFlowToContactQuery, clearMessagesQuery, ...getOrganizationQuery, updateContact, ]; +export const multiple_profile_mock = [ + getContactWithMultipleQueries, + getContactProfiles, + getContactDetailsQuery('2'), + getCurrentUserQuery, + getCurrentUserQuery, + getOrganizationLanguagesQuery, + getProfileMock('2', { + fields: + '{"role":{"value":"Parent","type":"string","label":"role","inserted_at":"2024-09-08T12:14:25.625321Z"},"name":{"value":"profile name 2","type":"string","label":"Name","inserted_at":"2024-09-08T12:14:25.619652Z"}}', + name: 'profile name 2', + type: 'Parent', + }), + getProfileMock('3', { + fields: + '{"role":{"value":"Student","type":"string","label":"role","inserted_at":"2024-09-08T12:14:25.625321Z"},"name":{"value":"profile name 1","type":"string","label":"Name","inserted_at":"2024-09-08T12:14:25.619652Z"}}', + name: 'profile name 1', + type: 'Student', + }), + getMultipleProfiles, + getOrganizationLanguagesQuery, +]; + export const LOGGED_IN_USER_MULTIPLE_PROFILES = [ getCurrentUserQuery, - getContactDetailsQuery({ activeProfile: { id: '4', __typename: 'Profile' } }), + getContactDetailsQuery('1', { activeProfile: { id: '4', __typename: 'Profile' } }), getOrganizationLanguagesQuery, getCurrentUserQuery, ...getOrganizationQuery, From 0d14728e25034545005a4cbe60df5faa73d35edc Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Sun, 8 Sep 2024 20:31:03 +0530 Subject: [PATCH 4/7] added test cases --- .../Profile/Contact/ContactProfile.test.tsx | 12 ++++++++++++ src/containers/Profile/Profile.tsx | 4 ---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/containers/Profile/Contact/ContactProfile.test.tsx b/src/containers/Profile/Contact/ContactProfile.test.tsx index 59d8077ac..da89632e7 100644 --- a/src/containers/Profile/Contact/ContactProfile.test.tsx +++ b/src/containers/Profile/Contact/ContactProfile.test.tsx @@ -34,6 +34,18 @@ describe('contact profile with single profile', () => { await waitFor(() => { expect(getAllByRole('textbox')[0]).toHaveValue('N/A'); }); + + fireEvent.click(getByText('History')); + + await waitFor(() => { + expect(screen.getByText('Removed from collection: "Optout contacts"')).toBeInTheDocument(); + }); + + fireEvent.click(getByText('Details')); + + await waitFor(() => { + expect(screen.getByText('Optin via BSP on 19/08/2021, 14:58:01')).toBeInTheDocument(); + }); }); }); diff --git a/src/containers/Profile/Profile.tsx b/src/containers/Profile/Profile.tsx index 88c57c376..258dccda6 100644 --- a/src/containers/Profile/Profile.tsx +++ b/src/containers/Profile/Profile.tsx @@ -61,10 +61,6 @@ export const Profile = ({ } const { selectedProfile, selectedProfileId } = multiProfileAttributes; - if (!selectedProfile) { - return; - } - if (selectedProfileId === multiProfileAttributes.activeProfileId) { setName(`${selectedProfile.name} (currently active)`); } else { From a4224bcc40c52846434ff785a6d160d45f81b6ac Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Sun, 8 Sep 2024 20:40:31 +0530 Subject: [PATCH 5/7] fixed test case --- src/containers/Profile/Contact/ContactProfile.test.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/containers/Profile/Contact/ContactProfile.test.tsx b/src/containers/Profile/Contact/ContactProfile.test.tsx index da89632e7..13daac53a 100644 --- a/src/containers/Profile/Contact/ContactProfile.test.tsx +++ b/src/containers/Profile/Contact/ContactProfile.test.tsx @@ -44,7 +44,8 @@ describe('contact profile with single profile', () => { fireEvent.click(getByText('Details')); await waitFor(() => { - expect(screen.getByText('Optin via BSP on 19/08/2021, 14:58:01')).toBeInTheDocument(); + expect(screen.getByText('Status')).toBeInTheDocument(); + expect(screen.getByText('Collections')).toBeInTheDocument(); }); }); }); From 8d30a45eb3f460581f43b846f874c6c122aa926c Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Mon, 9 Sep 2024 15:05:57 +0530 Subject: [PATCH 6/7] added status and bspStatus --- src/containers/Form/FormLayout.tsx | 3 +-- src/containers/Profile/Profile.tsx | 11 +++++++++-- src/graphql/queries/Contact.ts | 5 +++++ src/mocks/Contact.tsx | 5 +++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/containers/Form/FormLayout.tsx b/src/containers/Form/FormLayout.tsx index 327740452..b0bccfec6 100644 --- a/src/containers/Form/FormLayout.tsx +++ b/src/containers/Form/FormLayout.tsx @@ -547,7 +547,6 @@ export const FormLayout = ({ if (Object.keys(errors).length > 0) { return; } - onSaveClick(true); }; const form = ( @@ -582,7 +581,7 @@ export const FormLayout = ({ }} className={styles.Button} data-testid="submitActionButton" - loading={saveClick} + loading={formik.isSubmitting || formik.isValidating} disabled={buttonState.status} > {buttonState.status ? buttonState.text : button} diff --git a/src/containers/Profile/Profile.tsx b/src/containers/Profile/Profile.tsx index 258dccda6..3535a2bb4 100644 --- a/src/containers/Profile/Profile.tsx +++ b/src/containers/Profile/Profile.tsx @@ -97,6 +97,7 @@ export const Profile = ({ bspStatus: bspStatusValue, language: languageIdValue, fields: fieldsValue, + contact: contactDetails, }: any) => { updateName(); let hideDeleteButton = false; @@ -120,9 +121,15 @@ export const Profile = ({ hideDeleteButton = organizationPhone === currentUserPhone; } + if (hasMultipleProfiles) { + setStatus(contactDetails?.status); + setBspStatus(contactDetails?.bspStatus); + } else { + setStatus(statusValue); + setBspStatus(bspStatusValue); + } + setName(displayName); - setStatus(statusValue); - setBspStatus(bspStatusValue); setHideRemoveBtn(hideDeleteButton); setLanguageId(languageIdValue.id); }; diff --git a/src/graphql/queries/Contact.ts b/src/graphql/queries/Contact.ts index 07d6dae94..da4c41171 100644 --- a/src/graphql/queries/Contact.ts +++ b/src/graphql/queries/Contact.ts @@ -185,6 +185,11 @@ export const GET_PROFILE = gql` label id } + contact { + status + bspStatus + settings + } } } } diff --git a/src/mocks/Contact.tsx b/src/mocks/Contact.tsx index 2eb63f2e3..28619ff89 100644 --- a/src/mocks/Contact.tsx +++ b/src/mocks/Contact.tsx @@ -541,6 +541,11 @@ export const getProfileMock = (id: string, profileDetails?: any) => ({ id: '1', label: 'English', }, + contact: { + status: 'VALID', + bspStatus: 'SESSION_AND_HSM', + settings: {}, + }, ...profileDetails, }, }, From 5079983fa5a36255af6fa246530286966c43e374 Mon Sep 17 00:00:00 2001 From: Akansha Sakhre Date: Mon, 9 Sep 2024 15:17:16 +0530 Subject: [PATCH 7/7] fixed failing test case --- src/containers/Form/FormLayout.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/containers/Form/FormLayout.tsx b/src/containers/Form/FormLayout.tsx index b0bccfec6..327740452 100644 --- a/src/containers/Form/FormLayout.tsx +++ b/src/containers/Form/FormLayout.tsx @@ -547,6 +547,7 @@ export const FormLayout = ({ if (Object.keys(errors).length > 0) { return; } + onSaveClick(true); }; const form = ( @@ -581,7 +582,7 @@ export const FormLayout = ({ }} className={styles.Button} data-testid="submitActionButton" - loading={formik.isSubmitting || formik.isValidating} + loading={saveClick} disabled={buttonState.status} > {buttonState.status ? buttonState.text : button}