Skip to content

Commit

Permalink
Show suggested status when contact has no status (#1092)
Browse files Browse the repository at this point in the history
  • Loading branch information
caleballdrin authored Sep 24, 2024
1 parent 96af2b4 commit ba860f3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Components = ({
ContactStatus: {
data: {
contact: {
status: contactStatusQueryMock || StatusEnum.NeverContacted,
status: contactStatusQueryMock || null,
},
},
},
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('SuggestedContactStatus', () => {
});

it('renders suggested status when single contact and checks contact status with gql call', async () => {
const { getByText, findByText } = render(
const { getByText } = render(
<Components
suggestedContactStatus={StatusEnum.ContactForAppointment}
contactIds={['contact-1']}
Expand All @@ -122,10 +122,9 @@ describe('SuggestedContactStatus', () => {
},
});
});

expect(
await findByText("Change the contact's status to:"),
).toBeInTheDocument();
await waitFor(() => {
expect(getByText("Change the contact's status to:")).toBeInTheDocument();
});

expect(getByText('Initiate for Appointment')).toBeInTheDocument();
});
Expand All @@ -150,4 +149,22 @@ describe('SuggestedContactStatus', () => {
expect(getByText('Initiate for Appointment')).toBeInTheDocument();
});
});

it('renders suggested status when the contact has no status', async () => {
const { getByText } = render(
<Components
suggestedContactStatus={StatusEnum.ContactForAppointment}
contactIds={['contact-1']}
contactStatus={null}
contactStatusQueryMock={null}
/>,
);

await waitFor(() => {
expect(getByText("Change the contact's status to:")).toBeInTheDocument();
});
await waitFor(() =>
expect(getByText('Initiate for Appointment')).toBeInTheDocument(),
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ export const SuggestedContactStatus: React.FC<SuggestedContactStatusProps> = ({
contactStatus || data?.contact.status;

const shouldRenderContactSuggestion: boolean = useMemo(() => {
if (!currentContactStatus) {
return false;
}
// Hide suggestedStatus if the suggested status is the current status
if (suggestedContactStatus === currentContactStatus) {
return false;
}
const disabledStatuses: StatusEnum[] = getContactStatusesByPhase(
PhaseEnum.PartnerCare,
contactStatuses,
).map((s) => s.id);
return !disabledStatuses.includes(currentContactStatus);

if (currentContactStatus) {
const disabledStatuses: StatusEnum[] = getContactStatusesByPhase(
PhaseEnum.PartnerCare,
contactStatuses,
).map((s) => s.id);
// Hide suggestedStatus if the suggested status is a partner care status, otherwise, show it
return !disabledStatuses.includes(currentContactStatus);
}
// Show suggestedStatus if the contact has no status
return true;
}, [contactStatuses, currentContactStatus]);

return suggestedContactStatus && shouldRenderContactSuggestion ? (
Expand Down

0 comments on commit ba860f3

Please sign in to comment.