diff --git a/src/api/apiPutEmail.ts b/src/api/apiPutEmail.ts index bf409501d..9298ae543 100644 --- a/src/api/apiPutEmail.ts +++ b/src/api/apiPutEmail.ts @@ -1,4 +1,7 @@ +import { InputFieldLabelState } from '../components/inputField/InputField'; +import { isStringValidEmail } from '../components/registration/registrationHelpers'; import { config } from '../resources/scripts/config'; +import { translate } from '../resources/scripts/i18n/translate'; import { fetchData, FETCH_METHODS, FETCH_ERRORS } from './fetchData'; export const apiPutEmail = async (email: string): Promise => { @@ -11,3 +14,24 @@ export const apiPutEmail = async (email: string): Promise => { responseHandling: [FETCH_ERRORS.CONFLICT_WITH_RESPONSE] }); }; + +export const validateEmail = ( + email +): { valid: InputFieldLabelState; label: string } => { + if (email.length > 0 && isStringValidEmail(email)) { + return { + valid: 'valid', + label: translate('furtherSteps.email.overlay.input.valid') + }; + } else if (email.length > 0) { + return { + valid: 'invalid', + label: translate('furtherSteps.email.overlay.input.invalid') + }; + } else { + return { + valid: null, + label: translate('furtherSteps.email.overlay.input.label') + }; + } +}; diff --git a/src/components/message/FurtherSteps.tsx b/src/components/message/FurtherSteps.tsx index af3604ca3..abf729efd 100644 --- a/src/components/message/FurtherSteps.tsx +++ b/src/components/message/FurtherSteps.tsx @@ -15,10 +15,7 @@ import { InputFieldItem, InputFieldLabelState } from '../inputField/InputField'; -import { - isStringValidEmail, - ResortData -} from '../registration/registrationHelpers'; +import { ResortData } from '../registration/registrationHelpers'; import { useContext, useEffect, useState } from 'react'; import { Overlay, @@ -26,7 +23,7 @@ import { OverlayWrapper, OVERLAY_FUNCTIONS } from '../overlay/Overlay'; -import { apiPutEmail, FETCH_ERRORS } from '../../api'; +import { apiPutEmail, FETCH_ERRORS, validateEmail } from '../../api'; import { ActiveSessionGroupIdContext, getActiveSession, @@ -88,27 +85,6 @@ export const FurtherSteps = (props: FurtherStepsProps) => { labelState: emailLabelState }; - const validateEmail = ( - email - ): { valid: InputFieldLabelState; label: string } => { - if (email.length > 0 && isStringValidEmail(email)) { - return { - valid: 'valid', - label: translate('furtherSteps.email.overlay.input.valid') - }; - } else if (email.length > 0) { - return { - valid: 'invalid', - label: translate('furtherSteps.email.overlay.input.invalid') - }; - } else { - return { - valid: null, - label: translate('furtherSteps.email.overlay.input.label') - }; - } - }; - const handleEmailChange = (event) => { const validity = validateEmail(event.target.value); setEmailLabelState(validity.valid);