import { h, Component } from 'preact'; import PropTypes from 'prop-types'; import { getContentOfToken, updateOnboarding } from '../utilities'; import { Navigation } from './Navigation'; /* eslint-disable camelcase */ export class EmailPreferencesForm extends Component { constructor(props) { super(props); this.handleChange = this.handleChange.bind(this); this.onSubmit = this.onSubmit.bind(this); this.state = { email_newsletter: false, email_digest_periodic: false, }; } componentDidMount() { updateOnboarding('v2: email preferences form'); } onSubmit() { const csrfToken = getContentOfToken('csrf-token'); fetch('/onboarding/notifications', { method: 'PATCH', headers: { 'X-CSRF-Token': csrfToken, 'Content-Type': 'application/json', }, body: JSON.stringify({ notifications: this.state }), credentials: 'same-origin', }).then((response) => { if (response.ok) { localStorage.setItem('shouldRedirectToOnboarding', false); const { next } = this.props; next(); } }); } handleChange(event) { const { name } = event.target; this.setState((currentState) => ({ [name]: !currentState[name], })); } render() { const { email_newsletter, email_digest_periodic } = this.state; const { prev, slidesCount, currentSlideIndex } = this.props; return (