Skip to content

Commit

Permalink
feat: added OrderDetailsCancelModal
Browse files Browse the repository at this point in the history
  • Loading branch information
ameerul-deriv committed Apr 29, 2024
1 parent f28751e commit c0c3532
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 10 deletions.
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: -4rem;
left: 0;
z-index: 1;
height: calc(100vh - 8rem);
height: calc(100vh - 4rem);

& .mobile-wrapper__body {
overflow: auto;
Expand Down
2 changes: 1 addition & 1 deletion src/components/BuySellForm/BuySellForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const BuySellForm = ({

useEffect(() => {
if (isSuccess && orderCreatedInfo) {
history.push(`${ORDERS_URL}/${orderCreatedInfo.id}`);
history.push(`${ORDERS_URL}/${orderCreatedInfo.id}`, { from: 'BuySell' });
onRequestClose();
}
}, [isSuccess, orderCreatedInfo, history, onRequestClose]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.order-details-cancel-modal {
height: auto;
width: 44rem;
border-radius: 8px;

@include mobile {
width: 32.8rem;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { api } from '@/hooks';
import { Button, Modal, Text, useDevice } from '@deriv-com/ui';
import './OrderDetailsCancelModal.scss';

type TOrderDetailsCancelModalProps = {
id: string;
isModalOpen: boolean;
onRequestClose: () => void;
};

const OrderDetailsCancelModal = ({ id, isModalOpen, onRequestClose }: TOrderDetailsCancelModalProps) => {
const { data } = api.settings.useSettings();
const { data: advertiserInfo } = api.advertiser.useGetInfo();
const { mutate } = api.order.useCancel();
const { isMobile } = useDevice();
const textSize = isMobile ? 'md' : 'sm';

const onCancel = () => {
mutate({ id });
onRequestClose();
};

return (
<Modal className='order-details-cancel-modal' isOpen={isModalOpen}>
<Modal.Header className='lg:px-[2.4rem] px-[1.6rem]' hideBorder hideCloseIcon>
<Text weight='bold'>Do you want to cancel this order?</Text>
</Modal.Header>
<Modal.Body className='flex flex-col gap-2 lg:px-[2.4rem] px-[1.6rem]'>
<Text size='sm'>
If you cancel your order {data?.cancellation_limit} times in {data?.cancellation_count_period}{' '}
hours, you will be blocked from using Deriv P2P for {data?.cancellation_block_duration} hours.
<br />({advertiserInfo.cancels_remaining} cancellations remaining)
</Text>
<Text color='error' size='sm'>
Please do not cancel if you have already made payment.
</Text>
</Modal.Body>
<Modal.Footer className='gap-4 lg:px-[2.4rem] px-[1.6rem]' hideBorder>
<Button
className='border-2'
color='black'
onClick={onCancel}
size='lg'
textSize={textSize}
variant='outlined'
>
Cancel this order
</Button>
<Button onClick={onRequestClose} size='lg' textSize={textSize}>
Do not cancel
</Button>
</Modal.Footer>
</Modal>
);
};

export default OrderDetailsCancelModal;
1 change: 1 addition & 0 deletions src/components/Modals/OrderDetailsCancelModal/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as OrderDetailsCancelModal } from './OrderDetailsCancelModal';
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const OrderDetailsComplainModal = ({

const onCheckboxChange = (reason: string) => setDisputeReason(reason);

if (isMobile)
if (isMobile && isModalOpen)
return (
<FullPageMobileWrapper
className='order-details-complain-modal'
Expand Down
1 change: 1 addition & 0 deletions src/components/Modals/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './ErrorModal';
export * from './FilterModal';
export * from './MyAdsDeleteModal';
export * from './NicknameModal';
export * from './OrderDetailsCancelModal';
export * from './OrderDetailsComplainModal';
export * from './OrderDetailsConfirmModal';
export * from './OrderTimeTooltipModal';
Expand Down
1 change: 1 addition & 0 deletions src/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ html,
body {
font-family: 'IBM Plex Sans', sans-serif;
font-size: 10px;
overflow: hidden;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OrderDetailsComplainModal } from '@/components/Modals';
import { OrderDetailsCancelModal, OrderDetailsComplainModal } from '@/components/Modals';
import { useModalManager } from '@/hooks/custom-hooks';
import { useOrderDetails } from '@/providers/OrderDetailsProvider';
import { Button, useDevice } from '@deriv-com/ui';
Expand Down Expand Up @@ -32,7 +32,14 @@ const OrderDetailsCardFooter = () => {
<div className='order-details-card-footer'>
{shouldShowCancelAndPaidButton && (
<div className='flex gap-3 ml-auto'>
<Button className='border-2' color='black' size='lg' textSize={textSize} variant='outlined'>
<Button
className='border-2'
color='black'
onClick={() => showModal('OrderDetailsCancelModal')}
size='lg'
textSize={textSize}
variant='outlined'
>
Cancel order
</Button>
<Button size='lg' textSize={textSize}>
Expand Down Expand Up @@ -84,6 +91,11 @@ const OrderDetailsCardFooter = () => {
isModalOpen={!!isModalOpenFor('OrderDetailsComplainModal')}
onRequestClose={hideModal}
/>
<OrderDetailsCancelModal
id={id}
isModalOpen={!!isModalOpenFor('OrderDetailsCancelModal')}
onRequestClose={hideModal}
/>
</div>
);
};
Expand Down
5 changes: 2 additions & 3 deletions src/pages/orders/screens/OrderDetails/OrderDetails.scss
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
.order-details {
overflow-y: scroll;
overflow-x: hidden;
overflow: overlay;
height: calc(100vh - 28rem);

@include mobile {
position: absolute;
top: 4rem;
height: calc(100vh - 7.4rem);
height: calc(100vh - 3.5rem);

& .mobile-wrapper {
&__header {
Expand Down
8 changes: 7 additions & 1 deletion src/pages/orders/screens/OrderDetails/OrderDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react';
import { useHistory, useLocation, useParams } from 'react-router-dom';
import { FullPageMobileWrapper, PageReturn } from '@/components';
import { BUY_SELL_URL, ORDERS_URL } from '@/constants';
import { api } from '@/hooks';
import { useExtendedOrderDetails } from '@/hooks/custom-hooks';
import { ExtendedOrderDetails } from '@/hooks/custom-hooks/useExtendedOrderDetails';
Expand Down Expand Up @@ -35,7 +36,12 @@ const OrderDetails = () => {
const headerText = `${isBuyOrderForUser ? 'Buy' : 'Sell'} USD order`;
const warningMessage = 'Don’t risk your funds with cash transactions. Use bank transfers or e-wallets instead.';

const onReturn = () => history.goBack();
const onReturn = () => {
if ((location.state as { from: string })?.from === 'Orders') history.push(ORDERS_URL);
else if ((location.state as { from: string })?.from === 'BuySell') history.push(BUY_SELL_URL);
else history.goBack();
};

const onChatReturn = () => {
setShowChat(false);
if (showChatParam) onReturn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const OrdersTableRow = ({ ...props }: DeepPartial<THooks.Order.GetList[number]>)
const isBuyOrderForUser = orderDetails.isBuyOrderForUser;
const transactionAmount = `${Number(priceDisplay).toFixed(2)} ${localCurrency}`;
const offerAmount = `${amountDisplay} ${accountCurrency}`;
const showOrderDetails = () => history.push(`${ORDERS_URL}/${id}`);
const showOrderDetails = () => history.push(`${ORDERS_URL}/${id}`, { from: 'Orders' });

if (isMobile) {
return (
Expand Down

0 comments on commit c0c3532

Please sign in to comment.