diff --git a/storefront/components/Basic/RangeSlider/RangeSlider.tsx b/storefront/components/Basic/RangeSlider/RangeSlider.tsx index 904209f1af..672ef28fdf 100644 --- a/storefront/components/Basic/RangeSlider/RangeSlider.tsx +++ b/storefront/components/Basic/RangeSlider/RangeSlider.tsx @@ -136,7 +136,7 @@ export const RangeSlider: FC = ({ const onChangeMinInputHandler: ChangeEventHandler = (event) => setMinValueInput(parseFloat(event.currentTarget.value)); - const onKeyPressHandler: KeyboardEventHandler = (event) => + const onKeyDownHandler: KeyboardEventHandler = (event) => event.key === 'Enter' && event.currentTarget.blur(); const onChangeMinHandler = (event: ChangeEvent) => { @@ -219,7 +219,7 @@ export const RangeSlider: FC = ({ value={minValueInput} onChange={onChangeMinInputHandler} onBlur={onBlurMinHandler} - onKeyPress={onKeyPressHandler} + onKeyDown={onKeyDownHandler} disabled={isDisabled} /> @@ -235,7 +235,7 @@ export const RangeSlider: FC = ({ value={maxValueInput} onChange={onChangeMaxInputHandler} onBlur={onBlurMaxHandler} - onKeyPress={onKeyPressHandler} + onKeyDown={onKeyDownHandler} disabled={isDisabled} /> diff --git a/storefront/components/Forms/TextInput/TextInput.tsx b/storefront/components/Forms/TextInput/TextInput.tsx index 10d8517eb7..1fa0ae1f9f 100644 --- a/storefront/components/Forms/TextInput/TextInput.tsx +++ b/storefront/components/Forms/TextInput/TextInput.tsx @@ -5,8 +5,17 @@ import { twMergeCustom } from 'helpers/twMerge'; type NativeProps = ExtractNativePropsFromDefault< InputHTMLAttributes, - 'id' | 'onChange', - 'name' | 'disabled' | 'required' | 'onBlur' | 'onKeyPress' | 'className' | 'type' | 'children' | 'autoComplete' + 'id', + | 'name' + | 'disabled' + | 'required' + | 'onBlur' + | 'onKeyDown' + | 'className' + | 'type' + | 'children' + | 'autoComplete' + | 'onChange' >; export type TextInputProps = NativeProps & { @@ -30,7 +39,7 @@ export const TextInput = forwardRef( required, onBlur, onChange, - onKeyPress, + onKeyDown, className, dataTestId, value, @@ -64,7 +73,7 @@ export const TextInput = forwardRef( name={name} onBlur={onBlur} onChange={onChange} - onKeyPress={onKeyPress} + onKeyDown={onKeyDown} required={required} value={value} type={type} diff --git a/storefront/components/Forms/TextInput/TextInputControlled.tsx b/storefront/components/Forms/TextInput/TextInputControlled.tsx index e88452b2f2..3664dcfd88 100644 --- a/storefront/components/Forms/TextInput/TextInputControlled.tsx +++ b/storefront/components/Forms/TextInput/TextInputControlled.tsx @@ -11,7 +11,8 @@ type TextInputControlledProps = { | 'disabled' | 'required' | 'onBlur' - | 'onKeyPress' + | 'onKeyDown' + | 'onChange' | 'type' | 'label' | 'inputSize' @@ -39,7 +40,7 @@ export const TextInputControlled: FC = ({ (event) => { field.onBlur(); - if (textInputProps.onBlur !== undefined) { + if (textInputProps.onBlur) { textInputProps.onBlur(event); } }, diff --git a/storefront/components/Pages/Order/ContactInformation/ContactInformationCompany.tsx b/storefront/components/Pages/Order/ContactInformation/ContactInformationCompany.tsx index 72bd4b7d25..0468375137 100644 --- a/storefront/components/Pages/Order/ContactInformation/ContactInformationCompany.tsx +++ b/storefront/components/Pages/Order/ContactInformation/ContactInformationCompany.tsx @@ -38,7 +38,7 @@ export const ContactInformationCompany: FC = () => { required: true, type: 'text', autoComplete: 'organization', - onBlur: () => updateContactInformation({ companyName: companyNameValue }), + onChange: () => updateContactInformation({ companyName: companyNameValue }), }} /> { label: formMeta.fields.companyNumber.label, required: true, type: 'text', - onBlur: () => updateContactInformation({ companyNumber: companyNumberValue }), + onChange: () => updateContactInformation({ companyNumber: companyNumberValue }), }} /> { label: formMeta.fields.companyTaxNumber.label, required: false, type: 'text', - onBlur: () => updateContactInformation({ companyTaxNumber: companyTaxNumberValue }), + onChange: () => updateContactInformation({ companyTaxNumber: companyTaxNumberValue }), }} /> diff --git a/storefront/components/Pages/Order/ContactInformation/ContactInformationContent.tsx b/storefront/components/Pages/Order/ContactInformation/ContactInformationContent.tsx index 98264527d7..fe5e818785 100644 --- a/storefront/components/Pages/Order/ContactInformation/ContactInformationContent.tsx +++ b/storefront/components/Pages/Order/ContactInformation/ContactInformationContent.tsx @@ -27,19 +27,21 @@ const Popup = dynamic(() => import('components/Layout/Popup/Popup').then((compon export const ContactInformationContent: FC = () => { const { t } = useTranslation(); + const [isLoginPopupOpened, setIsLoginPopupOpened] = useState(false); const updateContactInformation = usePersistStore((store) => store.updateContactInformation); const formProviderMethods = useFormContext(); - const { trigger, formState } = formProviderMethods; - const formMeta = useContactInformationFormMeta(formProviderMethods); const isUserLoggedIn = !!useCurrentCustomerData(); + const { formState } = formProviderMethods; + + const formMeta = useContactInformationFormMeta(formProviderMethods); const emailValue = useWatch({ name: formMeta.fields.email.name, control: formProviderMethods.control }); - const [isEmailFilledCorrectly, setIsEmailFilledCorrectly] = useState(false); - const [isEmailAlreadyRegistered, setIsEmailAlreadyRegistered] = useState(false); - const [isLoginPopupOpened, setIsLoginPopupOpened] = useState(false); const [{ data: termsAndConditionsArticleUrlData }] = useTermsAndConditionsArticleUrlQueryApi(); - const termsAndConditionsArticleUrl = termsAndConditionsArticleUrlData?.termsAndConditionsArticle?.slug; const [{ data: privacyPolicyArticleUrlData }] = usePrivacyPolicyArticleUrlQueryApi(); + + const termsAndConditionsArticleUrl = termsAndConditionsArticleUrlData?.termsAndConditionsArticle?.slug; const privacyPolicyArticleUrl = privacyPolicyArticleUrlData?.privacyPolicyArticle?.slug; + const isEmailFilledCorrectly = !!emailValue && !formState.errors.email; + const [{ data: isCustomerUserRegisteredData }] = useIsCustomerUserRegisteredQueryApi({ variables: { email: emailValue, @@ -47,37 +49,12 @@ export const ContactInformationContent: FC = () => { pause: !isEmailFilledCorrectly, }); - const loginHandler = () => { - setIsLoginPopupOpened(true); - }; - useEffect(() => { - if (isUserLoggedIn === true) { + if (isUserLoggedIn) { setIsLoginPopupOpened(false); } }, [isUserLoggedIn]); - const onCloseLoginPopupHandler = () => { - setIsLoginPopupOpened(false); - }; - - useEffect(() => { - if (formState.touchedFields.email !== undefined) { - setIsEmailFilledCorrectly(formState.errors.email === undefined); - return; - } - - if (emailValue.length > 0) { - trigger('email', { shouldFocus: true }).then((isEmailValid) => { - setIsEmailFilledCorrectly(isEmailValid); - }); - } - }, [emailValue, trigger, formState.touchedFields, formState.errors]); - - useEffect(() => { - setIsEmailAlreadyRegistered(!!isCustomerUserRegisteredData?.isCustomerUserRegistered); - }, [isCustomerUserRegisteredData?.isCustomerUserRegistered]); - return ( <> { required: true, type: 'email', autoComplete: 'email', - onBlur: () => updateContactInformation({ email: emailValue }), + onChange: () => updateContactInformation({ email: emailValue }), }} /> - {isEmailAlreadyRegistered && !isUserLoggedIn && ( - )} @@ -138,8 +115,9 @@ export const ContactInformationContent: FC = () => { }} /> + {isLoginPopupOpened && ( - + setIsLoginPopupOpened(false)}> {t('Login')} diff --git a/storefront/pages/order/contact-information.tsx b/storefront/pages/order/contact-information.tsx index 4019a0e35b..a30bcc417c 100644 --- a/storefront/pages/order/contact-information.tsx +++ b/storefront/pages/order/contact-information.tsx @@ -89,7 +89,7 @@ const ContactInformationPage: FC = () => { let deliveryInfo; - if (currentCart.pickupPlace !== null) { + if (currentCart.pickupPlace) { deliveryInfo = { deliveryFirstName: formValues.differentDeliveryAddress ? formValues.deliveryFirstName @@ -141,12 +141,12 @@ const ContactInformationPage: FC = () => { }); if ( - createOrderResult.data !== undefined && - createOrderResult.data.CreateOrder.orderCreated === true && - createOrderResult.data.CreateOrder.order !== null && - currentCart.cart !== null && - currentCart.transport !== null && - currentCart.payment !== null + createOrderResult.data && + createOrderResult.data.CreateOrder.orderCreated && + createOrderResult.data.CreateOrder.order && + currentCart.cart && + currentCart.transport && + currentCart.payment ) { const gtmCreateOrderEventOrderPart = getGtmCreateOrderEventOrderPart( currentCart.cart, @@ -199,9 +199,9 @@ const ContactInformationPage: FC = () => { setOrderCreating(false); if ( - createOrderResult.data !== undefined && - createOrderResult.data.CreateOrder.orderCreated === false && - createOrderResult.data.CreateOrder.cart !== null + createOrderResult.data && + !createOrderResult.data.CreateOrder.orderCreated && + createOrderResult.data.CreateOrder.cart ) { handleCartModifications(createOrderResult.data.CreateOrder.cart.modifications, t, changePaymentInCart); } @@ -219,6 +219,7 @@ const ContactInformationPage: FC = () => { return ( <> + @@ -236,9 +237,11 @@ const ContactInformationPage: FC = () => { +