From 34dfede4e3ebad404c8137f8ca55ad62b28a2fdb Mon Sep 17 00:00:00 2001 From: Nada Date: Thu, 9 May 2024 12:22:12 +0400 Subject: [PATCH] fix: mobile view add payment method fixed --- .../PaymentMethodCardBody.tsx | 9 +++-- .../__tests__/PaymentMethodCardBody.spec.tsx | 7 ++++ .../PaymentMethodForm/PaymentMethodForm.tsx | 39 +++++++++++-------- .../PaymentMethodsFormFooter.scss | 2 +- .../PaymentMethodsFormFooter.tsx | 13 ++++++- .../SellAdPaymentSelection.scss | 3 +- src/pages/my-ads/screens/MyAds/MyAds.tsx | 2 +- 7 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx b/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx index 0e319c6b..3c285cee 100644 --- a/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx +++ b/src/components/PaymentMethodCard/PaymentMethodCardBody/PaymentMethodCardBody.tsx @@ -1,4 +1,5 @@ import { TAccount, TBankName, THooks, TName } from 'types'; +import { useDevice } from '@/hooks'; import { Text } from '@deriv-com/ui'; import './PaymentMethodCardBody.scss'; @@ -14,13 +15,15 @@ const PaymentMethodCardBody = ({ const displayName = paymentMethod?.display_name; const modifiedDisplayName = displayName?.replace(/\s|-/gm, ''); const isBankOrOther = modifiedDisplayName && ['BankTransfer', 'Other'].includes(modifiedDisplayName); + const { isMobile } = useDevice(); + const textSize = isMobile ? 'md' : 'sm'; return (
- {isBankOrOther && !shouldShowPaymentMethodDisplayName ? null : {displayName}} - + {isBankOrOther && !shouldShowPaymentMethodDisplayName ? null : {displayName}} + {(paymentMethod.fields?.bank_name as TBankName)?.value ?? (paymentMethod.fields?.name as TName)?.value} - {(paymentMethod.fields?.account as TAccount)?.value} + {(paymentMethod.fields?.account as TAccount)?.value}
); }; diff --git a/src/components/PaymentMethodCard/__tests__/PaymentMethodCardBody.spec.tsx b/src/components/PaymentMethodCard/__tests__/PaymentMethodCardBody.spec.tsx index 352fb110..9800a42c 100644 --- a/src/components/PaymentMethodCard/__tests__/PaymentMethodCardBody.spec.tsx +++ b/src/components/PaymentMethodCard/__tests__/PaymentMethodCardBody.spec.tsx @@ -1,6 +1,13 @@ import { render, screen } from '@testing-library/react'; import { PaymentMethodCardBody } from '../PaymentMethodCardBody'; +jest.mock('@deriv-com/ui', () => ({ + ...jest.requireActual('@deriv-com/ui'), + useDevice: jest.fn(() => { + false; + }), +})); + describe('PaymentMethodCardBody', () => { it('should render the component correctly', () => { render( diff --git a/src/components/PaymentMethodForm/PaymentMethodForm.tsx b/src/components/PaymentMethodForm/PaymentMethodForm.tsx index 3c210597..ed4a2b66 100644 --- a/src/components/PaymentMethodForm/PaymentMethodForm.tsx +++ b/src/components/PaymentMethodForm/PaymentMethodForm.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from 'react'; +import { FormEvent, useEffect, useMemo, useState } from 'react'; import { useForm } from 'react-hook-form'; import { TAdvertiserPaymentMethod, TFormState, TSelectedPaymentMethod } from 'types'; import { PageReturn, PaymentMethodField, PaymentMethodsFormFooter } from '@/components'; @@ -181,6 +181,24 @@ const PaymentMethodForm = ({ ); } + const handleFormSubmit = (event: FormEvent) => { + event.preventDefault(); // Prevents create edit ad form submission + event.stopPropagation(); + handleSubmit(data => { + const hasData = Object.keys(data).length > 0; + if (actionType === 'ADD' && hasData) { + create({ + ...data, + method: String((selectedPaymentMethod as TAdvertiserPaymentMethod)?.method), + }); + } else if (actionType === 'EDIT' && hasData) { + update(String(selectedPaymentMethod?.id), { + ...data, + }); + } + })(event); + }; + return (
-
{ - const hasData = Object.keys(data).length > 0; - if (actionType === 'ADD' && hasData) { - create({ - ...data, - method: String((selectedPaymentMethod as TAdvertiserPaymentMethod)?.method), - }); - } else if (actionType === 'EDIT' && hasData) { - update(String(selectedPaymentMethod?.id), { - ...data, - }); - } - })} - > +
)} diff --git a/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.scss b/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.scss index 0c6ea109..c6ab4a20 100644 --- a/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.scss +++ b/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.scss @@ -11,6 +11,6 @@ padding: 1.6rem 2.4rem; border-top: 2px solid #f2f3f4; position: absolute; - bottom: 2.2rem; + bottom: 0; } } diff --git a/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.tsx b/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.tsx index 23576f79..f4954ab2 100644 --- a/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.tsx +++ b/src/components/PaymentMethodsFormFooter/PaymentMethodsFormFooter.tsx @@ -1,3 +1,4 @@ +import { ButtonHTMLAttributes, FormEvent, MouseEventHandler } from 'react'; import { TFormState } from 'types'; import { Button, useDevice } from '@deriv-com/ui'; import './PaymentMethodsFormFooter.scss'; @@ -8,6 +9,8 @@ type TPaymentMethodsFormFooterProps = { isDirty: boolean; isSubmitting: boolean; isValid: boolean; + onSubmit?: (event: FormEvent) => void; + type?: ButtonHTMLAttributes['type']; }; /** @@ -26,6 +29,8 @@ const PaymentMethodsFormFooter = ({ isDirty, isSubmitting, isValid, + onSubmit, + type = 'submit', }: TPaymentMethodsFormFooterProps) => { const { isMobile } = useDevice(); const textSize = isMobile ? 'md' : 'sm'; @@ -48,7 +53,13 @@ const PaymentMethodsFormFooter = ({ Cancel {/* TODO: Remember to translate these */} -
diff --git a/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.scss b/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.scss index fae67562..125be9e2 100644 --- a/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.scss +++ b/src/pages/my-ads/components/SellAdPaymentSelection/SellAdPaymentSelection.scss @@ -11,9 +11,10 @@ & .payment-method-form { @include mobile { background: #ffffff; - z-index: 1; + z-index: 999; inset: 0; top: 4rem; + position: fixed; &__form { & .payment-methods-form-footer { diff --git a/src/pages/my-ads/screens/MyAds/MyAds.tsx b/src/pages/my-ads/screens/MyAds/MyAds.tsx index 61daf22c..e5048cbd 100644 --- a/src/pages/my-ads/screens/MyAds/MyAds.tsx +++ b/src/pages/my-ads/screens/MyAds/MyAds.tsx @@ -6,7 +6,7 @@ const MyAds = () => { const { isMobile } = useDevice(); return ( -
+
);