Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPDX-8304 Next Action autoselected #1149

Merged
merged 7 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ const TaskModalCompleteForm = ({
setFieldValue={setFieldValue}
setResultSelected={setResultSelected}
phaseData={phaseData}
completedAction={activityType}
/>

<SuggestedContactStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { ThemeProvider } from '@emotion/react';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import TestWrapper from '__tests__/util/TestWrapper';
import { Phase, ResultEnum } from 'src/graphql/types.generated';
import {
ActivityTypeEnum,
Phase,
ResultEnum,
} from 'src/graphql/types.generated';
import theme from 'src/theme';
import { SetResultSelected, handleResultChange } from '../../TaskModalHelper';
import {
Expand Down Expand Up @@ -41,6 +45,7 @@ const Components = ({ availableResults }: ComponentsProps) => (
setFieldValue={setFieldValue}
setResultSelected={setResultSelected as unknown as SetResultSelected}
phaseData={phaseData}
completedAction={ActivityTypeEnum.FollowUpTextMessage}
/>
</TestWrapper>
</ThemeProvider>
Expand Down Expand Up @@ -82,6 +87,7 @@ describe('ResultSelect', () => {
setFieldValue,
setResultSelected,
phaseData,
completedAction: ActivityTypeEnum.FollowUpTextMessage,
});
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Autocomplete, Grid, TextField } from '@mui/material';
import { useTranslation } from 'react-i18next';
import {
ActivityTypeEnum,
DisplayResultEnum,
Phase,
ResultEnum,
Expand All @@ -18,6 +19,7 @@ export interface ResultAutocompleteProps {
setResultSelected: SetResultSelected;
result?: ResultEnum | DisplayResultEnum | null;
phaseData: Phase | null;
completedAction: ActivityTypeEnum | null | undefined;
}

export const ResultAutocomplete: React.FC<ResultAutocompleteProps> = ({
Expand All @@ -26,6 +28,7 @@ export const ResultAutocomplete: React.FC<ResultAutocompleteProps> = ({
setResultSelected,
result,
phaseData,
completedAction,
}) => {
const { t } = useTranslation();

Expand All @@ -45,6 +48,7 @@ export const ResultAutocomplete: React.FC<ResultAutocompleteProps> = ({
setFieldValue,
setResultSelected,
phaseData,
completedAction,
});
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ describe('TaskModalLogForm', () => {
userEvent.click(getByRole('combobox', { name: 'Result' }));
userEvent.click(await findByRole('option', { name: 'No Response Yet' }));

expect(getByRole('combobox', { name: 'Next Action' })).toBeInTheDocument();
expect(getByRole('combobox', { name: 'Next Action' })).toHaveValue(
'Phone Call',
);
userEvent.click(getByRole('combobox', { name: 'Next Action' }));
userEvent.click(await findByRole('option', { name: 'Phone Call' }));
userEvent.click(await findByRole('option', { name: 'Email' }));

await waitFor(() => {
expect(getByText('Save')).not.toBeDisabled();
Expand All @@ -442,7 +444,7 @@ describe('TaskModalLogForm', () => {
expect(openTaskModal).toHaveBeenCalledWith({
view: TaskModalEnum.Add,
defaultValues: {
activityType: ActivityTypeEnum.FollowUpPhoneCall,
activityType: ActivityTypeEnum.FollowUpEmail,
contactIds: [],
tagList: [],
userId: 'user-1',
Expand Down
11 changes: 6 additions & 5 deletions src/components/Task/Modal/Form/LogForm/TaskModalLogForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ const taskSchema = yup.object({
completedAt: nullableDateTime(),
userId: yup.string().nullable(),
tagList: yup.array().of(yup.string()).default([]),
displayResult: yup.mixed<DisplayResultEnum>(),
result: yup.mixed<ResultEnum>(),
displayResult: yup.mixed<DisplayResultEnum>().nullable(),
result: yup.mixed<ResultEnum>().nullable(),
changeContactStatus: yup.boolean(),
nextAction: yup.mixed<ActivityTypeEnum>().nullable(),
// These field schemas should ideally be string().defined(), but Formik thinks the form is invalid
Expand Down Expand Up @@ -167,10 +167,10 @@ const TaskModalLogForm = ({
completedAt: DateTime.local(),
userId: defaultValues?.userId ?? session.data?.user.userID ?? null,
tagList: defaultValues?.tagList ?? [],
displayResult: defaultValues?.displayResult ?? undefined,
result: defaultValues?.result ?? undefined,
displayResult: defaultValues?.displayResult ?? null,
result: defaultValues?.result ?? null,
changeContactStatus: false,
nextAction: defaultValues?.nextAction ?? undefined,
nextAction: defaultValues?.nextAction ?? null,
location: '',
comment: '',
};
Expand Down Expand Up @@ -428,6 +428,7 @@ const TaskModalLogForm = ({
setFieldValue={setFieldValue}
setResultSelected={setResultSelected}
phaseData={phaseData}
completedAction={activityType}
/>
<SuggestedContactStatus
suggestedContactStatus={partnerStatus?.suggestedContactStatus}
Expand Down
1 change: 1 addition & 0 deletions src/components/Task/Modal/Form/TaskModalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ const TaskModalForm = ({
setFieldValue={setFieldValue}
setResultSelected={setResultSelected}
phaseData={phaseData}
completedAction={activityType}
/>
)}

Expand Down
22 changes: 15 additions & 7 deletions src/components/Task/Modal/Form/TaskModalHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type HandleResultChangeProps = {
setFieldValue: SetFieldValue;
setResultSelected: SetResultSelected;
phaseData: Phase | null;
completedAction: ActivityTypeEnum | null | undefined;
};

export const handleTaskPhaseChange = ({
Expand All @@ -63,9 +64,9 @@ export const handleTaskPhaseChange = ({
setFieldValue('taskPhase', phase);
setFieldValue('activityType', '');
setFieldValue('subject', '');
setFieldValue('displayResult', undefined);
setFieldValue('result', undefined);
setFieldValue('nextAction', undefined);
setFieldValue('displayResult', null);
setFieldValue('result', null);
setFieldValue('nextAction', null);
setResultSelected(null);
setActionSelected(undefined);
setPhaseId(phase);
Expand Down Expand Up @@ -105,6 +106,7 @@ export const handleResultChange = ({
setFieldValue,
setResultSelected,
phaseData,
completedAction,
}: HandleResultChangeProps): void => {
setFieldValue('displayResult', result);
setFieldValue('result', result);
Expand All @@ -115,13 +117,19 @@ export const handleResultChange = ({
result as DisplayResultEnum,
ActivityTypeEnum.None,
);
const defaultNextAction = findNextAction(completedAction, nextActions);
setFieldValue('nextAction', defaultNextAction);
};

const findNextAction = (completedAction, nextActions) => {
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
const actionsWithoutNone = nextActions.filter(
(action) => action !== ActivityTypeEnum.None,
);
setFieldValue(
'nextAction',
actionsWithoutNone.length === 1 ? actionsWithoutNone[0] : undefined,
);
return completedAction && nextActions.includes(completedAction)
caleballdrin marked this conversation as resolved.
Show resolved Hide resolved
? completedAction
: actionsWithoutNone.length === 1
? actionsWithoutNone[0]
: undefined;
};

export const getDatabaseValueFromResult = (
Expand Down
Loading