Skip to content

Commit

Permalink
Ameerul /Task #65487 Dropdown Block User Feature (#5682)
Browse files Browse the repository at this point in the history
* added dropdown, menu dots icon, added function for users to block advertisers with block user modal

* refactored code, and renamed dropdown component to advertiser-page-dropdown-menu

* renamed variables and functions according to comments

* refactored block user function in advertiser-page-store and block-user-modal

* minor changes to the imports

* merged with master and added changes

* removed old blockUser and showModal functions from advertiser store

* removed is_blocked from dropdown

* refactored code with comments

* moved showBlockUserModal function to the store

* removed curly brackets in name

* fixed gap in modal

* fixed tooltip message and user cannot block themselves

* fixed dropdown darkmode design and hid menu dots icon when user is blocked

* changed dropdown hover colour

* added useOnClickOutisde Hook to hide dropdown when clicked outside
  • Loading branch information
ameerul-deriv committed Aug 9, 2022
1 parent 4211075 commit f17d1d2
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 36 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions packages/components/src/components/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ import './common/ic-lookbacks.svg';
import './common/ic-loss.svg';
import './common/ic-macos-logo.svg';
import './common/ic-macos.svg';
import './common/ic-menu-dots.svg';
import './common/ic-message-delivered.svg';
import './common/ic-message-errored.svg';
import './common/ic-message-pending.svg';
Expand Down
31 changes: 16 additions & 15 deletions packages/components/stories/icon/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const icons =
'IcBrandDmt5',
'IcBrandDtrader',
'IcBrandDxtrade',
'IcBrandSmarttrader',
'IcBrandSmarttrader'
],
'cashier': [
'IcCashierAdd',
Expand Down Expand Up @@ -141,7 +141,7 @@ export const icons =
'IcCashierXanpoolLight',
'IcCashierXanpoolSmallDark',
'IcCashierXanpoolSmallLight',
'IcCashier',
'IcCashier'
],
'common': [
'IcAccountError',
Expand Down Expand Up @@ -290,6 +290,7 @@ export const icons =
'IcLoss',
'IcMacosLogo',
'IcMacos',
'IcMenuDots',
'IcMessageDelivered',
'IcMessageErrored',
'IcMessagePending',
Expand Down Expand Up @@ -394,7 +395,7 @@ export const icons =
'IcWindows',
'IcWip',
'IcZoomIn',
'IcZoomOut',
'IcZoomOut'
],
'contract': [
'IcContractBarrier',
Expand All @@ -410,7 +411,7 @@ export const icons =
'IcContractSafeguard',
'IcContractStartTimeCircle',
'IcContractStartTime',
'IcContractTarget',
'IcContractTarget'
],
'currency': [
'IcCurrencyAud',
Expand All @@ -432,7 +433,7 @@ export const icons =
'IcCurrencyUsdc',
'IcCurrencyUsdk',
'IcCurrencyUst',
'IcCurrencyVirtual',
'IcCurrencyVirtual'
],
'dxtrade': [
'IcDxtradeDeviceDesktopLight',
Expand All @@ -447,7 +448,7 @@ export const icons =
'IcDxtradeFinancial',
'IcDxtradeOnePassword',
'IcDxtradeSyntheticPlatform',
'IcDxtradeSynthetic',
'IcDxtradeSynthetic'
],
'flag': [
'IcFlagDe',
Expand All @@ -463,7 +464,7 @@ export const icons =
'IcFlagUk',
'IcFlagVi',
'IcFlagZhCn',
'IcFlagZhTw',
'IcFlagZhTw'
],
'mt5': [
'IcMt5CfdPlatform',
Expand All @@ -490,7 +491,7 @@ export const icons =
'IcMt5SyntheticIndices',
'IcMt5SyntheticPlatform',
'IcMt5Synthetic',
'IcMt5TradeTypes',
'IcMt5TradeTypes'
],
'option': [
'IcOptionCallPutReset',
Expand All @@ -508,7 +509,7 @@ export const icons =
'IcOptionRaiseFall',
'IcOptionStayinGoesout',
'IcOptionTouchNotouch',
'IcOptionUpDownAsian',
'IcOptionUpDownAsian'
],
'stock': [
'IcStockAdidasSalomon',
Expand Down Expand Up @@ -558,7 +559,7 @@ export const icons =
'IcStockVisa',
'IcStockWallMart',
'IcStockWaltDisney',
'IcStockZoom',
'IcStockZoom'
],
'tradetype': [
'IcTradetypeAsiand',
Expand Down Expand Up @@ -593,7 +594,7 @@ export const icons =
'IcTradetypeRunlow',
'IcTradetypeTickhigh',
'IcTradetypeTicklow',
'IcTradetypeUpordown',
'IcTradetypeUpordown'
],
'underlying': [
'IcUnderlying1HZ100V',
Expand Down Expand Up @@ -750,7 +751,7 @@ export const icons =
'IcUnderlyingWLDEUR',
'IcUnderlyingWLDGBP',
'IcUnderlyingWLDUSD',
'IcUnderlyingWLDXAU',
'IcUnderlyingWLDXAU'
],
'wallet': [
'IcWalletClearFunds',
Expand Down Expand Up @@ -786,6 +787,6 @@ export const icons =
'IcWalletWebmoneyLight',
'IcWalletWebmoney',
'IcWalletZingpayDark',
'IcWalletZingpayLight',
],
}
'IcWalletZingpayLight'
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { observer } from 'mobx-react-lite';
import PropTypes from 'prop-types';
import { Dropdown, Icon, Text } from '@deriv/components';
import { Localize } from 'Components/i18next';
import { useStores } from 'Stores';
import { useOnClickOutside } from '../../../../components/src/hooks';
import './advertiser-page.scss';

const AdvertiserPageDropdownMenu = ({ is_my_advert }) => {
const dropdown_menu_ref = React.useRef();
const { advertiser_page_store } = useStores();

const onClickOutside = () => {
advertiser_page_store.setIsDropdownMenuVisible(false);
};

useOnClickOutside(dropdown_menu_ref, onClickOutside, () => advertiser_page_store.is_dropdown_menu_visible);

return (
!advertiser_page_store.is_counterparty_advertiser_blocked && (
<div className='advertiser-page__menu-dots-toggle'>
<Icon
className='advertiser-page__menu-dots-icon'
icon='IcMenuDots'
onClick={() =>
advertiser_page_store.setIsDropdownMenuVisible(!advertiser_page_store.is_dropdown_menu_visible)
}
size={16}
/>
{advertiser_page_store.is_dropdown_menu_visible && (
<div
ref={dropdown_menu_ref}
className='advertiser-page__dropdown'
onClick={advertiser_page_store.showBlockUserModal}
>
<Dropdown
className={`advertiser-page__dropdown-container${is_my_advert ? '--disabled' : ''}`}
is_align_text_right
list={['Block']}
name='block_user_dropdown'
placeholder={
<Text
color={
advertiser_page_store.is_counterparty_advertiser_blocked
? 'less-prominent'
: 'prominent'
}
size='xs'
>
<Localize i18n_default_text='Block' />
</Text>
}
/>
</div>
)}
</div>
)
);
};

export default observer(AdvertiserPageDropdownMenu);

AdvertiserPageDropdownMenu.propTypes = {
is_my_advert: PropTypes.bool,
};
35 changes: 22 additions & 13 deletions packages/p2p/src/components/advertiser-page/advertiser-page.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Loading, Text } from '@deriv/components';
import { DesktopWrapper, Loading, MobileWrapper, Text } from '@deriv/components';
import { daysSince, isMobile } from '@deriv/shared';
import { reaction } from 'mobx';
import { observer } from 'mobx-react-lite';
Expand All @@ -13,6 +13,7 @@ import UserAvatar from 'Components/user/user-avatar/user-avatar.jsx';
import { useStores } from 'Stores';
import AdvertiserPageStats from './advertiser-page-stats.jsx';
import AdvertiserPageAdverts from './advertiser-page-adverts.jsx';
import AdvertiserPageDropdownMenu from './advertiser-page-dropdown-menu.jsx';
import TradeBadge from '../trade-badge/trade-badge.jsx';
import BlockUserOverlay from './block-user/block-user-overlay';
import BlockUserModal from 'Components/block-user/block-user-modal';
Expand All @@ -28,13 +29,17 @@ const AdvertiserPage = () => {
created_time,
first_name,
full_verification,
id,
last_name,
name,
sell_orders_count,
} = advertiser_page_store.advertiser_info;
const joined_since = daysSince(created_time);
const is_my_advert = id === general_store.advertiser_id;

React.useEffect(() => {
advertiser_page_store.onMount();
advertiser_page_store.setIsDropdownMenuVisible(false);

return reaction(
() => advertiser_page_store.active_index,
Expand All @@ -61,27 +66,28 @@ const AdvertiserPage = () => {
>
<RateChangeModal onMount={advertiser_page_store.setShowAdPopup} />
<BlockUserModal
advertiser_name={name}
is_advertiser_blocked={!!advertiser_page_store.is_counterparty_advertiser_blocked}
is_block_user_modal_open={general_store.is_block_user_modal_open}
onCancel={() => general_store.setIsBlockUserModalOpen(false)}
onSubmit={() =>
general_store.blockUnblockUser(
!advertiser_page_store.is_counterparty_advertiser_blocked,
advertiser_page_store.advertiser_details_id
)
}
onCancel={advertiser_page_store.onCancel}
onSubmit={advertiser_page_store.onSubmit}
/>
<BuySellModal
selected_ad={advertiser_page_store.advert}
should_show_popup={advertiser_page_store.show_ad_popup}
setShouldShowPopup={advertiser_page_store.setShowAdPopup}
table_type={advertiser_page_store.counterparty_type === buy_sell.BUY ? buy_sell.BUY : buy_sell.SELL}
/>
<PageReturn
className='buy-sell__advertiser-page-return'
onClick={buy_sell_store.hideAdvertiserPage}
page_title={localize("Advertiser's page")}
/>
<div className='advertiser-page__page-return-header'>
<PageReturn
className='buy-sell__advertiser-page-return'
onClick={buy_sell_store.hideAdvertiserPage}
page_title={localize("Advertiser's page")}
/>
<MobileWrapper>
<AdvertiserPageDropdownMenu is_my_advert={is_my_advert} />
</MobileWrapper>
</div>
<BlockUserOverlay
is_visible={!!advertiser_page_store.is_counterparty_advertiser_blocked}
onClickUnblock={() => general_store.setIsBlockUserModalOpen(true)}
Expand Down Expand Up @@ -125,6 +131,9 @@ const AdvertiserPage = () => {
/>
</div>
</div>
<DesktopWrapper>
<AdvertiserPageDropdownMenu is_my_advert={is_my_advert} />
</DesktopWrapper>
</div>
<AdvertiserPageStats />
</div>
Expand Down
65 changes: 65 additions & 0 deletions packages/p2p/src/components/advertiser-page/advertiser-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,71 @@
display: flex;
flex-direction: column;

&__dropdown {
box-shadow: 0 1rem 2rem var(--shadow-menu);
border-radius: $BORDER_RADIUS;
cursor: pointer;
position: absolute;
right: 0;
z-index: 2;

.dc-dropdown__display {
background-color: var(--general-main-2);
border: 1px solid var(--general-active);

span {
background-color: var(--general-main-2);
}

&-placeholder {
top: auto;
}
}

&-container {
margin-top: 0;

&--disabled {
margin-top: 0;

span {
color: var(--text-disabled) !important;
}
}
}

&:hover {
.dc-dropdown__display {
background-color: var(--border-normal);
border: 1px solid var(--border-normal);

span {
background-color: var(--border-normal);
}
}
}
}

&__menu-dots-icon {
cursor: pointer;
margin-bottom: 0.8rem;
}

&__menu-dots-toggle {
position: absolute;
right: 2.4rem;

@include mobile {
bottom: 0.8rem;
right: 1.2rem;
}
}

&__page-return-header {
display: flex;
position: relative;
}

&--no-scroll {
overflow: hidden;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const BlockUserCount = () => {

const [is_block_user_count_modal_open, setIsBlockUserCountModalOpen] = React.useState(false);

const message =
blocked_by_count === 0
? localize('Nobody has blocked you. Yay!')
: localize('{{blocked_by_count}} people have blocked you.', { blocked_by_count });
const getMessage = () => {
if (blocked_by_count === 0) {
return localize('Nobody has blocked you. Yay!');
} else if (blocked_by_count === 1) {
return localize('{{blocked_by_count}} person has blocked you', { blocked_by_count });
}
return localize('{{blocked_by_count}} people have blocked you', { blocked_by_count });
};

React.useEffect(() => {
my_profile_store.getAdvertiserInfo();
Expand All @@ -29,7 +33,7 @@ const BlockUserCount = () => {
<Modal has_close_icon={false} is_open={is_block_user_count_modal_open} width='440px'>
<Modal.Body>
<Text color='prominent' size='xs'>
{message}
{getMessage()}
</Text>
</Modal.Body>
<Modal.Footer>
Expand All @@ -50,7 +54,7 @@ const BlockUserCount = () => {
alignment='top'
className='block-user-count'
classNameTarget='block-user-count__container'
message={message}
message={getMessage()}
>
<Icon className='block-user-count__container--icon' icon='IcUserBlockedOutline' size={16} />
<Text color='less-prominent' line_height='m' size={isDesktop() ? 'xs' : 14}>
Expand Down
Loading

0 comments on commit f17d1d2

Please sign in to comment.