|

   Veteran Tools Platform - Developer Documentation

There are no notes for this item.

PropRequired?TypeDefaultDescription
terms No object
onCancel No func
<div id="reactMount" data-tpl="accepttermsprompt">
    <div class="row primary terms-acceptance">
        <div class="small-12 columns usa-content" role="region" aria-label="Terms and Conditions" tabindex="0">
            <div>test header content</div>
            <h1>Terms and Conditions</h1>
            <div class="terms-box">
                <div class="terms-head">Scroll to read the full terms and conditions to continue</div>
                <div class="terms-scroller" tabindex="0">
                    <div>
                        <div>
                            <p><strong>Terms and Conditions for Medical Information</strong></p>
                            <p>The Department of Veterans Affairs (VA) owns and manages the website Vets.gov. Vets.gov allows you to use online tools that display parts of your personal health information. This health information is only displayed on Vets.gov—the
                                information is stored on VA protected federal computer systems and networks. VA supports the secure storage and transmission of all information on Vets.gov.</p>
                            <p><strong>Terms and Conditions for Medical Information</strong></p>
                            <p>The Department of Veterans Affairs (VA) owns and manages the website Vets.gov. Vets.gov allows you to use online tools that display parts of your personal health information. This health information is only displayed on Vets.gov—the
                                information is stored on VA protected federal computer systems and networks. VA supports the secure storage and transmission of all information on Vets.gov.</p>
                            <p><strong>Terms and Conditions for Medical Information</strong></p>
                            <p>The Department of Veterans Affairs (VA) owns and manages the website Vets.gov. Vets.gov allows you to use online tools that display parts of your personal health information. This health information is only displayed on Vets.gov—the
                                information is stored on VA protected federal computer systems and networks. VA supports the secure storage and transmission of all information on Vets.gov.</p>
                        </div>
                    </div>
                </div>
                <div class="form-radio-buttons disabled">
                    <div><input type="checkbox" name="form-selection" id="form-yes" value="yes" disabled="" /><label for="form-yes">accept terms and conditions</label></div>
                </div>
            </div>
            <div>
                <div>test footer content</div>
            </div>
            <div><button class="usa-button usa-button-disabled submit-button" disabled="">Submit</button><button class="usa-button usa-button-secondary">Cancel</button></div>
        </div>
    </div>
</div>
<script>
    window.currentProps = {
        "package": {
            "name": "department-of-veteran-affairs/jean-pants",
            "version": "0.1.0"
        },
        "assetPath": "/design-system/",
        "isProduction": true,
        "componentSourcePath": "./AcceptTermsPrompt.jsx"
    }
</script>
import React from 'react';
import AcceptTermsPrompt from './AcceptTermsPrompt';

export default function AcceptTermsPromptExample(props) {
  return (
      <AcceptTermsPrompt terms={{termsContent: '<div><p><strong>Terms and Conditions for Medical Information</strong></p><p>The Department of Veterans Affairs (VA) owns and manages the website Vets.gov. Vets.gov allows you to use online tools that display parts of your personal health information. This health information is only displayed on Vets.gov—the information is stored on VA protected federal computer systems and networks. VA supports the secure storage and transmission of all information on Vets.gov.</p><p><strong>Terms and Conditions for Medical Information</strong></p><p>The Department of Veterans Affairs (VA) owns and manages the website Vets.gov. Vets.gov allows you to use online tools that display parts of your personal health information. This health information is only displayed on Vets.gov—the information is stored on VA protected federal computer systems and networks. VA supports the secure storage and transmission of all information on Vets.gov.</p><p><strong>Terms and Conditions for Medical Information</strong></p><p>The Department of Veterans Affairs (VA) owns and manages the website Vets.gov. Vets.gov allows you to use online tools that display parts of your personal health information. This health information is only displayed on Vets.gov—the information is stored on VA protected federal computer systems and networks. VA supports the secure storage and transmission of all information on Vets.gov.</p></div>', headerContent: 'test header content', title: 'Terms and Conditions',footerContent:'test footer content', yesContent: 'accept terms and conditions'}} onAccept={()=>{}} onCancel={()=>{}}/>
  );
}
package:
  name: department-of-veteran-affairs/jean-pants
  version: 0.1.0
assetPath: /design-system/
isProduction: true
componentSourcePath: ./AcceptTermsPrompt.jsx
  • Content:
    import React from 'react';
    import classNames from 'classnames';
    import PropTypes from 'prop-types';
    
    class AcceptTermsPrompt extends React.Component {
      constructor(props) {
        super(props);
        this.handleScroll = this.handleScroll.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);
        this.handleAnswer = this.handleAnswer.bind(this);
        this.state = { scrolledToBottom: false, yesSelected: false };
      }
    
      componentDidMount() {
        window.dataLayer.push({ event: 'terms-shown' });
        window.scrollTo(0, 0);
      }
    
      handleSubmit() {
        this.props.onAccept(this.props.terms.name);
      }
    
      handleScroll(event) {
        const ct = event.currentTarget;
        if (ct.scrollTop + ct.offsetHeight + 100 >= ct.scrollHeight) {
          this.setState({
            scrolledToBottom: true,
            yesSelected: this.state.yesSelected
          });
        }
      }
    
      handleAnswer(event) {
        if (event.currentTarget.value === 'yes' && event.currentTarget.checked) {
          this.setState({
            scrolledToBottom: this.state.scrolledToBottom,
            yesSelected: true
          });
        }
      }
    
      render() {
        // loading state for terms content is handled by parent component
        const { terms, onCancel } = this.props;
    
        if (!terms.termsContent) {
          return <div/>;
        }
    
        const submitDisabled = !(
          this.state.scrolledToBottom && this.state.yesSelected
        );
    
        const submitClass = classNames({
          'usa-button': true,
          'usa-button-disabled': submitDisabled,
          'submit-button': true
        });
    
        const submitButton = (
          <button
            className={submitClass}
            disabled={submitDisabled}
            onClick={this.handleSubmit}>
            Submit
          </button>
        );
    
        const yesButton = (
          <div>
            <input
              type="checkbox"
              name="form-selection"
              id="form-yes"
              value="yes"
              onChange={this.handleAnswer}
              disabled={!this.state.scrolledToBottom}/>
            <label htmlFor="form-yes">{terms.yesContent}</label>
          </div>
        );
    
        const actionButtonClass = classNames({
          'form-radio-buttons': true,
          disabled: !this.state.scrolledToBottom
        });
    
        /* eslint-disable react/no-danger */
        /* eslint-disable jsx-a11y/no-noninteractive-tabindex */
        return (
          <div className="row primary terms-acceptance">
            <div
              className="small-12 columns usa-content"
              role="region"
              aria-label="Terms and Conditions"
              tabIndex="0">
              <div dangerouslySetInnerHTML={{ __html: terms.headerContent }}/>
              <h1>{terms.title}</h1>
              <div className="terms-box">
                <div className="terms-head">
                  Scroll to read the full terms and conditions to continue
                </div>
                <div
                  className="terms-scroller"
                  onScroll={this.handleScroll}
                  tabIndex="0">
                  <div dangerouslySetInnerHTML={{ __html: terms.termsContent }}/>
                </div>
                <div className={actionButtonClass}>{yesButton}</div>
              </div>
              <div>
                <div dangerouslySetInnerHTML={{ __html: terms.footerContent }}/>
              </div>
              <div>
                {submitButton}
                <button
                  className="usa-button usa-button-secondary"
                  onClick={onCancel}>
                  Cancel
                </button>
              </div>
            </div>
          </div>
        );
        /* eslint-enable jsx-a11y/no-noninteractive-tabindex */
        /* eslint-enable react/no-danger */
      }
    }
    
    AcceptTermsPrompt.propTypes = {
      /* content shown as the actual terms and conditions */
      terms: PropTypes.object,
    
      /* cancel button click handler */
      onCancel: PropTypes.func
    };
    export default AcceptTermsPrompt;
    
  • URL: /components/raw/accepttermsprompt/AcceptTermsPrompt.jsx
  • Filesystem Path: src/components/AcceptTermsPrompt/AcceptTermsPrompt.jsx
  • Size: 3.7 KB
  • Content:
    import React from 'react';
    import { expect } from 'chai';
    import { mount } from 'enzyme';
    import { axeCheck } from '../../../lib/testing/helpers';
    import sinon from 'sinon';
    
    import AcceptTermsPrompt from './AcceptTermsPrompt.jsx';
    
    const defaultProps = {
      terms: {
        termsContent: 'content',
        name: 'mhvac',
        yesContent: 'yes content',
        title: 'Terms and Conditions'
      },
      onAccept: sinon.spy(),
      onCancel: sinon.spy()
    };
    describe('<AcceptTermsPrompt/>', () => {
      let wrapper;
    
      beforeEach(() => {
        window.dataLayer = [];
        window.scrollTo = () => {};
        wrapper = mount(<AcceptTermsPrompt {...defaultProps}/>).setState({
          scrolledToBottom: false,
          yesSelected: false
        });
      });
      it('should be empty if there is no content', () => {
        const tree = mount(<AcceptTermsPrompt terms={{}}/>);
        expect(tree.text()).to.equal('');
      });
      it('should render', () => {
        expect(wrapper.text()).to.contain(
          'Scroll to read the full terms and conditions to continuecontentyes contentSubmitCancel'
        );
      });
      it('should pass aXe check', () => {
        return axeCheck(
          <AcceptTermsPrompt terms={{}} onAccept={() => {}} onCancel={() => {}}/>
        );
      });
      it('should pass aXe check with default props', () => {
        return axeCheck(<AcceptTermsPrompt {...defaultProps}/>);
      });
      it('submit button should be disabled by default', () => {
        const submitButtonDisabled = wrapper.find('.usa-button-disabled');
        expect(submitButtonDisabled).to.have.lengthOf(1);
      });
      it('submit button should be enabled if state is valid', () => {
        wrapper.setState({
          yesSelected: true,
          scrolledToBottom: true
        });
        const submitButton = wrapper.find('.submit-button');
        expect(submitButton).to.have.lengthOf(1);
      });
      it('should call onAccept correctly', () => {
        wrapper.setState({
          yesSelected: true,
          scrolledToBottom: true
        });
        const submitButton = wrapper.find('.submit-button');
        submitButton.simulate('click');
        expect(defaultProps.onAccept.calledWith('mhvac')).to.be.true;
      });
      it('should call onCancel correctly', () => {
        const cancelButton = wrapper.find('.usa-button-secondary');
        cancelButton.simulate('click');
        expect(defaultProps.onCancel.calledOnce).to.be.true;
      });
    });
    
  • URL: /components/raw/accepttermsprompt/AcceptTermsPrompt.unit.spec.jsx
  • Filesystem Path: src/components/AcceptTermsPrompt/AcceptTermsPrompt.unit.spec.jsx
  • Size: 2.3 KB
  • Handle: @accepttermsprompt
  • Preview:
  • Filesystem Path: src/components/AcceptTermsPrompt/AcceptTermsPrompt.njk