diff --git a/client/src/components/eula/eula.component.jsx b/client/src/components/eula/eula.component.jsx index c1130c783..4ffc4be97 100644 --- a/client/src/components/eula/eula.component.jsx +++ b/client/src/components/eula/eula.component.jsx @@ -1,28 +1,28 @@ -import React, { useCallback, useEffect, useRef, useState } from "react"; +import React, {useCallback, useEffect, useRef, useState} from "react"; import {Button, Card, Checkbox, Col, Form, Input, Modal, notification, Row} from "antd"; import Markdown from "react-markdown"; -import { createStructuredSelector } from "reselect"; -import { selectCurrentEula, selectCurrentUser } from "../../redux/user/user.selectors"; -import { connect } from "react-redux"; -import { FormDatePicker } from "../form-date-picker/form-date-picker.component"; -import { INSERT_EULA_ACCEPTANCE } from "../../graphql/user.queries"; -import { useMutation } from "@apollo/client"; -import { acceptEula } from "../../redux/user/user.actions"; -import { useTranslation } from "react-i18next"; +import {createStructuredSelector} from "reselect"; +import {selectCurrentEula, selectCurrentUser} from "../../redux/user/user.selectors"; +import {connect} from "react-redux"; +import {FormDatePicker} from "../form-date-picker/form-date-picker.component"; +import {INSERT_EULA_ACCEPTANCE} from "../../graphql/user.queries"; +import {useMutation} from "@apollo/client"; +import {acceptEula} from "../../redux/user/user.actions"; +import {useTranslation} from "react-i18next"; import day from '../../utils/day'; import './eula.styles.scss'; -const Eula = ({ currentEula, currentUser, acceptEula }) => { +const Eula = ({currentEula, currentUser, acceptEula}) => { const [formReady, setFormReady] = useState(false); const [hasEverScrolledToBottom, setHasEverScrolledToBottom] = useState(false); const [insertEulaAcceptance] = useMutation(INSERT_EULA_ACCEPTANCE); const [form] = Form.useForm(); const markdownCardRef = useRef(null); - const { t } = useTranslation(); + const {t} = useTranslation(); const [api, contextHolder] = notification.useNotification(); - const handleScroll = useCallback((e) => { + const handleScroll = useCallback((e) => { const bottom = e.target.scrollHeight - 100 <= e.target.scrollTop + e.target.clientHeight; if (bottom && !hasEverScrolledToBottom) { setHasEverScrolledToBottom(true); @@ -32,11 +32,11 @@ const Eula = ({ currentEula, currentUser, acceptEula }) => { }, [hasEverScrolledToBottom, setHasEverScrolledToBottom]); useEffect(() => { - handleScroll({ target: markdownCardRef.current }); + handleScroll({target: markdownCardRef.current}); }, [handleScroll]); const handleChange = useCallback(() => { - form.validateFields({ validateOnly: true }) + form.validateFields({validateOnly: true}) .then(() => setFormReady(hasEverScrolledToBottom)) .catch(() => setFormReady(false)); }, [form, hasEverScrolledToBottom]); @@ -45,12 +45,12 @@ const Eula = ({ currentEula, currentUser, acceptEula }) => { handleChange(); }, [handleChange, hasEverScrolledToBottom, form]); - const onFinish = async ({ acceptTerms, ...formValues }) => { + const onFinish = async ({acceptTerms, ...formValues}) => { const eulaId = currentEula.id; const useremail = currentUser.email; try { - const { accepted_terms, ...otherFormValues } = formValues; + const {accepted_terms, ...otherFormValues} = formValues; await insertEulaAcceptance({ variables: { eulaAcceptance: { @@ -63,7 +63,7 @@ const Eula = ({ currentEula, currentUser, acceptEula }) => { }); acceptEula(); } catch (err) { - api.error({ + api.error({ message: t('eula.errors.acceptance.message'), description: t('eula.errors.acceptance.description'), placement: 'bottomRight', @@ -99,25 +99,25 @@ const Eula = ({ currentEula, currentUser, acceptEula }) => { )} closable={false} > - -
- -
+ +
+ +
+
+ + + + {!hasEverScrolledToBottom && ( + +

{t('eula.content.never_scrolled')}

- - - - {!hasEverScrolledToBottom && ( - -

{t('eula.content.never_scrolled')}

-
- )} + )} ) } -const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( +const EulaFormComponent = ({form, handleChange, onFinish, t}) => (
@@ -125,20 +125,28 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( + value.trim() !== '' ? Promise.resolve() : Promise.reject(new Error(t('eula.messages.first_name'))), + },]} > + aria-label={t('eula.labels.first_name')}/> + value.trim() !== '' ? Promise.resolve() : Promise.reject(new Error(t('eula.messages.last_name'))), + }]} > + aria-label={t('eula.labels.last_name')}/> @@ -147,10 +155,13 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( + value.trim() !== '' ? Promise.resolve() : Promise.reject(new Error(t('eula.messages.business_name'))), + }]} > - + @@ -165,7 +176,7 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( ]} > + aria-label={t('eula.labels.phone_number')}/> @@ -175,7 +186,7 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( label={t('eula.labels.address')} name="address" > - + @@ -183,8 +194,8 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( label={t('eula.labels.date_accepted')} name="date_accepted" rules={[ - { required: true }, { + required: true, validator: (_, value) => { if (day(value).isSame(day(), 'day')) { return Promise.resolve(); @@ -194,8 +205,7 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( }, ]} > - + @@ -206,13 +216,13 @@ const EulaFormComponent = ({ form, handleChange, onFinish, t }) => ( valuePropName="checked" rules={[ { + required: true, validator: (_, value) => value ? Promise.resolve() : Promise.reject(new Error(t('eula.messages.accepted_terms'))), }, ]} > - {t('eula.labels.accepted_terms')} + {t('eula.labels.accepted_terms')}