Skip to content

Commit

Permalink
Artsem / Disable popovers + change color if user is barred (#5191)
Browse files Browse the repository at this point in the history
* disable popovers + change color if user is barred

* DRY for add payment method functionality

* remove redundant condition

* replace condition check from component to store

Co-authored-by: Carol Sachdeva <58209918+carol-binary@users.noreply.github.com>
  • Loading branch information
artsemkavaleu-binary and carolsachdeva committed Apr 28, 2022
1 parent 401f25e commit 5360d58
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 38 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 24 additions & 23 deletions packages/p2p/src/components/my-ads/my-ads-row-renderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ const MyAdsRowRenderer = observer(({ row: advert, setAdvert }) => {
const amount_dealt = amount - remaining_amount;
const is_buy_advert = type === buy_sell.BUY;

const onClickActivateDeactivate = () => {
my_ads_store.onClickActivateDeactivate(id, is_advert_active, setIsAdvertActive);
const onClickAddPaymentMethod = () => {
if (!general_store.is_barred) {
setAdvert(advert);
my_ads_store.showQuickAddModal(advert);
}
};
const onClickDelete = () => !general_store.is_barred && my_ads_store.onClickDelete(id);
const onClickEdit = () => !general_store.is_barred && my_ads_store.onClickEdit(id);
const onClickActivateDeactivate = () =>
my_ads_store.onClickActivateDeactivate(id, is_advert_active, setIsAdvertActive);
const onClickDelete = () => my_ads_store.onClickDelete(id);
const onClickEdit = () => my_ads_store.onClickEdit(id);
const onMouseEnter = () => setIsPopoverActionsVisible(true);
const onMouseLeave = () => setIsPopoverActionsVisible(false);

Expand Down Expand Up @@ -159,15 +164,13 @@ const MyAdsRowRenderer = observer(({ row: advert, setAdvert }) => {
);
})
) : (
<div
className='p2p-my-ads__table-add'
onClick={() => {
setAdvert(advert);
my_ads_store.showQuickAddModal(advert);
}}
>
<Icon icon='IcAdd' />
<Text color='prominent' size='xxs' weight='bold'>
<div className='p2p-my-ads__table-add' onClick={onClickAddPaymentMethod}>
<Icon color={general_store.is_barred && 'disabled'} icon='IcAdd' />
<Text
color={general_store.is_barred ? 'less-prominent' : 'prominent'}
size='xxs'
weight='bold'
>
<Localize i18n_default_text='Add' />
</Text>
</div>
Expand Down Expand Up @@ -224,15 +227,13 @@ const MyAdsRowRenderer = observer(({ row: advert, setAdvert }) => {
);
})
) : (
<div
className='p2p-my-ads__table-add'
onClick={() => {
setAdvert(advert);
my_ads_store.showQuickAddModal(advert);
}}
>
<Icon icon='IcAdd' />
<Text color='prominent' size='xxs' weight='bold'>
<div className='p2p-my-ads__table-add' onClick={onClickAddPaymentMethod}>
<Icon color={general_store.is_barred && 'disabled'} icon='IcAdd' />
<Text
color={general_store.is_barred ? 'less-prominent' : 'prominent'}
size='xxs'
weight='bold'
>
<Localize i18n_default_text='Add' />
</Text>
</div>
Expand Down Expand Up @@ -281,7 +282,7 @@ const MyAdsRowRenderer = observer(({ row: advert, setAdvert }) => {
className='p2p-my-ads__table-popovers__edit'
message={localize('Edit')}
>
<Icon icon='IcEdit' size={16} />
<Icon icon='IcEdit' color={general_store.is_barred && 'disabled'} size={16} />
</Popover>
</div>
<div onClick={onClickDelete}>
Expand Down
32 changes: 19 additions & 13 deletions packages/p2p/src/stores/my-ads-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,16 @@ export default class MyAdsStore extends BaseStore {
@action.bound
onClickActivateDeactivate(id, is_ad_active, setIsAdvertActive) {
requestWS({ p2p_advert_update: 1, id, is_active: is_ad_active ? 0 : 1 }).then(response => {
if (response.error) {
this.setActivateDeactivateErrorMessage(response.error.message);
} else {
setIsAdvertActive(!!response.p2p_advert_update.is_active);
}
this.setSelectedAdId('');
});
if (!this.root_store.general_store.is_barred) {
requestWS({ p2p_advert_update: 1, id, is_active: is_ad_active ? 0 : 1 }).then(response => {
if (response.error) {
this.setActivateDeactivateErrorMessage(response.error.message);
} else {
setIsAdvertActive(!!response.p2p_advert_update.is_active);
}
this.setSelectedAdId('');
});
}
}
@action.bound
Expand Down Expand Up @@ -226,15 +228,19 @@ export default class MyAdsStore extends BaseStore {
@action.bound
onClickDelete(id) {
this.setSelectedAdId(id);
this.setIsDeleteModalOpen(true);
if (!this.root_store.general_store.is_barred) {
this.setSelectedAdId(id);
this.setIsDeleteModalOpen(true);
}
}
@action.bound
onClickEdit(id) {
this.setSelectedAdId(id);
this.setShowEditAdForm(true);
this.getAdvertInfo();
if (!this.root_store.general_store.is_barred) {
this.setSelectedAdId(id);
this.setShowEditAdForm(true);
this.getAdvertInfo();
}
}
@action.bound
Expand Down

1 comment on commit 5360d58

@vercel
Copy link

@vercel vercel bot commented on 5360d58 Apr 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-app – ./

deriv-app.vercel.app
binary.sx
deriv-app.binary.sx
deriv-app-git-master.binary.sx

Please sign in to comment.