import { h, Component } from 'preact'; import PropTypes from 'prop-types'; import Navigation from './Navigation'; import { getContentOfToken, userData, updateOnboarding } from '../utilities'; /* eslint-disable camelcase */ class IntroSlide extends Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.onSubmit = this.onSubmit.bind(this); this.user = userData(); this.state = { checked_code_of_conduct: false, checked_terms_and_conditions: false, text: null, }; } componentDidMount() { updateOnboarding('v2: intro, code of conduct, terms & conditions'); } onSubmit() { const { next } = this.props; const csrfToken = getContentOfToken('csrf-token'); fetch('/onboarding_checkbox_update', { method: 'PATCH', headers: { 'X-CSRF-Token': csrfToken, 'Content-Type': 'application/json', }, body: JSON.stringify({ user: this.state }), credentials: 'same-origin', }).then((response) => { if (response.ok) { localStorage.setItem('shouldRedirectToOnboarding', false); next(); } }); } handleChange(event) { const { name } = event.target; this.setState((currentState) => ({ [name]: !currentState[name], })); } handleShowText(event, id) { event.preventDefault(); this.setState({ text: document.getElementById(id).innerHTML }); } isButtonDisabled() { const { checked_code_of_conduct, checked_terms_and_conditions, } = this.state; return !checked_code_of_conduct || !checked_terms_and_conditions; } render() { const { slidesCount, currentSlideIndex, prev } = this.props; const { checked_code_of_conduct, checked_terms_and_conditions, text, } = this.state; if (text) { return (
); } return (
DEV

{this.user.name} — welcome to DEV!

DEV is where programmers share ideas and help each other grow.

); } } IntroSlide.propTypes = { prev: PropTypes.func.isRequired, next: PropTypes.func.isRequired, slidesCount: PropTypes.number.isRequired, currentSlideIndex: PropTypes.func.isRequired, }; export default IntroSlide; /* eslint-enable camelcase */