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

4609: forward message modal #5542

Merged
merged 3 commits into from
Jun 18, 2020
Merged
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
@@ -0,0 +1,23 @@
import { state } from 'cerebral';

/**
* set the modal state
*
* @param {object} providers the providers object
* @param {object} providers.store the cerebral store function
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get

export const setForwardMessageModalDialogModalStateAction = ({
get,
store,
}) => {
const messageDetail = get(state.messageDetail)[0]; //todo in later task
store.set(state.modal.validationErrors, {});
store.set(state.modal.form, {
attachments: messageDetail.attachments,
from: messageDetail.from,
fromSection: messageDetail.fromSection,
fromUserId: messageDetail.fromUserId,
parentMessageId: messageDetail.parentMessageId,
subject: messageDetail.subject,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { presenter } from '../../presenter-mock';
import { runAction } from 'cerebral/test';
import { setForwardMessageModalDialogModalStateAction } from './setForwardMessageModalDialogModalStateAction';

describe('setForwardMessageModalDialogModalStateAction', () => {
it('should set the modal state for forwarding a message', async () => {
const result = await runAction(
setForwardMessageModalDialogModalStateAction,
{
modules: {
presenter,
},
props: {},
state: {
messageDetail: [
{
attachments: [
{
documentId: 'a5273185-f694-4d9c-bc90-71eddc5e5937',
documentTitle: 'Petition',
},
],
from: 'test user 1',
fromSection: 'petitions',
fromUserId: '589002b0-dacd-4e84-874a-52d9898623c3',
parentMessageId: '530f9b43-4934-4b2f-9aa4-50dcbe8064fa',
subject: 'the subject',
},
],
},
},
);

expect(result.state.modal).toEqual({
form: {
attachments: [
{
documentId: 'a5273185-f694-4d9c-bc90-71eddc5e5937',
documentTitle: 'Petition',
},
],
from: 'test user 1',
fromSection: 'petitions',
fromUserId: '589002b0-dacd-4e84-874a-52d9898623c3',
parentMessageId: '530f9b43-4934-4b2f-9aa4-50dcbe8064fa',
subject: 'the subject',
},
validationErrors: {},
});
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { clearModalStateAction } from '../actions/clearModalStateAction';
import { setForwardMessageModalDialogModalStateAction } from '../actions/WorkItem/setForwardMessageModalDialogModalStateAction';
import { setShowModalFactoryAction } from '../actions/setShowModalFactoryAction';

export const openForwardMessageModalSequence = [
clearModalStateAction,
setForwardMessageModalDialogModalStateAction,
setShowModalFactoryAction('ForwardMessageModal'),
];
153 changes: 150 additions & 3 deletions web-client/src/views/Messages/ForwardCaseMessageModalDialog.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import { CaseMessageModalAttachments } from './CaseMessageModalAttachments';
import { ConfirmModal } from '../../ustc-ui/Modal/ConfirmModal';
import { FormGroup } from '../../ustc-ui/FormGroup/FormGroup';
import { connect } from '@cerebral/react';
import { sequences, state } from 'cerebral';
import React from 'react';

export const ForwardCaseMessageModalDialog = connect(
{},
function ForwardCaseMessageModalDialog() {
{
constants: state.constants,
form: state.modal.form,
showChambersSelect: state.modal.showChambersSelect,
updateCreateCaseMessageValueInModalSequence:
sequences.updateCreateCaseMessageValueInModalSequence,
updateModalValueSequence: sequences.updateModalValueSequence,
users: state.users,
validateCreateCaseMessageInModalSequence:
sequences.validateCreateCaseMessageInModalSequence,
validationErrors: state.validationErrors,
workQueueSectionHelper: state.workQueueSectionHelper,
},
function ForwardCaseMessageModalDialog({
constants,
form,
showChambersSelect,
updateCreateCaseMessageValueInModalSequence,
updateModalValueSequence,
users,
validateCreateCaseMessageInModalSequence,
validationErrors,
workQueueSectionHelper,
}) {
return (
<ConfirmModal
cancelLabel="Cancel"
Expand All @@ -13,7 +38,129 @@ export const ForwardCaseMessageModalDialog = connect(
title="Forward Message"
onCancelSequence="clearModalFormSequence"
onConfirmSequence={() => {}}
></ConfirmModal>
>
<FormGroup
errorText={!showChambersSelect && validationErrors.toSection}
>
<label className="usa-label" htmlFor="toSection">
Select a section
</label>

<select
className="usa-select"
id="toSection"
name="toSection"
onChange={async e => {
await updateCreateCaseMessageValueInModalSequence({
key: e.target.name,
value: e.target.value,
});
validateCreateCaseMessageInModalSequence();
}}
>
<option value="">- Select -</option>
{constants.SECTIONS.map(section => (
<option key={section} value={section}>
{workQueueSectionHelper.sectionDisplay(section)}
</option>
))}
</select>
</FormGroup>
{showChambersSelect && (
<FormGroup
errorText={validationErrors.toSection && 'Select a chamber'}
>
<label className="usa-label" htmlFor="chambers">
Select chambers
</label>
<select
className="usa-select"
id="chambers"
name="chambers"
onChange={e => {
updateCreateCaseMessageValueInModalSequence({
key: e.target.name,
value: e.target.value,
});
validateCreateCaseMessageInModalSequence();
}}
>
<option value="">- Select -</option>
{constants.CHAMBERS_SECTIONS.map(section => (
<option key={section} value={section}>
{workQueueSectionHelper.chambersDisplay(section)}
</option>
))}
</select>
</FormGroup>
)}
<FormGroup errorText={validationErrors.toUserId}>
<label className="usa-label" htmlFor="toUserId">
Select recipient
</label>
<select
aria-disabled={!form.toSection ? 'true' : 'false'}
className="usa-select"
disabled={!form.toSection}
id="toUserId"
name="toUserId"
onChange={e => {
updateCreateCaseMessageValueInModalSequence({
key: e.target.name,
value: e.target.value,
});
validateCreateCaseMessageInModalSequence();
}}
>
<option value="">- Select -</option>
{users.map(user => (
<option key={user.userId} value={user.userId}>
{user.name}
</option>
))}
</select>
</FormGroup>

<FormGroup errorText={validationErrors.subject}>
<label className="usa-label" htmlFor="subject">
Subject line
</label>
<input
className="usa-input"
id="subject"
name="form.subject"
type="text"
value={form.subject || ''}
onChange={e => {
updateModalValueSequence({
key: e.target.name,
value: e.target.value,
});
validateCreateCaseMessageInModalSequence();
}}
/>
</FormGroup>

<FormGroup errorText={validationErrors.message}>
<label className="usa-label" htmlFor="message">
Add message
</label>
<textarea
className="usa-textarea"
id="message"
name="form.message"
onChange={e => {
updateModalValueSequence({
key: e.target.name,
value: e.target.value,
});
validateCreateCaseMessageInModalSequence();
}}
/>
</FormGroup>

<CaseMessageModalAttachments />
</ConfirmModal>
);
},
);