class FooterGobeu extends React.Component { static contextType = FooterContext constructor(props) { super(props) this.state = { name: '', mail: '', chBox_1: false, chBox_2: true, errs: [], errorText: '', confirmation: '', cook: '', } } componentDidMount() { var chCook = $.cookie(this.context.cook_name) if (!chCook || chCook !== 'ok') this.setState({ cook: 'act' }) } #change = ({ target: { value: v } }, inp) => { this.setState(pr => { pr[inp] = v return pr }) } #chBox = (ch, { target: { tagName: T } }) => { if ('A' != T) this.setState(pr => { pr[`chBox_${ch}`] = !pr[`chBox_${ch}`] return pr }) } #formSubmit = () => { let { form_err_policy, form_err_inp, form_err_incor } = this.context, { name, mail, chBox_1, chBox_2 } = this.state, errs = [], rg = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@(([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{2,})$/iu if (!chBox_1) { errs.push('policy') this.setState({ errorText: form_err_policy }) } // Проверка имени if (name.trim() === '') { errs.push('name') this.setState({ errorText: form_err_inp }) } // Проверка email if (mail.trim() === '' || !rg.test(mail)) { errs.push('mail') this.setState({ errorText: form_err_incor }) } // Очистка ошибки, если ошибок больше не осталось if (errs.length === 0) { this.setState({ errorText: '' }) } // Сохранение ошибок в состоянии this.setState({ errs }) // Если есть ошибки, прекращаем выполнение if (errs.length > 0) { this.setState({ errs }) return } fetch( '/staging/wp-content/themes/healbe/blocks/lazyblock-footer-gobeu/getresponse-footer-gobeu.php', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ lg: 'ru', name: name, mail: mail, check: chBox_1, checkSub: chBox_2, }), } ) .then(resp => { this.setState({ confirmation: 'conf' }) console.log(resp) }) .catch(error => { console.error('Ошибка при отправке данных:', error) }) } render() { let { menu_title, menu, copyright, title_apps, android_app, ios_app, social_title, links, form_title, form_input_name, form_input_mail, form_ch_1, form_ch_2, button_join, submit_ok, cookie_title, cookie_text, mobile_cookie_text, cookie_link, button_settings, button_consent, cook_name, } = this.context, { name, mail, chBox_1, chBox_2, errorText, errs, confirmation, cook } = this.state, cookAgree = cook => { $.cookie(cook, 'ok', { path: '/' }) $('.check-cookie-policy').hide() } return ( <>
{menu_title}
{menu.map(({ lb, url }) => ( {lb} ))}
{title_apps}
{social_title}
{links.map(({ resurs: r, url: h }) => ( ))}
{form_title}
{submit_ok}
{ this.#change(ev, 'name') }} value={name} placeholder={form_input_name} /> { this.#change(ev, 'mail') }} value={mail} placeholder={form_input_mail} />
{ this.#chBox(1, ev) }} dangerouslySetInnerHTML={{ __html: '' + '

' + form_ch_1 + '

', }} />
{ this.#chBox(2, ev) }} dangerouslySetInnerHTML={{ __html: '' + '

' + form_ch_2 + '

', }} />
{errorText}
{button_join}
{button_join}
) } } ReactDOM.render(, document.getElementById('footer-gobeu'))