Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nada/fix: style issue in ad create, add balance info #101

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/pages/my-ads/components/AdFormInput/AdFormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Input } from '@deriv-com/ui';

type TAdFormInputProps = ComponentProps<typeof Input> & {
currency?: string;
hint?: JSX.Element | string;
isDisabled?: boolean;
label: string;
name: string;
Expand All @@ -14,6 +15,7 @@ type TAdFormInputProps = ComponentProps<typeof Input> & {
};

const AdFormInput = ({
hint = <div />,
isDisabled = false,
label,
name,
Expand All @@ -33,7 +35,7 @@ const AdFormInput = ({
disabled={isDisabled}
error={!!error?.message}
label={label}
message={error ? error?.message : ''}
message={error ? error?.message : hint}
onBlur={onBlur}
onChange={event => {
onChange(event);
Expand Down
14 changes: 14 additions & 0 deletions src/pages/my-ads/components/AdTypeSection/AdTypeSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Controller, useFormContext } from 'react-hook-form';
import { TCurrency } from 'types';
import { FloatingRate, RadioGroup } from '@/components';
import { BUY_SELL, RATE_TYPE } from '@/constants';
import { api } from '@/hooks';
import { useQueryString } from '@/hooks/custom-hooks';
import { getValidationRules, restrictDecimalPlace } from '@/utils';
import { useTranslations } from '@deriv-com/translations';
import { Text, useDevice } from '@deriv-com/ui';
import { FormatUtils } from '@deriv-com/utils';
import { AdFormController } from '../AdFormController';
import { AdFormInput } from '../AdFormInput';
import { AdFormTextArea } from '../AdFormTextArea';
Expand All @@ -25,6 +27,8 @@ type TAdTypeSectionProps = {

const AdTypeSection = ({ currency, localCurrency, onCancel, rateType, ...props }: TAdTypeSectionProps) => {
const { queryString } = useQueryString();
const { data: advertiserInfo } = api.advertiser.useGetInfo();
const { balance_available: balanceAvailable } = advertiserInfo || {};
const { localize } = useTranslations();
const { advertId = '' } = queryString;
const isEdit = !!advertId;
Expand Down Expand Up @@ -95,6 +99,16 @@ const AdTypeSection = ({ currency, localCurrency, onCancel, rateType, ...props }
)}
<div className='flex flex-col lg:flex-row lg:gap-[1.6rem]'>
<AdFormInput
hint={
isSell ? (
localize('Your Deriv P2P balance is {{balance}} {{currency}}', {
balance: FormatUtils.formatMoney(balanceAvailable ?? 0, { currency }),
currency,
})
) : (
<div />
)
}
isDisabled={isEdit}
label={localize('Total amount')}
name='amount'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ jest.mock('@/hooks/custom-hooks', () => ({
useQueryString: jest.fn().mockReturnValue({ queryString: { advertId: '' } }),
}));

jest.mock('@/hooks', () => ({
...jest.requireActual('@/hooks'),
api: {
advertiser: {
useGetInfo: jest.fn(() => ({
data: {
balance_available: 1000,
},
})),
},
},
}));

const mockProps = {
currency: 'usd' as TCurrency,
getCurrentStep: jest.fn(() => 1),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.order-time-selection {
margin: 1rem 0;
}

@include mobile {
#react-tiny-popover-container {
display: none;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { OrderTimeTooltipModal } from '@/components/Modals';
import { getOrderTimeCompletionList, getOrderTimeInfoMessage } from '@/constants';
import { LabelPairedChevronDownMdRegularIcon, LabelPairedCircleInfoCaptionRegularIcon } from '@deriv/quill-icons';
import { Localize, useTranslations } from '@deriv-com/translations';
import { Button, Dropdown, Text, Tooltip, useDevice } from '@deriv-com/ui';
import { Dropdown, Text, TooltipMenuIcon, useDevice } from '@deriv-com/ui';
import './OrderTimeSelection.scss';

const OrderTimeSelection = () => {
const { control } = useFormContext();
Expand All @@ -14,26 +15,25 @@ const OrderTimeSelection = () => {
const { localize } = useTranslations();

return (
<div className='my-4'>
<div className='order-time-selection'>
<div className='flex items-center gap-[0.8rem]'>
<Text color='prominent' size={isMobile ? 'md' : 'sm'}>
<Localize i18n_default_text='Orders must be completed in' />
</Text>
<Text size='xs'>
<Tooltip className='max-w-none' message={getOrderTimeInfoMessage(localize)} position='top'>
<Button
color='white'
onClick={isMobile ? () => setIsModalOpen(true) : () => undefined}
type='button'
variant='contained'
>
<LabelPairedCircleInfoCaptionRegularIcon
data-testid='dt_order_info_icon'
height={24}
width={24}
/>
</Button>
</Tooltip>
<TooltipMenuIcon
as='button'
disableHover
onClick={isMobile ? () => setIsModalOpen(true) : () => undefined}
tooltipContent={getOrderTimeInfoMessage(localize)}
type='button'
>
<LabelPairedCircleInfoCaptionRegularIcon
data-testid='dt_order_info_icon'
height={24}
width={24}
/>
</TooltipMenuIcon>
</Text>
</div>
<Controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ jest.mock('@/hooks', () => ({
mutate: jest.fn(),
}),
},
advertiser: {
useGetInfo: jest.fn(() => ({
data: {
balance_available: 1000,
},
})),
},
countryList: {
useGet: () => ({
data: {
Expand Down
Loading