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

Mhv 60731 save empty message error #33279

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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 @@ -47,9 +47,10 @@
import { getCategories } from '../../actions/categories';
import ElectronicSignature from './ElectronicSignature';
import RecipientsSelect from './RecipientsSelect';
import { getPatientSignature } from '../../actions/preferences';

const ComposeForm = props => {
const { pageTitle, headerRef, draft, recipients, signature } = props;
const { pageTitle, headerRef, draft, recipients } = props;

Check warning on line 53 in src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx:53:11:'pageTitle' is missing in props validation

Check warning on line 53 in src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx:53:22:'headerRef' is missing in props validation
const {
noAssociations,
allTriageGroupsBlocked,
Expand All @@ -58,11 +59,22 @@
const dispatch = useDispatch();
const history = useHistory();

const signature = useSelector(state => state.sm.preferences?.signature);

const [recipientsList, setRecipientsList] = useState(allowedRecipients);
const [selectedRecipientId, setSelectedRecipientId] = useState(null);
const [isSignatureRequired, setIsSignatureRequired] = useState(null);
const [checkboxMarked, setCheckboxMarked] = useState(false);

useEffect(
() => {
if (!signature) {
dispatch(getPatientSignature());
}
},
[signature, dispatch],
);

useEffect(
() => {
if (selectedRecipientId) {
Expand Down Expand Up @@ -266,7 +278,7 @@
.catch(() => setSendMessageFlag(false), scrollToTop());
}
},
[sendMessageFlag, isSaving, scrollToTop],

Check warning on line 281 in src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx:281:5:React Hook useEffect has missing dependencies: 'attachments', 'category', 'currentFolder?.folderId', 'dispatch', 'draft?.messageId', 'electronicSignature', 'history', 'messageBody', 'selectedRecipientId', and 'subject'. Either include them or remove the dependency array. Outer scope values like 'scrollToTop' aren't valid dependencies because mutating them doesn't re-render the component.
);

useEffect(
Expand Down Expand Up @@ -346,7 +358,11 @@
setSubjectError(ErrorMessages.ComposeForm.SUBJECT_REQUIRED);
messageValid = false;
}
if (messageBody === '' || messageBody.match(/^[\s]+$/)) {
if (
messageBody === '' ||
messageBody.match(/^[\s]+$/) ||
(formattedSignature && messageBody.trim() === formattedSignature.trim())
) {
setBodyError(ErrorMessages.ComposeForm.BODY_REQUIRED);
messageValid = false;
}
Expand All @@ -372,6 +388,7 @@
messageBody,
category,
isSignatureRequired,
formattedSignature,
electronicSignature,
checkboxMarked,
setMessageInvalid,
Expand Down Expand Up @@ -713,7 +730,7 @@
noTimeout();
}
},
[

Check warning on line 733 in src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx:733:5:React Hook useCallback has missing dependencies: 'noTimeout' and 'signOutMessage'. Either include them or remove the dependency array.
draft,
selectedRecipientId,
category,
Expand All @@ -733,7 +750,7 @@
noTimeout();
};
},
[beforeUnloadHandler],

Check warning on line 753 in src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/components/ComposeForm/ComposeForm.jsx:753:5:React Hook useEffect has a missing dependency: 'noTimeout'. Either include it or remove the dependency array.
);

if (sendMessageFlag === true) {
Expand Down
12 changes: 0 additions & 12 deletions src/applications/mhv-secure-messaging/containers/Compose.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import InterstitialPage from './InterstitialPage';
import { closeAlert } from '../actions/alerts';
import { PageTitles, Paths } from '../util/constants';
import { getPatientSignature } from '../actions/preferences';

const Compose = () => {
const dispatch = useDispatch();
const recipients = useSelector(state => state.sm.recipients);
const { drafts, saveError } = useSelector(state => state.sm.threadDetails);
const signature = useSelector(state => state.sm.preferences.signature);
const draftMessage = drafts?.[0] ?? null;
const { draftId } = useParams();

Expand Down Expand Up @@ -44,18 +42,9 @@
checkNextPath();
};
},
[dispatch, draftId, location.pathname],

Check warning on line 45 in src/applications/mhv-secure-messaging/containers/Compose.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/containers/Compose.jsx:45:5:React Hook useEffect has a missing dependency: 'history'. Either include it or remove the dependency array.
);

useEffect(
() => {
if (!signature) {
dispatch(getPatientSignature());
}
},
[signature, dispatch],
);

useEffect(
() => {
if (draftMessage?.messageId && draftMessage.draftDate === null) {
Expand Down Expand Up @@ -84,7 +73,7 @@
if (acknowledged && header) focusElement(document.querySelector('h1'));
document.title = `${pageTitle} ${PageTitles.PAGE_TITLE_TAG}`;
},
[header, acknowledged],

Check warning on line 76 in src/applications/mhv-secure-messaging/containers/Compose.jsx

View workflow job for this annotation

GitHub Actions / Linting (Files Changed)

src/applications/mhv-secure-messaging/containers/Compose.jsx:76:5:React Hook useEffect has a missing dependency: 'pageTitle'. Either include it or remove the dependency array.
);

const content = () => {
Expand All @@ -96,7 +85,6 @@
headerRef={header}
draft={draftMessage}
recipients={!recipients.error && recipients}
signature={signature}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,31 @@ describe('Compose form component', () => {
);
});

it('displays error states on message body field when send button is clicked and message body only has signature', async () => {
const customState = {
...initialState,
sm: {
...initialState.sm,
triageTeams: { triageTeams },
categories: { categories },
preferences: signatureReducers.signatureEnabled,
},
featureToggles: {},
};
const screen = setup(customState, Paths.COMPOSE, {
draft: { ...draftMessage, body: '\n\nName\nTitle' },
});

const sendButton = screen.getByTestId('send-button');

fireEvent.click(sendButton);

const messageInput = await screen.getByTestId('message-body-field');
const messageInputError = messageInput[getProps(messageInput)].error;

expect(messageInputError).to.equal('Message body cannot be blank.');
});

it('displays an error on attempt to save a draft with attachments', async () => {
const customProps = {
...draftMessage,
Expand Down
Loading