forked from binary-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[P2PS] farrah/P2PS-2244/feat: copy advert (binary-com#14283)
* feat: copy ads * fix: ad menu style * fix: comments * fix: ad rate * fix: subtasks raised * fix: layout issues * fix: remove unnecessary change * fix: subtasks * fix: test * fix: switch rates * fix: switch rates flow * fix: test * fix: subtasks * fix: switch on ad edit * fix: scroll * fix: word break
- Loading branch information
1 parent
ed0a5a7
commit a46d04a
Showing
39 changed files
with
1,115 additions
and
392 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
packages/components/src/components/icon/cashier/ic-cashier-vertical-ellipsis.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 15 additions & 11 deletions
26
...-ad-cancel-modal/edit-ad-cancel-modal.tsx → ...odals/ad-cancel-modal/ad-cancel-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,40 @@ | ||
import React from 'react'; | ||
import { Button, Modal, Text } from '@deriv/components'; | ||
import { localize, Localize } from 'Components/i18next'; | ||
import { 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 = { | ||
confirm_label: string; | ||
message: string; | ||
onConfirm?: () => void; | ||
title: string; | ||
}; | ||
|
||
const AdCancelModal = ({ confirm_label, 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={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.' /> | ||
{message} | ||
</Text> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button | ||
has_effect | ||
text={localize('Cancel')} | ||
onClick={() => { | ||
hideModal(); | ||
setShowEditAdForm(false); | ||
hideModal({ should_hide_all_modals: true }); | ||
onConfirm?.(); | ||
}} | ||
secondary | ||
large | ||
/> | ||
<Button has_effect text={localize("Don't cancel")} onClick={hideModal} primary large /> | ||
<Button has_effect text={confirm_label} onClick={hideModal} primary large /> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default EditAdCancelModal; | ||
export default AdCancelModal; |
3 changes: 3 additions & 0 deletions
3
packages/p2p/src/components/modal-manager/modals/ad-cancel-modal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/p2p/src/components/modal-manager/modals/ad-created-modal/ad-created-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React from 'react'; | ||
import { Button, Checkbox, Modal, Text } from '@deriv/components'; | ||
import { localize, Localize } from 'Components/i18next'; | ||
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context'; | ||
import { api_error_codes } from 'Constants/api-error-codes'; | ||
import { useStores } from 'Stores'; | ||
|
||
type TAdCreatedModalProps = { | ||
adverts_archive_period: number; | ||
}; | ||
|
||
const AdCreatedModal = ({ adverts_archive_period }: TAdCreatedModalProps) => { | ||
const { hideModal, is_modal_open } = useModalManagerContext(); | ||
const { general_store, my_ads_store } = useStores(); | ||
const should_not_show_auto_archive_message_again = React.useRef(false); | ||
|
||
const onCheckboxChange = () => | ||
(should_not_show_auto_archive_message_again.current = !should_not_show_auto_archive_message_again.current); | ||
|
||
const onClickOkCreatedAd = () => { | ||
localStorage.setItem( | ||
'should_not_show_auto_archive_message', | ||
JSON.stringify(should_not_show_auto_archive_message_again.current) | ||
); | ||
my_ads_store.setIsAdCreatedModalVisible(false); | ||
if (my_ads_store.advert_details?.visibility_status?.includes(api_error_codes.AD_EXCEEDS_BALANCE)) { | ||
general_store.showModal({ | ||
key: 'AdVisibilityErrorModal', | ||
props: { error_code: api_error_codes.AD_EXCEEDS_BALANCE }, | ||
}); | ||
} else if (my_ads_store.advert_details?.visibility_status?.includes(api_error_codes.AD_EXCEEDS_DAILY_LIMIT)) { | ||
general_store.showModal({ | ||
key: 'AdVisibilityErrorModal', | ||
props: { error_code: api_error_codes.AD_EXCEEDS_DAILY_LIMIT }, | ||
}); | ||
} | ||
|
||
my_ads_store.setShowAdForm(false); | ||
hideModal({ should_hide_all_modals: true }); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
className='my-ads__ad-created' | ||
has_close_icon={false} | ||
is_open={is_modal_open} | ||
small | ||
title={localize("You've created an ad")} | ||
toggleModal={hideModal} | ||
> | ||
<Modal.Body> | ||
<Text as='p' size='xs' color='prominent'> | ||
<Localize | ||
i18n_default_text="If the ad doesn't receive an order for {{adverts_archive_period}} days, it will be deactivated." | ||
values={{ adverts_archive_period }} | ||
/> | ||
</Text> | ||
<br /> | ||
<Checkbox | ||
label={localize('Don’t show this message again.')} | ||
onChange={onCheckboxChange} | ||
value={should_not_show_auto_archive_message_again.current} | ||
/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button has_effect text={localize('Ok')} onClick={onClickOkCreatedAd} primary large /> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AdCreatedModal; |
3 changes: 3 additions & 0 deletions
3
packages/p2p/src/components/modal-manager/modals/ad-created-modal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import AdCreatedModal from './ad-created-modal'; | ||
|
||
export default AdCreatedModal; |
54 changes: 54 additions & 0 deletions
54
...rc/components/modal-manager/modals/copy-advert-modal/__tests__/copy-advert-modal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import { mockStore, P2PSettingsProvider, StoreProvider } from '@deriv/stores'; | ||
import { adverts } from 'Pages/my-ads/__mocks__/mock-data'; | ||
import { useStores } from 'Stores/index'; | ||
import CopyAdvertModal from '../copy-advert-modal'; | ||
|
||
const wrapper = ({ children }) => ( | ||
<StoreProvider store={mockStore({})}> | ||
<P2PSettingsProvider>{children}</P2PSettingsProvider> | ||
</StoreProvider> | ||
); | ||
|
||
const mock_store: DeepPartial<ReturnType<typeof useStores>> = { | ||
my_ads_store: { | ||
payment_method_ids: [], | ||
payment_method_names: [], | ||
setShowEditAdForm: jest.fn(), | ||
}, | ||
}; | ||
|
||
const el_modal = document.createElement('div'); | ||
|
||
jest.mock('Stores', () => ({ | ||
...jest.requireActual('Stores'), | ||
useStores: jest.fn(() => mock_store), | ||
})); | ||
|
||
jest.mock('Components/modal-manager/modal-manager-context', () => ({ | ||
...jest.requireActual('Components/modal-manager/modal-manager-context'), | ||
useModalManagerContext: jest.fn(() => ({ | ||
hideModal: jest.fn(), | ||
is_modal_open: true, | ||
})), | ||
})); | ||
|
||
describe('<CopyAdvertModal />', () => { | ||
beforeAll(() => { | ||
el_modal.setAttribute('id', 'modal_root'); | ||
document.body.appendChild(el_modal); | ||
}); | ||
|
||
afterAll(() => { | ||
document.body.removeChild(el_modal); | ||
}); | ||
|
||
it('should render CopyAdvertModal', () => { | ||
render(<CopyAdvertModal advert={adverts[0]} />, { wrapper }); | ||
|
||
expect(screen.getByText('Create a similar ad')).toBeInTheDocument(); | ||
expect(screen.getByRole('button', { name: 'Cancel' })); | ||
expect(screen.getByRole('button', { name: 'Create ad' })); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
packages/p2p/src/components/modal-manager/modals/copy-advert-modal/copy-advert-modal.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.copy-advert-modal { | ||
@include desktop { | ||
padding: 1rem 0 0; | ||
} | ||
|
||
@include mobile { | ||
padding: 1rem; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/p2p/src/components/modal-manager/modals/copy-advert-modal/copy-advert-modal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react'; | ||
import { Modal } from '@deriv/components'; | ||
import { Localize } from 'Components/i18next'; | ||
import { useModalManagerContext } from 'Components/modal-manager/modal-manager-context'; | ||
import CopyAdvertForm from 'Pages/my-ads/copy-advert-form'; | ||
import { useStores } from 'Stores'; | ||
import { TAdvert } from 'Types'; | ||
|
||
const CopyAdvertModal = ({ advert }: TAdvert) => { | ||
const { is_modal_open } = useModalManagerContext(); | ||
const { my_ads_store } = useStores(); | ||
|
||
return ( | ||
<Modal | ||
is_open={is_modal_open} | ||
small | ||
has_close_icon={false} | ||
title={<Localize i18n_default_text='Create a similar ad' />} | ||
> | ||
<Modal.Body className='copy-advert-modal'> | ||
<CopyAdvertForm advert={advert} onCancel={() => my_ads_store.setShowEditAdForm(false)} /> | ||
</Modal.Body> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default CopyAdvertModal; |
4 changes: 4 additions & 0 deletions
4
packages/p2p/src/components/modal-manager/modals/copy-advert-modal/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import CopyAdvertModal from './copy-advert-modal'; | ||
import './copy-advert-modal.scss'; | ||
|
||
export default CopyAdvertModal; |
3 changes: 0 additions & 3 deletions
3
packages/p2p/src/components/modal-manager/modals/edit-ad-cancel-modal/index.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.