* fix: eslint operator-linebreak issue * fix: eslint quotes issue * fix: react jsx indent and props issues * fix: eslint trailing spaces issues * fix: eslint line around directives issue * fix: eslint semi rule * fix: eslint newline per chain rule * fix: eslint space infix ops rule * fix: eslint space-in-parens issue * fix: eslint space before function paren issue * fix: eslint space before blocks issue * fix: eslint arrow body style issue * fix: eslint dot-location issue * fix: eslint quotes issue * fix: eslint quote props issue * fix: eslint operator assignment issue * fix: eslint new line after import issue * fix: indent issues * fix: operator assignment issue * fix: all autofixable eslint issues * fix: all react related fixable issues * fix: autofixable eslint issues * chore: remove all template literals * fix: remaining autofixable issues * fix: failing js test
97 lines
4.4 KiB
JavaScript
97 lines
4.4 KiB
JavaScript
/* global gettext */
|
|
import React from 'react';
|
|
import Cookies from 'js-cookie';
|
|
import {DemographicsCollectionModal} from './DemographicsCollectionModal';
|
|
|
|
export class DemographicsCollectionBanner extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
modalOpen: false,
|
|
hideBanner: false
|
|
};
|
|
|
|
this.dismissBanner = this.dismissBanner.bind(this);
|
|
}
|
|
|
|
/**
|
|
* Utility function that controls hiding the CTA from the Course Dashboard where appropriate.
|
|
* This can be called one of two ways - when a user clicks the "dismiss" button on the CTA
|
|
* itself, or when the learner completes all of the questions within the modal.
|
|
*
|
|
* The dismiss button itself is nested inside of an <a>, so we need to call stopPropagation()
|
|
* here to prevent the Modal from _also_ opening when the Dismiss button is clicked.
|
|
*/
|
|
async dismissBanner(e) {
|
|
// Since this function also doubles as a callback in the Modal, we check if e is null/undefined
|
|
// before calling stopPropagation()
|
|
if (e) {
|
|
e.stopPropagation();
|
|
}
|
|
|
|
const requestOptions = {
|
|
method: 'PATCH',
|
|
credentials: 'include',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-CSRFTOKEN': Cookies.get('csrftoken'),
|
|
},
|
|
body: JSON.stringify({
|
|
show_call_to_action: false,
|
|
})
|
|
};
|
|
|
|
await fetch(`${this.props.lmsRootUrl}/api/demographics/v1/demographics/status/`, requestOptions);
|
|
// No matter what the response is from the API call we always allow the learner to dismiss the
|
|
// banner when clicking the dismiss button
|
|
this.setState({hideBanner: true});
|
|
}
|
|
|
|
render() {
|
|
if (!(this.state.hideBanner)) {
|
|
return (
|
|
<div>
|
|
<a id="demographics-banner-link" className="btn" onClick={() => this.setState({modalOpen: true})}>
|
|
<div
|
|
className="demographics-banner d-flex justify-content-lg-between flex-row py-1 px-2 mb-2 mb-lg-4"
|
|
role="dialog"
|
|
aria-modal="false"
|
|
aria-label="demographics questionnaire pitch"
|
|
>
|
|
<div className="d-flex justify-content-left align-items-lg-center flex-column flex-lg-row w-100">
|
|
<img className="demographics-banner-icon d-none d-lg-inline-block" src={this.props.bannerLogo} alt="" aria-hidden="true" />
|
|
<div className="demographics-banner-prompt d-inline-block font-weight-bold text-white mr-4 py-3 px-2 px-lg-3">
|
|
{gettext('Want to make edX better for everyone?')}
|
|
</div>
|
|
<button className="demographics-banner-btn d-flex align-items-center bg-white font-weight-bold border-0 py-2 px-3 mx-2 mb-3 m-lg-0 shadow justify-content-center">
|
|
<span className="fa fa-thumbs-up px-2" aria-hidden="true" />
|
|
{gettext('Get started')}
|
|
</button>
|
|
</div>
|
|
<div className="demographics-dismiss-container md-flex justify-content-right align-self-start align-self-lg-center ml-lg-auto">
|
|
<button type="button" className="demographics-dismiss-btn btn btn-default px-0" id="demographics-dismiss" aria-label="close">
|
|
<i className="fa fa-times-circle text-white px-2" aria-hidden="true" onClick={this.dismissBanner} />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</a>
|
|
<div>
|
|
{this.state.modalOpen
|
|
&& (
|
|
<DemographicsCollectionModal
|
|
{...this.props}
|
|
user={this.props.user}
|
|
open={this.state.modalOpen}
|
|
closeModal={() => this.setState({modalOpen: false})}
|
|
dismissBanner={this.dismissBanner}
|
|
/>
|
|
)}
|
|
</div>
|
|
</div>
|
|
);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|