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

[P2PS] farrah/P2PS-1953/feat: ad terms #13636

Merged
merged 24 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
12512ba
feat: add unavailable button
farrah-deriv Feb 16, 2024
14e39e0
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv Feb 16, 2024
2a2f2cb
fix: translation
farrah-deriv Feb 19, 2024
c1d478b
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv Feb 19, 2024
aca4d2e
feat: ad terms flow
farrah-deriv Mar 6, 2024
3ea3adf
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv Mar 7, 2024
a7d6b15
fix: review comments
farrah-deriv Mar 11, 2024
b5856f3
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv Mar 11, 2024
2236253
fix: moved eligibility function to utils
farrah-deriv Mar 12, 2024
c5816a2
fix: refactor code
farrah-deriv Mar 12, 2024
cd8ec86
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv Apr 13, 2024
179afd3
feat: add eligible countries
farrah-deriv Apr 14, 2024
af6d199
fix: test
farrah-deriv Apr 15, 2024
d53f2e1
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv Apr 22, 2024
b54eca1
fix: remove unnecessary change
farrah-deriv Apr 25, 2024
950f42a
Merge remote-tracking branch 'upstream/master' into ad-terms
farrah-deriv May 1, 2024
2791f8a
fix: subtasks
farrah-deriv May 6, 2024
4447bb9
fix: tests
farrah-deriv May 7, 2024
9c7c2b0
fix: message type
farrah-deriv May 7, 2024
28b8fac
fix: subtasks
farrah-deriv May 8, 2024
06d138f
fix: subtasks
farrah-deriv May 13, 2024
70b815c
fix: subtasks
farrah-deriv May 14, 2024
adaae77
fix: sorting of country list
farrah-deriv May 14, 2024
d3c827a
fix: subtask
farrah-deriv May 16, 2024
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
26 changes: 26 additions & 0 deletions packages/p2p/src/components/block-selector/block-selector.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.block-selector {
margin: 2rem 0;

&__label {
display: flex;
align-items: center;
column-gap: 1rem;
}

&__options {
display: flex;
column-gap: 1rem;
}

&__option {
background-color: transparent;
border: 1px solid var(--border-normal);
border-radius: 0.4rem;
padding: 0.7rem 1.6rem;
width: 12.4rem;

&--selected {
background-color: var(--general-main-3);
}
}
}
72 changes: 72 additions & 0 deletions packages/p2p/src/components/block-selector/block-selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from 'react';
import classNames from 'classnames';
import { Icon, Popover, Text } from '@deriv/components';
import { Localize } from 'Components/i18next';

type TBlockSelectorOptionProps = {
is_selected?: boolean;
name: string;
value: number;
};
type TBlockSelectorProps = {
label: string;
onSelect: (value: number) => void;
options: TBlockSelectorOptionProps[];
tooltip_info: string;
value: number;
};

const BlockSelector = ({ label, onSelect, options, tooltip_info, value }: TBlockSelectorProps) => {
const [selectors, setSelectors] = React.useState(options);
const [selected_value, setSelectedValue] = React.useState(value);
const onClick = e => {
const selected_value = e.target.getAttribute('data-value');
onSelect?.(0);
setSelectedValue(0);

const updated_selectors = selectors.map(selector => {
const is_selected = !selector.is_selected && selector.value == selected_value;

if (is_selected) {
onSelect?.(selector.value);
setSelectedValue(selector.value);
}

return { ...selector, is_selected };
});

setSelectors(updated_selectors);
};

return (
<div className='block-selector'>
<div className='block-selector__label'>
<Text color='less-prominent' size='xs' line_height='xl'>
<Localize i18n_default_text={label} />
</Text>
<Popover alignment='top' message={<Localize i18n_default_text={tooltip_info} />}>
<Icon color='disabled' icon='IcInfoOutline' />
farrah-deriv marked this conversation as resolved.
Show resolved Hide resolved
</Popover>
</div>
<div className='block-selector__options'>
{selectors.map(option => (
<Text
as='div'
align='center'
color={option.value === selected_value ? 'colored-background' : 'less-prominent'}
data-value={option.value}
key={option.name}
onClick={onClick}
className={classNames('block-selector__option', {
'block-selector__option--selected': option.value === selected_value,
})}
>
{option.name}
</Text>
))}
</div>
</div>
);
};

export default BlockSelector;
4 changes: 4 additions & 0 deletions packages/p2p/src/components/block-selector/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import BlockSelector from './block-selector';
import './block-selector.scss';

export default BlockSelector;
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import userEvent from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';
import AdCancelModal from '../ad-cancel-modal';

const mock_modal_manager = {
hideModal: jest.fn(),
is_modal_open: true,
};

jest.mock('Components/modal-manager/modal-manager-context');
const mocked_useModalManagerContext = useModalManagerContext as jest.MockedFunction<
() => Partial<ReturnType<typeof useModalManagerContext>>
>;

mocked_useModalManagerContext.mockImplementation(() => mock_modal_manager);

describe('<AdCancelModal/>', () => {
let modal_root_el: HTMLElement;
beforeAll(() => {
modal_root_el = document.createElement('div');
modal_root_el.setAttribute('id', 'modal_root');
document.body.appendChild(modal_root_el);
});

afterAll(() => {
document.body.removeChild(modal_root_el);
});
it('should render the AdCancelModal', () => {
const message = "If you choose to cancel, the details you've entered will be lost.";
const onConfirm = jest.fn();
const title = 'Cancel ad creation?';
render(<AdCancelModal message={message} onConfirm={onConfirm} title={title} />);

expect(
screen.getByText("If you choose to cancel, the details you've entered will be lost.")
).toBeInTheDocument();
expect(screen.getByText('Cancel ad creation?')).toBeInTheDocument();
});
it("should close modal on clicking Don't cancel button", () => {
const message = 'If you choose to cancel, the edited details will be lost.';
const title = 'Cancel your edits?';

render(<AdCancelModal message={message} title={title} />);

const dont_cancel_button = screen.getByText("Don't cancel");
farrah-deriv marked this conversation as resolved.
Show resolved Hide resolved
userEvent.click(dont_cancel_button);
expect(mock_modal_manager.hideModal).toHaveBeenCalled();
});
it('should call onConfirm on clicking Cancel button', () => {
const message = 'If you choose to cancel, the edited details will be lost.';
const onConfirm = jest.fn();
const title = 'Cancel your edits?';

render(<AdCancelModal message={message} onConfirm={onConfirm} title={title} />);

const cancel_button = screen.getByText('Cancel');
userEvent.click(cancel_button);
expect(onConfirm).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import React from 'react';
import { Button, Modal, Text } from '@deriv/components';
import { localize, Localize } from 'Components/i18next';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';
import { useStores } from 'Stores';

const EditAdCancelModal = () => {
const { my_ads_store } = useStores();
type TAdCancelModalProps = {
message: string;
onConfirm?: () => void;
title: string;
};

const AdCancelModal = ({ message, onConfirm, title }: TAdCancelModalProps) => {
const { hideModal, is_modal_open } = useModalManagerContext();
const { setShowEditAdForm } = my_ads_store;

return (
<Modal has_close_icon={false} is_open={is_modal_open} small title={localize('Cancel your edits?')}>
<Modal has_close_icon={false} is_open={is_modal_open} small title={localize(title)}>
<Modal.Body>
<Text as='p' size='xs' color='prominent'>
<Localize i18n_default_text='If you choose to cancel, the edited details will be lost.' />
<Localize i18n_default_text={message} />
</Text>
</Modal.Body>
<Modal.Footer>
Expand All @@ -22,7 +25,7 @@ const EditAdCancelModal = () => {
text={localize('Cancel')}
onClick={() => {
hideModal();
setShowEditAdForm(false);
onConfirm?.();
}}
secondary
large
Expand All @@ -33,4 +36,4 @@ const EditAdCancelModal = () => {
);
};

export default EditAdCancelModal;
export default AdCancelModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AdCancelModal from './ad-cancel-modal';

export default AdCancelModal;

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import PreferredCountriesModal from './preferred-countries-modal';
import './preferred-countries-modal.scss';

export default PreferredCountriesModal;
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.preferred-countries-modal {
&__search-field {
margin-bottom: 0;

input {
margin-left: 2.5rem;
}
}

&__checkbox {
padding: 1.6rem 1rem;
}
}

.dc-modal__container_preferred-countries-modal {
.dc-modal-body {
padding: 0;
}

.dc-modal-footer {
> button {
flex: 1;
}
}
}
farrah-deriv marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { Field, Form, Formik, FormikValues } from 'formik';
import { Button, Icon, Input, Modal } from '@deriv/components';
import { localize, Localize } from 'Components/i18next';
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context';

type tPreferredCountriesModal = {
onApply?: () => void;
};

const PreferredCountriesModal = ({ onApply }: tPreferredCountriesModal) => {
const { hideModal, is_modal_open } = useModalManagerContext();

return (
<Modal
className='preferred-countries-modal'
is_open={is_modal_open}
small
title={localize('Preferred countries')}
toggleModal={() => hideModal()}
>
<Modal.Body>
<Formik initialValues={{ search: '' }}>
{({ submitForm, values: { search } }) => (
<Form>
<Field name='search'>
{({ field }: FormikValues) => (
<Input
{...field}
className='preferred-countries-modal__search-field'
data-lpignore='true'
leading_icon={<Icon icon='IcSearch' />}
name='search'
onFocus={submitForm}
placeholder={localize('Search countries')}
trailing_icon={search ? <Icon color='secondary' icon='IcCloseCircle' /> : null}
type='text'
/>
)}
</Field>
</Form>
)}
</Formik>
</Modal.Body>
<Modal.Footer>
<Button large onClick={hideModal} secondary>
<Localize i18n_default_text='Clear' />
</Button>
<Button primary large onClick={onApply}>
<Localize i18n_default_text='Apply' />
</Button>
</Modal.Footer>
</Modal>
);
};
export default PreferredCountriesModal;
15 changes: 9 additions & 6 deletions packages/p2p/src/constants/modals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React from 'react';

export const Modals = {
AdCancelModal: React.lazy(
() => import(/* webpackChunkName: "ad-cancel-modal" */ 'Components/modal-manager/modals/ad-cancel-modal')
),
AdCreateEditErrorModal: React.lazy(
() =>
import(
Expand Down Expand Up @@ -85,12 +88,6 @@ export const Modals = {
DisclaimerModal: React.lazy(
() => import(/* webpackChunkName: "disclaimer-modal" */ 'Components/modal-manager/modals/disclaimer-modal')
),
EditAdCancelModal: React.lazy(
() =>
import(
/* webpackChunkName: "edit-ad-cancel-modal" */ 'Components/modal-manager/modals/edit-ad-cancel-modal'
)
),
EmailLinkBlockedModal: React.lazy(
() =>
import(
Expand Down Expand Up @@ -182,6 +179,12 @@ export const Modals = {
/* webpackChunkName: "order-time-tooltip-modal" */ 'Components/modal-manager/modals/order-time-tooltip-modal'
)
),
PreferredCountriesModal: React.lazy(
() =>
import(
/* webpackChunkName: "preferred-countries-modal" */ 'Components/modal-manager/modals/preferred-countries-modal'
)
),
QuickAddModal: React.lazy(
() => import(/* webpackChunkName: "quick-add-modal" */ 'Components/modal-manager/modals/quick-add-modal')
),
Expand Down
Loading