diff --git a/src/components/direct/send-direct/DirectForm.tsx b/src/components/direct/send-direct/DirectForm.tsx new file mode 100644 index 00000000..57b35dc3 --- /dev/null +++ b/src/components/direct/send-direct/DirectForm.tsx @@ -0,0 +1,294 @@ +import { + Box, + Button, + Container, + Divider, + FormControlLabel, + FormGroup, + InputAdornment, + MenuItem, + Stack, + Switch, + TextField, + Tooltip, + Typography, +} from '@mui/material' +import DragandDropFile from '@components/shared/DragandDropFile' +import HelpIcon from '@mui/icons-material/Help' +import React, { useEffect, useState } from 'react' +import _ from 'lodash' + +const documentDropdown = [ + { + value: 'CCDA_Ambulatory.xml', + label: 'CCDA_Ambulatory.xml', + }, + { + value: 'CCDA_AMB.ZIP', + label: 'CCDA_AMB.ZIP', + }, + { + value: 'CCDA_Inpatient.xml', + label: 'CCDA_Inpatient.xml', + }, + { + value: 'CCDA_INPATIENT_IN_XDM.ZIP', + label: 'CCDA_INPATIENT_IN_XDM.ZIP', + }, + { + value: 'TOC_XDM_FULL_METADATA.ZIP', + label: 'TOC_XDM_FULL_METADATA.ZIP', + }, + { + value: 'TOC_XDM_LIMITED_METADATA.ZIP', + label: 'TOC_XDM_LIMITED_METADATA.ZIP', + }, +] + +export type certProps = { value: string; label: string } +export type algorithmProps = { label: string; value: string } +export interface DirectFormProps { + version: string + certificateDropdown: certProps[] + algorithmDropdown: algorithmProps[] +} + +const DirectForm = ({ version, certificateDropdown, algorithmDropdown }: DirectFormProps) => { + const [formErrors, setFormErrors] = useState({}) + const [formValues, setFormValues] = useState({}) + const [disableSendButton, setDisableSendButton] = React.useState(true) + /* TO-DO: Form submission, this would change when we work on functionality */ + const handleSubmit = (e: React.FormEvent) => { + const { name, value } = e.currentTarget + setFormValues({ + ...formValues, + [name]: value, + }) + console.log(formValues) + } + + /* Validation*/ + const handleValidation = (e: React.ChangeEvent) => { + let errors = {} + const { name, value } = e.target + + if (value === '') { + errors = { ...errors, [name]: 'Email Address is required' } + } + if (!/^[a-zA-Z0-9._:$!%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]$/.test(value)) { + errors = { ...errors, [name]: 'Please enter a valid email' } + } + setFormValues({ + ...formValues, + [name]: value, + }) + setFormErrors(errors) + } + + useEffect(() => { + if (_.has(formValues, 'fromEmail') && _.has(formValues, 'toEmail') && _.isEmpty(formErrors)) { + setDisableSendButton(false) + } + }, [disableSendButton, formErrors, formValues]) + + return ( + + + + Step 1 + + + Enter the fields below to send your direct message + + + + + @ett.healthit.gov + + ), + type: 'email', + }} + required + onChange={handleValidation} + /> + + + + + {documentDropdown.map((option) => ( + + {option.label} + + ))} + + + {version === 'v12' && ( + } + label="Message Format: Wrapped" + name="wrapped" + /> + )} + {version === 'v13' && ( + } + label="Message Format: Wrapped" + name="wrapped" + /> + )} + + + + + + + + Upload your own C-CDA file + + + + + + + + + + + Step 2 + + + Signing + + + + + {certificateDropdown.map((option) => ( + + {option.label} + + ))} + + + + or select message with invalid digest (message which had been altered) + + + } + label="Invalid Digest" + name="invalidDigest" + /> + + + + + {algorithmDropdown.map((option) => ( + + {option.label} + + ))} + + + + + Encryption Certificate + + + + + + + + + + + + ) +} + +export default DirectForm diff --git a/src/components/direct/send-direct/Version12Tab.tsx b/src/components/direct/send-direct/Version12Tab.tsx index 8c112edd..e1162df0 100644 --- a/src/components/direct/send-direct/Version12Tab.tsx +++ b/src/components/direct/send-direct/Version12Tab.tsx @@ -1,5 +1,21 @@ +import DirectForm, { algorithmProps, certProps } from './DirectForm' + +const certificateDropdownV12: certProps[] = [ + { value: 'GOOD', label: 'GOOD_CERT' }, + { value: 'INVALID', label: 'INVALID_CERT' }, + { value: 'EXPIRED', label: 'EXPIRED_CERT' }, + { value: 'DIFF', label: 'DIFFERENT_TRUST_ANCHOR' }, + { value: 'AIA', label: 'BAD_AIA' }, +] + +const algorithmDropdownV12: algorithmProps[] = [ + { value: 'sha1', label: 'SHA-1' }, + { value: 'sha256', label: 'SHA-256' }, +] const Version12 = () => { - return 'version 1.2' + return ( + + ) } export default Version12 diff --git a/src/components/direct/send-direct/Version13Tab.tsx b/src/components/direct/send-direct/Version13Tab.tsx index 0b5da29f..2b6dc3f7 100644 --- a/src/components/direct/send-direct/Version13Tab.tsx +++ b/src/components/direct/send-direct/Version13Tab.tsx @@ -1,51 +1,7 @@ -import { - Box, - Button, - Container, - Divider, - FormControlLabel, - FormGroup, - InputAdornment, - MenuItem, - Stack, - Switch, - TextField, - Tooltip, - Typography, -} from '@mui/material' -import DragandDropFile from '@components/shared/DragandDropFile' -import HelpIcon from '@mui/icons-material/Help' -import React, { useEffect, useState } from 'react' -import _ from 'lodash' +import React from 'react' +import DirectForm, { algorithmProps, certProps } from './DirectForm' -const documentDropdown = [ - { - value: 'CCDA_Ambulatory.xml', - label: 'CCDA_Ambulatory.xml', - }, - { - value: 'CCDA_AMB.ZIP', - label: 'CCDA_AMB.ZIP', - }, - { - value: 'CCDA_Inpatient.xml', - label: 'CCDA_Inpatient.xml', - }, - { - value: 'CCDA_INPATIENT_IN_XDM.ZIP', - label: 'CCDA_INPATIENT_IN_XDM.ZIP', - }, - { - value: 'TOC_XDM_FULL_METADATA.ZIP', - label: 'TOC_XDM_FULL_METADATA.ZIP', - }, - { - value: 'TOC_XDM_LIMITED_METADATA.ZIP', - label: 'TOC_XDM_LIMITED_METADATA.ZIP', - }, -] - -const certificateDropdown = [ +const certificateDropdown: certProps[] = [ { value: 'GOOD_CERT', label: 'GOOD_CERT' }, { value: 'INVALID_CERT', label: 'INVALID_CERT' }, { value: 'EXPIRED_CERT', label: 'EXPIRED_CERT' }, @@ -60,7 +16,7 @@ const certificateDropdown = [ { value: 'CERT_WITH_3072_BITS', label: 'CERT_WITH_3072_BITS' }, { value: 'CERT_WITH_4096_BITS', label: 'CERT_WITH_4096_BITS' }, ] -const algorithmDropdown = [ +const algorithmDropdown: algorithmProps[] = [ { value: 'SHA-256', label: 'SHA-256' }, { value: 'SHA-384', label: 'SHA-384' }, { value: 'SHA-512', label: 'SHA-512' }, @@ -77,228 +33,7 @@ const algorithmDropdown = [ ] const Version13 = () => { - const [formErrors, setFormErrors] = useState({}) - const [formValues, setFormValues] = useState({}) - const [disableSendButton, setDisableSendButton] = React.useState(true) - /* TO-DO: Form submission, this would change when we work on functionality */ - const handleSubmit = (e: React.FormEvent) => { - const { name, value } = e.currentTarget - setFormValues({ - ...formValues, - [name]: value, - }) - console.log(formValues) - } - - /* Validation*/ - const handleValidation = (e: React.ChangeEvent) => { - let errors = {} - const { name, value } = e.target - - if (value === '') { - errors = { ...errors, [name]: 'Email Address is required' } - } - if (!/^[a-zA-Z0-9._:$!%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]$/.test(value)) { - errors = { ...errors, [name]: 'Please enter a valid email' } - } - setFormValues({ - ...formValues, - [name]: value, - }) - setFormErrors(errors) - } - - useEffect(() => { - if (_.has(formValues, 'fromEmail') && _.has(formValues, 'toEmail') && _.isEmpty(formErrors)) { - setDisableSendButton(false) - } - }, [disableSendButton, formErrors, formValues]) - - return ( - - - - Step 1 - - - Enter the fields below to send your direct message - - - - - @ett.healthit.gov - - ), - type: 'email', - }} - required - onChange={handleValidation} - /> - - - - - {documentDropdown.map((option) => ( - - {option.label} - - ))} - - - } label="Wrapped" name="wrapped" /> - - - - - - - - Upload your own C-CDA file - - - - - - - - - - - Step 2 - - - Signing - - - - - {certificateDropdown.map((option) => ( - - {option.label} - - ))} - - - - or select message with invalid digest (message which had been altered) - - - } - label="Invalid Digest" - name="invalidDigest" - /> - - - - - {algorithmDropdown.map((option) => ( - - {option.label} - - ))} - - - - - Encryption Certificate - - - - - - - - - - - - ) + return } export default Version13