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

feat: 🎸 SQFormGuidedWorkflow additional section #587

Merged
merged 1 commit into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all 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,34 @@
import React from 'react';
import {Section, SectionBody} from 'scplus-shared-components';
import {AdditionalInformationPropTypes} from './PropTypes';
import Header from './Header';

function AdditionalInformationSection({
actionButton,
title,
infoText,
warningText,
errorText,
successText,
isFailedState,
Elements,
SeanGroff marked this conversation as resolved.
Show resolved Hide resolved
}) {
return (
<Section>
<Header
actionButton={actionButton}
title={title}
infoText={infoText}
warningText={warningText}
errorText={errorText}
successText={successText}
isFailedState={isFailedState}
/>
<SectionBody>{Elements}</SectionBody>
</Section>
);
}

AdditionalInformationSection.propTypes = AdditionalInformationPropTypes;

export default AdditionalInformationSection;
12 changes: 12 additions & 0 deletions src/components/SQFormGuidedWorkflow/PropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ export const HeaderPropTypes = {
isFailedState: PropTypes.bool,
};

export const AdditionalInformationPropTypes = {
Elements: PropTypes.oneOfType([
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]).isRequired,
...HeaderPropTypes,
};

export const AgentScriptPropTypes = {
/** Scripted Text for the user to read */
text: PropTypes.string.isRequired,
Expand Down Expand Up @@ -83,6 +91,10 @@ export const TaskModuleProps = {
isSubmitButtonDisabled: PropTypes.bool,
/** The props used to configure SQForm */
formikProps: PropTypes.shape(FormikProps).isRequired,
/** The props used to configure the Additional Information section */
additionalInformationSectionProps: PropTypes.shape(
AdditionalInformationPropTypes
),
/** The props used to configure the Scripted Text section */
scriptedTextProps: PropTypes.shape(AgentScriptPropTypes).isRequired,
/** The props used to configure the Outcome form section */
Expand Down
7 changes: 7 additions & 0 deletions src/components/SQFormGuidedWorkflow/SQFormGuidedWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import SQFormButton from '../SQForm/SQFormButton';
import AgentScript from './AgentScript';
import OutcomeForm from './OutcomeForm';
import AdditionalInformationSection from './AdditionalInformationSection';
import {useManageTaskModules} from './useManageTaskModules';
import {useGuidedWorkflowContext} from './useGuidedWorkflowContext';
import {GuidedWorkflowProps} from './PropTypes';
Expand Down Expand Up @@ -138,6 +139,12 @@ function SQFormGuidedWorkflow({
</div>
) : (
<>
{taskModule.additionalInformationSectionProps && (
<AdditionalInformationSection
{...taskModule.additionalInformationSectionProps}
isFailedState={taskModule.isFailedState}
/>
)}
<AgentScript
{...taskModule.scriptedTextProps}
isFailedState={taskModule.isFailedState}
Expand Down
150 changes: 104 additions & 46 deletions stories/SQFormGuidedWorkflow.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,32 @@ import {
ExpandingCardList,
ExpandingCard,
RoundedButton,
TextButton
TextButton,
} from 'scplus-shared-components';
import {
SQFormGuidedWorkflow,
SQFormDropdown,
SQFormTextarea,
SQFormTextField
SQFormTextField,
} from '../src';
import {Grid, Typography} from '@material-ui/core';

const sleep = milliseconds => {
return new Promise(resolve => setTimeout(resolve, milliseconds));
const sleep = (milliseconds) => {
return new Promise((resolve) => setTimeout(resolve, milliseconds));
};

export default {
title: 'Forms/SQFormGuidedWorkflow',
component: SQFormGuidedWorkflow,
argTypes: {
onError: {action: 'error', table: {disable: true}},
taskModules: {table: {disable: true}}
}
taskModules: {table: {disable: true}},
},
};

const outcomeDropdownOptions = [
{label: 'Not Interested', value: 'not-interested'},
{label: 'Interested', value: 'interested'}
{label: 'Interested', value: 'interested'},
];

const Template = () => {
Expand All @@ -37,7 +38,7 @@ const Template = () => {
const scriptedTextMap = {
customerName: 'Bob Smith',
agentName: 'Jane Doe',
planName: 'Super Cheap Med+'
planName: 'Super Cheap Med+',
};
const taskModules = [
{
Expand All @@ -46,7 +47,7 @@ const Template = () => {
formikProps: {
initialValues: {
outcome: '',
notes: ''
notes: '',
},
onSubmit: async (values, _formikBag, _context) => {
await sleep(3000); // Simulate API call to see loading spinner
Expand All @@ -58,12 +59,33 @@ const Template = () => {
},
validationSchema: {
outcome: Yup.string().required(),
notes: Yup.string()
}
notes: Yup.string(),
},
},
additionalInformationSectionProps: {
Elements: (
<>
<Grid container={true}>
<Grid item={true} sm={4}>
<Typography variant="body2">Name: Bob Smith</Typography>
</Grid>
<Grid item={true} sm={4}>
<Typography variant="body2">Age: 76</Typography>
</Grid>
<Grid item={true} sm={4}>
<Typography variant="body2">
Occupation: Dream Engineer
</Typography>
</Grid>
</Grid>
</>
),
title: 'Customer Information',
infoText: 'This is suplmental information for the agent only.',
},
scriptedTextProps: {
text: `Hi, ${scriptedTextMap.customerName}, my name is ${scriptedTextMap.agentName}, and I am calling to discuss ${scriptedTextMap.planName}.\n Are you available right now to talk through some things with me, today?`,
title: 'Agent Script'
title: 'Agent Script',
},
outcomeProps: {
FormElements: (
Expand All @@ -74,8 +96,8 @@ const Template = () => {
<SQFormTextarea name="notes" label="Notes" />
</>
),
title: 'Confirm Info'
}
title: 'Confirm Info',
},
},
{
name: 'cancellation',
Expand All @@ -88,18 +110,18 @@ const Template = () => {
formikProps: {
initialValues: {
outcome: '',
notes: ''
notes: '',
},
onSubmit: async (_values, _formikBag, _context) => {},
validationSchema: {
outcome: Yup.string().required(),
notes: Yup.string()
}
notes: Yup.string(),
},
},
scriptedTextProps: {
text: `Stuff about policy cancellation documents`,
title: 'Agent Script',
actionButton: <TextButton tooltip="View">View Doc</TextButton>
actionButton: <TextButton tooltip="View">View Doc</TextButton>,
},
outcomeProps: {
FormElements: (
Expand All @@ -121,8 +143,8 @@ const Template = () => {
'Interact with the form to see me change colors based on form state',
warningText: 'Form needs your attention',
successText: 'Form is ready to submit',
errorText: 'Do not pass go, do not collect $200'
}
errorText: 'Do not pass go, do not collect $200',
},
},
{
name: 'providers',
Expand All @@ -132,19 +154,55 @@ const Template = () => {
formikProps: {
initialValues: {
outcome: '',
notes: ''
notes: '',
},
onSubmit: async (_values, _formikBag, _context) => {},
validationSchema: {
outcome: Yup.string().required(),
notes: Yup.string()
}
notes: Yup.string(),
},
},
additionalInformationSectionProps: {
Elements: (
<>
<ul>
<li>
<div>
<b>Name</b>: Dr. Cassidy Cole,&nbsp;
<b>State</b>: Alaska,&nbsp;
<b>Primary</b>: Yes,&nbsp;
</div>
</li>
<li>
<div>
<b>Name</b>: Dr. Ana Amari,&nbsp;
<b>State</b>: Hawaii,&nbsp;
<b>Primary</b>: No,&nbsp;
</div>
</li>
<li>
<div>
<b>Name</b>: Dr. Hana Song,&nbsp;
<b>State</b>: Wisconsin,&nbsp;
<b>Primary</b>: No,&nbsp;
</div>
</li>
</ul>
</>
),
title: 'Providers',
actionButton: (
<TextButton
tooltip="View"
onClick={() => window.alert('Awesome list here')}
>
View Full Providers List
</TextButton>
),
},
scriptedTextProps: {
text:
'Before proceeding, please verify the list of providers is correct',
text: 'Before proceeding, please verify the list of providers is correct',
title: 'Agent Script',
actionButton: <TextButton tooltip="View">View Providers</TextButton>
},
outcomeProps: {
FormElements: (
Expand All @@ -155,9 +213,9 @@ const Template = () => {
<SQFormTextarea name="notes" label="Notes" />
</>
),
title: 'Confirm Info'
}
}
title: 'Confirm Info',
},
},
];

return (
Expand All @@ -170,7 +228,7 @@ const Template = () => {
initialCompletedTasks={0}
isStrictMode={false}
taskModules={taskModules}
onError={error => {
onError={(error) => {
window.alert(error);
}}
/>
Expand All @@ -182,7 +240,7 @@ const Template = () => {

export const Default = Template.bind({});

const TestTemplate = args => {
const TestTemplate = (args) => {
const {mainTitle, ...rest} = args;

const taskModules = [
Expand All @@ -192,17 +250,17 @@ const TestTemplate = args => {
formikProps: {
initialValues: {
firstText: '',
secondText: ''
secondText: '',
},
onSubmit: async _values => {},
onSubmit: async (_values) => {},
validationSchema: {
firstText: Yup.string().required(),
secondText: Yup.string()
}
secondText: Yup.string(),
},
},
scriptedTextProps: {
text: 'This is some text',
title: 'Script Title'
title: 'Script Title',
},
outcomeProps: {
FormElements: (
Expand All @@ -211,8 +269,8 @@ const TestTemplate = args => {
<SQFormTextField name="secondText" label="Second Text" />
</>
),
title: 'Outcome Test'
}
title: 'Outcome Test',
},
},
{
name: 'secondSection',
Expand All @@ -221,13 +279,13 @@ const TestTemplate = args => {
initialValues: {
testText: '',
outcome: '',
notes: ''
notes: '',
},
onSubmit: async _values => {}
onSubmit: async (_values) => {},
},
scriptedTextProps: {
text: 'This is some more text',
title: 'Another Script Title'
title: 'Another Script Title',
},
outcomeProps: {
FormElements: (
Expand All @@ -236,9 +294,9 @@ const TestTemplate = args => {
<SQFormTextarea name="notes" label="Notes" />
</>
),
title: 'Outcome Test'
}
}
title: 'Outcome Test',
},
},
];

return (
Expand All @@ -248,7 +306,7 @@ const TestTemplate = args => {
<SQFormGuidedWorkflow
{...rest}
mainTitle={mainTitle}
onError={error => {
onError={(error) => {
window.alert(error);
}}
taskModules={taskModules}
Expand All @@ -264,5 +322,5 @@ Testing.args = {
mainTitle: 'CCA Guided Workflow',
mainSubtitle:
'Please review these Services with your client, then confirm their responses.',
isStrictMode: false
isStrictMode: false,
};