import React, { Component } from 'react'; import autobind from 'autobind-decorator'; import { Notification } from 'react-notification'; import Spinner from '../Spinner'; import CVDescInput from '../ContribView/CVDescInput'; import CVUploadInput from '../ContribView/CVUploadInput'; import CVPersonalInfosInputs from '../ContribView/CVPersonalInfosInputs'; import CVAGBInput from '../ContribView/CVAGBInput'; import CVSubmit from '../ContribView/CVSubmit'; import CVObjectTypeRadio from '../ContribView/CVObjectTypeRadio'; import CVKeepInput from '../ContribView/CVKeepInput'; import reduxLang from '../../middleware/lang'; import animateScrollTo from 'animated-scroll-to'; @reduxLang('ContribView') @autobind export default class PreLaunchForm extends Component { constructor(props) { super(props); this.state = { desc: '', file: '', first_name: '', last_name: '', birth_year: '', address: '', post_code: '', city: '', phone: '', mail: '', agb: false, notification: '', uploadeBtn: true }; this.props.toggleParticipated(false); } onObjectTypeChange(event) { this.setState({ object_type: event.target.value }); } onDescChange(event) { this.setState({ desc: event.target.value }); } onFileChange(value) { this.setState({ file: value }); } onPersonalInfosChange(event) { this.setState({ [event.target.name]: event.target.value }); } onKeepChange(event) { this.setState({ keep: event.target.value }); } onAGBChange(event) { this.setState({ agb: event.target.checked }); } onSubmit(event) { event.preventDefault(); if (this.validForm()) { const data = { ...this.state }; delete data.abg; delete data.notification; this.props.sendParticipation(data); } } validForm() { const { object_type, desc, first_name, last_name, mail, keep, agb } = this.state; const { t } = this.props; if (!object_type) { this.setState({ notification: t('noti_object_type') }); return false; } if (!desc) { this.setState({ notification: t('noti_desc') }); return false; } if (!first_name) { this.setState({ notification: t('noti_first_name') }); return false; } if (!last_name) { this.setState({ notification: t('noti_last_name') }); return false; } if (!mail) { this.setState({ notification: t('noti_mail') }); return false; } if (!keep) { this.setState({ notification: t('noti_keep') }); return false; } if (!agb) { this.setState({ notification: t('noti_agb') }); return false; } return true; } onNotificationDismiss() { this.setState({ notification: '' }); } resetUploadBtn() { this.setState({ uploadeBtn: false }); setImmediate(() => this.setState({ uploadeBtn: true })); } componentDidUpdate(prevProps) { if (this.props.participated) { animateScrollTo(document.getElementById('pre-launch-contribute-form')); } if (prevProps.locale !== this.props.locale) { this.resetUploadBtn(); } } render() { const { notification, uploadeBtn } = this.state; const { pending, participated, t } = this.props; if (pending) { return ; } return (

{t('we_search')}

{uploadeBtn && ( )}
{participated && (
{t('thank_you')}
)}
); } }