import * as React from 'react'; import { ValidationState, Validation } from '../../models/Validation'; import { Colors } from '../../models/colors'; import { TextBoxProps } from '../../containers/text-box/TextBox'; import { CheckboxProps } from '../../containers/checkbox/Checkbox'; import CheckboxOne from '../../components/checkboxes/checkbox-one/CheckboxOne'; import { upperTextStyle, checkboxStyle, boxStyle, additionalTextStyle } from './givingYourConsent.style'; import TextBoxOne from '../../components/text-boxes/text-box-one/TextBoxOne'; interface GivingYourConsentProps { name: string; palette?: Colors; value?: { consentToSearch?: boolean; directorCheck?: boolean; understandProceed?: boolean }; validationState?: { consentToSearch?: Validation; directorCheck?: Validation; understandProceed?: Validation; }; consentToSearchRequired?: boolean; directorCheckRequired?: boolean; understandProceedRequired?: boolean; termsAndConditionLink?: string; automationName?: string; textBox?: React.ReactElement; checkbox?: React.ReactElement; onChange?: (name: string, value: any) => void; notifyValidity?: (name: string, state: ValidationState, errorMessage?: string) => void; translator?: Function; checkIfTranslateExist?: Function; } export default class GivingYourConsent extends React.PureComponent { onChange = (name: string, value: boolean) => { let _name = name.replace(this.props.name + '.', ''); this.props.onChange(this.props.name, Object.assign({}, this.props.value, { [_name]: value })); }; render() { let validConsentToSearch, validDirectorCheck, validUnderstandProceed; let checkboxConsentToSearch, checkboxDirectorCheck, checkboxUnderstandProceed; if (this.props.validationState) { validConsentToSearch = this.props.validationState.consentToSearch.state; } if (this.props.validationState) { validDirectorCheck = this.props.validationState.directorCheck.state; } if (this.props.validationState) { validUnderstandProceed = this.props.validationState.understandProceed.state; } let consentToSearchLink = ( {this.props.translator(`${this.props.name}.consentToSearchLink`)} ); const { consentToSearch, understandProceed, directorCheck } = this.props.value || { consentToSearch: false, directorCheck: false, understandProceed: false }; checkboxConsentToSearch = React.cloneElement(this.props.checkbox || , { automationName: 'consentToSearch', palette: this.props.palette, id: 'consentToSearch', label: (
{this.props.translator(`${this.props.name}.consentToSearch`)} {consentToSearchLink}
), checked: consentToSearch, onChange: this.onChange, name: `${this.props.name}.consentToSearch`, required: this.props.consentToSearchRequired, notifyValidity: this.props.notifyValidity, valid: validConsentToSearch, translator: this.props.translator }); checkboxDirectorCheck = React.cloneElement(this.props.checkbox || , { automationName: 'directorCheck', palette: this.props.palette, id: 'directorCheck', label: this.props.translator(`${this.props.name}.directorCheck`), checked: directorCheck, onChange: this.onChange, name: `${this.props.name}.directorCheck`, required: this.props.directorCheckRequired, notifyValidity: this.props.notifyValidity, valid: validDirectorCheck, translator: this.props.translator }); checkboxUnderstandProceed = React.cloneElement(this.props.checkbox || , { automationName: 'understandProceed', palette: this.props.palette, id: 'understandProceed', label: this.props.translator(`${this.props.name}.understandProceed`), checked: understandProceed, onChange: this.onChange, name: `${this.props.name}.understandProceed`, required: this.props.understandProceedRequired, notifyValidity: this.props.notifyValidity, valid: validUnderstandProceed, translator: this.props.translator }); const content = [
{this.props.translator(`${this.props.name}.boxUpperContent`)}
{checkboxConsentToSearch}
{checkboxDirectorCheck}
{checkboxUnderstandProceed}
]; const box = React.cloneElement( this.props.textBox || , { palette: this.props.palette, customStyle: boxStyle }, content ); return (
{box}

{this.props.translator(`${this.props.name}.additionalText`)}

); } }