diff --git a/src/components/Header/Header.tsx b/src/components/Header/Header.tsx index 04185b8ea..987c0da8a 100644 --- a/src/components/Header/Header.tsx +++ b/src/components/Header/Header.tsx @@ -28,6 +28,7 @@ type Props = { onSearchButtonClick?: () => void; onCloseSearchButtonClick?: () => void; onLoginButtonClick?: () => void; + onSignUpButtonClick?: () => void; toggleUserMenu: (value: boolean) => void; children?: ReactFragment; isLoggedIn: boolean; @@ -45,6 +46,7 @@ const Header: React.FC = ({ searchEnabled, onCloseSearchButtonClick, onLoginButtonClick, + onSignUpButtonClick, isLoggedIn, userMenuOpen, toggleUserMenu, @@ -104,14 +106,7 @@ const Header: React.FC = ({ ) : (
) ) : null; diff --git a/src/components/Layout/Layout.tsx b/src/components/Layout/Layout.tsx index f0d3826eb..42ff6b903 100644 --- a/src/components/Layout/Layout.tsx +++ b/src/components/Layout/Layout.tsx @@ -63,6 +63,10 @@ const Layout: FC = ({ children }) => { history.push(addQueryParam(history, 'u', 'login')); }; + const signUpButtonClickHandler = () => { + history.push(addQueryParam(history, 'u', 'create_account')); + }; + const toggleUserMenu = (value: boolean) => UIStore.update((state) => { state.userMenuOpen = value; @@ -111,6 +115,7 @@ const Layout: FC = ({ children }) => { onSearchButtonClick={searchButtonClickHandler} onCloseSearchButtonClick={closeSearchButtonClickHandler} onLoginButtonClick={loginButtonClickHandler} + onSignUpButtonClick={signUpButtonClickHandler} isLoggedIn={isLoggedIn} userMenuOpen={userMenuOpen} toggleUserMenu={toggleUserMenu} diff --git a/src/containers/AccountModal/forms/Registration.tsx b/src/containers/AccountModal/forms/Registration.tsx new file mode 100644 index 000000000..bbffc5358 --- /dev/null +++ b/src/containers/AccountModal/forms/Registration.tsx @@ -0,0 +1,55 @@ +import React from 'react'; +import { object, string, SchemaOf, boolean } from 'yup'; +import type { RegistrationFormData } from 'types/account'; +import { useTranslation } from 'react-i18next'; +import { useHistory } from 'react-router'; + +import RegistrationForm from '../../../components/RegistrationForm/RegistrationForm'; +import useForm, { UseFormOnSubmitHandler } from '../../../hooks/useForm'; +import { addQueryParam } from '../../../utils/history'; + +//todo add registration logic + +const temp = (t: unknown) => { + t; +}; + +const Registration = () => { + const history = useHistory(); + const { t } = useTranslation('account'); + const loginSubmitHandler: UseFormOnSubmitHandler = async (formData, { setErrors, setSubmitting, setValue }) => { + try { + await temp(formData); + + history.push(addQueryParam(history, 'u', 'personal_details')); + } catch (error: unknown) { + if (error instanceof Error) { + if (error.message.toLowerCase().includes('invalid param email')) { + setErrors({ email: t('registrations.invalid_email') }); + } else if (error.message.toLowerCase().includes('invalid param password')) { + setErrors({ form: t('registrations.invalid_password') }); + } + setValue('password', ''); + } + } + + setSubmitting(false); + }; + + const validationSchema: SchemaOf = object().shape({ + email: string().email(t('registrations.field_is_not_valid_email')).required(t('registrations.field_required')), + password: string().required(t('registrations.field_required')), + termsConditions: boolean().required(t('registrations.field_required')), + emailUpdates: boolean().required(), + }); + const initialValues: RegistrationFormData = { email: '', password: '', termsConditions: true, emailUpdates: true }; + const { handleSubmit, handleChange, values, errors, submitting } = useForm( + initialValues, + loginSubmitHandler, + validationSchema, + ); + + return ; +}; + +export default Registration; diff --git a/src/hooks/useForm.ts b/src/hooks/useForm.ts index 9c017436f..11c067c62 100644 --- a/src/hooks/useForm.ts +++ b/src/hooks/useForm.ts @@ -16,7 +16,7 @@ export type UseFormReturnValue = { }; type UseFormMethods = { - setValue: (key: keyof T, value: string) => void; + setValue: (key: keyof T, value: string | boolean) => void; setErrors: (errors: FormErrors) => void; setSubmitting: (submitting: boolean) => void; }; @@ -32,7 +32,7 @@ export default function useForm( const [submitting, setSubmitting] = useState(false); const [errors, setErrors] = useState>({}); - const setValue = (name: keyof T, value: string) => { + const setValue = (name: keyof T, value: string | boolean) => { setValues((current) => ({ ...current, [name]: value })); }; diff --git a/src/i18n/locales/en_US/account.json b/src/i18n/locales/en_US/account.json index fbdfff263..c702f57c9 100644 --- a/src/i18n/locales/en_US/account.json +++ b/src/i18n/locales/en_US/account.json @@ -10,5 +10,17 @@ "view_password": "View password", "wrong_combination": "Incorrect email/password combination", "wrong_email": "Please check your email and try again." + }, + "registration": { + "email": "Email", + "field_required": "This field is required", + "hide_password": "Hide password", + "password": "Password", + "sign_up": "Sign up", + "continue": "Continue", + "view_password": "View password", + "terms_conditions": "I accept the Terms and Conditions of Cleeng.", + "email_updates": "Yes, I want to receive {{siteName}} updates by email.", + "already_account": "Already have an account?" } } diff --git a/src/styles/_theme.scss b/src/styles/_theme.scss index 1b31f0632..e0069a5a9 100644 --- a/src/styles/_theme.scss +++ b/src/styles/_theme.scss @@ -91,7 +91,7 @@ $cookies-color: $dark-color !default; $cookies-bg: variables.$white !default; // Form -$form-error-bg-color: #FF0C3E !default; +$form-error-bg-color: #ff0c3e !default; // Footer @@ -151,7 +151,11 @@ $text-field-hover-bg-color: rgba(variables.$white, 0.08) !default; $text-field-active-color: variables.$white !default; $text-field-active-border-color: variables.$white !default; $text-field-placeholder-color: rgba(variables.$white, 0.7) !default; -$text-field-error-color: #FF0C3E !default; +$text-field-error-color: #ff0c3e !default; + +// Input +$input-resting-border-color: rgba(variables.$white, 0.34) !default; +$input-hover-border-color: rgba(variables.$white, 0.7) !default; // Toggle diff --git a/types/account.d.ts b/types/account.d.ts index f3d66521c..24919413f 100644 --- a/types/account.d.ts +++ b/types/account.d.ts @@ -21,6 +21,13 @@ export type LoginFormData = { password: string; }; +export type RegistrationFormData = { + email: string; + password: string; + termsConditions: boolean; + emailUpdates: boolean; +}; + export type RegisterPayload = { email: string; password: string; diff --git a/types/general.d.ts b/types/general.d.ts index aafebb521..57fd6d101 100644 --- a/types/general.d.ts +++ b/types/general.d.ts @@ -1 +1 @@ -type FormValues = Record; +type FormValues = Record;