Skip to content

Commit

Permalink
Merge pull request #108 from nada-deriv/nada/FEQ-2340/buy-sell-issues
Browse files Browse the repository at this point in the history
nada/fix: ui issues in buy sell flow
  • Loading branch information
farrah-deriv authored Jun 7, 2024
2 parents 8d502a2 + 64bfbfc commit 985f8b8
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/components/AdvertsTableRow/AdvertsTableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ const AdvertsTableRow = memo((props: TAdvertsTableRowRenderer) => {
{payment_method_names ? (
payment_method_names.map((method: string, idx: number) => (
<PaymentMethodLabel
color={textColor}
color='general'
key={idx}
paymentMethodName={method}
size={isMobile ? 'sm' : 'xs'}
size={isMobile ? 'xs' : 'sm'}
/>
))
) : (
<PaymentMethodLabel color={textColor} paymentMethodName='-' />
<PaymentMethodLabel color='general' paymentMethodName='-' />
)}
</div>
</Container>
Expand Down
5 changes: 4 additions & 1 deletion src/components/BuySellForm/BuySellAmount/BuySellAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type TBuySellAmountProps = {
minLimit: string;
paymentMethodNames?: string[];
setValue: ReturnType<typeof useForm>['setValue'];
trigger: ReturnType<typeof useForm>['trigger'];
};
const BuySellAmount = ({
accountCurrency,
Expand All @@ -33,6 +34,7 @@ const BuySellAmount = ({
minLimit,
paymentMethodNames,
setValue,
trigger,
}: TBuySellAmountProps) => {
const { isMobile } = useDevice();
const labelSize = isMobile ? 'sm' : 'xs';
Expand All @@ -52,7 +54,8 @@ const BuySellAmount = ({
useEffect(() => {
setInputValue(minLimit);
setValue('amount', minLimit);
}, [minLimit, setValue]);
trigger('amount');
}, [minLimit, setValue, trigger]);

return (
<div className='flex flex-col gap-[2rem] py-[1.6rem]'>
Expand Down
2 changes: 1 addition & 1 deletion src/components/BuySellForm/BuySellForm.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
top: 0;
left: 0;
z-index: 1;
height: calc(100vh - 4rem);
height: calc(100vh - 7rem);

& .mobile-wrapper__body {
overflow: overlay;
Expand Down
5 changes: 5 additions & 0 deletions src/components/BuySellForm/BuySellForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const BuySellForm = ({ advertId, isModalOpen, onRequestClose }: TBuySellFormProp
const { data } = api.advertiser.useGetInfo() || {};
const [errorMessage, setErrorMessage] = useState('');
const scrollRef = useRef<HTMLDivElement>(null);
const [isHidden, setIsHidden] = useState(false);
const {
balance_available = '',
daily_buy = 0,
Expand Down Expand Up @@ -154,6 +155,7 @@ const BuySellForm = ({ advertId, isModalOpen, onRequestClose }: TBuySellFormProp
getValues,
handleSubmit,
setValue,
trigger,
} = useForm({
defaultValues: {
amount: min_order_amount_limit ?? 1,
Expand Down Expand Up @@ -224,6 +226,7 @@ const BuySellForm = ({ advertId, isModalOpen, onRequestClose }: TBuySellFormProp
<BuySellFormDisplayWrapper
accountCurrency={account_currency as TCurrency}
isBuy={isBuy}
isHidden={isHidden}
isModalOpen={isModalOpen}
isValid={isValid && ((isBuy && selectedPaymentMethods.length > 0) || !isBuy)}
onRequestClose={onRequestClose}
Expand Down Expand Up @@ -264,6 +267,7 @@ const BuySellForm = ({ advertId, isModalOpen, onRequestClose }: TBuySellFormProp
availablePaymentMethods={availablePaymentMethods as TPaymentMethod[]}
onSelectPaymentMethodCard={onSelectPaymentMethodCard}
selectedPaymentMethodIds={selectedPaymentMethods}
setIsHidden={setIsHidden}
/>
)}
<BuySellAmount
Expand All @@ -283,6 +287,7 @@ const BuySellForm = ({ advertId, isModalOpen, onRequestClose }: TBuySellFormProp
minLimit={min_order_amount_limit_display ?? '0'}
paymentMethodNames={payment_method_names}
setValue={setValue as unknown as (name: string, value: string) => void}
trigger={trigger as unknown as () => Promise<boolean>}
/>
</BuySellFormDisplayWrapper>
</form>
Expand Down
5 changes: 4 additions & 1 deletion src/components/BuySellForm/BuySellFormDisplayWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { BuySellFormHeader } from './BuySellFormHeader';
type TBuySellFormDisplayWrapperProps = {
accountCurrency: string;
isBuy: boolean;
isHidden: boolean;
isModalOpen: boolean;
isValid: boolean;
onRequestClose: () => void;
Expand All @@ -18,6 +19,7 @@ const BuySellFormDisplayWrapper = ({
accountCurrency,
children,
isBuy,
isHidden,
isModalOpen,
isValid,
onRequestClose,
Expand All @@ -44,10 +46,11 @@ const BuySellFormDisplayWrapper = ({
return (
<Modal
ariaHideApp={false}
className={clsx('buy-sell-form', { 'buy-sell-form--is-buy': isBuy })}
className={clsx('buy-sell-form', { 'buy-sell-form--is-buy': isBuy, hidden: isHidden })}
isOpen={isModalOpen}
onRequestClose={onRequestClose}
shouldCloseOnOverlayClick={false}
style={{ overlay: { background: isHidden ? 'transparent' : 'rgba(0, 0, 0, 0.72)', zIndex: 9999 } }}
>
<Modal.Header onRequestClose={onRequestClose}>
<BuySellFormHeader currency={accountCurrency} isBuy={isBuy} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useReducer } from 'react';
import { Dispatch, SetStateAction, useCallback, useReducer } from 'react';
import { TPaymentMethod, TSelectedPaymentMethod } from 'types';
import { LightDivider, PaymentMethodForm } from '@/components';
import { useModalManager } from '@/hooks';
Expand All @@ -12,12 +12,14 @@ type TBuySellPaymentSectionProps = {
availablePaymentMethods: (TPaymentMethod & { isAvailable?: boolean })[];
onSelectPaymentMethodCard?: (paymentMethodId: number) => void;
selectedPaymentMethodIds: number[];
setIsHidden?: Dispatch<SetStateAction<boolean>>;
};

const BuySellPaymentSection = ({
availablePaymentMethods,
onSelectPaymentMethodCard,
selectedPaymentMethodIds,
setIsHidden,
}: TBuySellPaymentSectionProps) => {
const { isMobile } = useDevice();
const sortedList = sortPaymentMethodsWithAvailability(availablePaymentMethods);
Expand Down Expand Up @@ -61,6 +63,7 @@ const BuySellPaymentSection = ({
key={index}
medium
onClickAdd={() => {
setIsHidden?.(true);
showModal('PaymentMethodForm', { shouldStackModals: false });
handleAddPaymentMethod(paymentMethod?.display_name, paymentMethod);
}}
Expand All @@ -76,7 +79,10 @@ const BuySellPaymentSection = ({
<PaymentMethodForm
displayModal={!isMobile && !!isModalOpenFor('PaymentMethodForm')}
formState={formState}
onRequestClose={hideModal}
onRequestClose={() => {
hideModal();
setIsHidden?.(false);
}}
onResetFormState={handleResetFormState}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,22 @@ describe('<BuySellPaymentSection />', () => {
expect(mockUseModalManager.showModal).toHaveBeenCalledWith('PaymentMethodForm', { shouldStackModals: false });
expect(screen.getByText('PaymentMethodForm')).toBeInTheDocument();
});

it('should hide the background modal when setishidden is passed', async () => {
const setIsHidden = jest.fn();
mockAvailablePaymentMethods.isAvailable = false;
mockUseModalManager.isModalOpenFor.mockImplementation((modal: string) => modal === 'PaymentMethodForm');
render(
<BuySellPaymentSection
{...mockProps}
availablePaymentMethods={[mockAvailablePaymentMethods]}
setIsHidden={setIsHidden}
/>
);

const addButton = screen.getByTestId('dt_payment_method_add_button');
await userEvent.click(addButton);
expect(mockUseModalManager.showModal).toHaveBeenCalledWith('PaymentMethodForm', { shouldStackModals: false });
expect(setIsHidden).toHaveBeenCalledWith(true);
});
});
1 change: 1 addition & 0 deletions src/components/BuySellForm/__tests__/BuySellForm.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ jest.mock('react-hook-form', () => ({
})),
handleSubmit: mockHandleSubmit,
setValue: jest.fn(),
trigger: jest.fn(),
}),
}));

Expand Down
6 changes: 6 additions & 0 deletions src/pages/advertiser/screens/Advertiser/Advertiser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
height: calc(100vh - 4rem);
width: 100%;
}

& .page-return {
@include mobile {
padding: 0.5rem 1.6rem;
}
}
}
1 change: 1 addition & 0 deletions src/pages/advertiser/screens/Advertiser/Advertiser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const Advertiser = () => {
/>
),
})}
size={isMobile ? 'lg' : 'md'}
weight='bold'
/>
<AdvertiserBlockOverlay
Expand Down

0 comments on commit 985f8b8

Please sign in to comment.