Skip to content

Commit

Permalink
fix: use dropdown instead of custom componnet
Browse files Browse the repository at this point in the history
  • Loading branch information
nada-deriv committed May 15, 2024
1 parent 2e8c65b commit b1ffbe6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 66 deletions.
50 changes: 18 additions & 32 deletions src/components/AdvertiserName/BlockDropdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,29 @@
display: flex;
flex-direction: column;
position: relative;
.deriv-dropdown {
width: 3.2rem;

&__icon {
margin-left: 1rem;
}

& .deriv-tooltip {
@include mobile {
display: none;
& .deriv-dropdown__button {
transform: none;
transition: none;
}
}
&__list {
display: flex;
flex-direction: column;
border-radius: 0.4rem;
width: 15rem;
box-shadow: 0 1rem 2rem rgba(0, 0, 0, 0.16);
z-index: 1;
top: 2.8rem;
position: absolute;
background: #fff;
right: 2rem;

&-item {
padding: 1rem 1.6rem;
height: inherit;
justify-content: start;
border-radius: unset;
&__items {
width: 12.8rem;
border: 0;
padding: 0;
top: 3rem;
right: 1rem;
}

// TODO: remove this once hover styles can be removed from the button component
&:hover {
// stylelint-disable-next-line declaration-no-important
background-color: #e6e9e9 !important;
.deriv-input {
border: 0;
padding: 0;

& span {
// stylelint-disable-next-line declaration-no-important
color: #333 !important;
}
&__field,
&__helper-message {
display: none;
}
}
}
Expand Down
51 changes: 17 additions & 34 deletions src/components/AdvertiserName/BlockDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { useRef, useState } from 'react';
import { useOnClickOutside } from 'usehooks-ts';
import { BlockUnblockUserModal } from '@/components/Modals';
import { useAdvertiserStats, useModalManager } from '@/hooks';
import { LabelPairedEllipsisVerticalMdRegularIcon } from '@deriv/quill-icons';
import { Localize } from '@deriv-com/translations';
import { Button, Text, useDevice } from '@deriv-com/ui';
import { LabelPairedEllipsisVerticalXlRegularIcon } from '@deriv/quill-icons';
import { useTranslations } from '@deriv-com/translations';
import { Dropdown } from '@deriv-com/ui';
import './BlockDropdown.scss';

type TBlockDropdownProps = {
Expand All @@ -13,39 +11,24 @@ type TBlockDropdownProps = {
};

const BlockDropdown = ({ id, onClickBlocked }: TBlockDropdownProps) => {
const [visible, setVisible] = useState(false);
const { localize } = useTranslations();
const { hideModal, isModalOpenFor, showModal } = useModalManager();
const { data } = useAdvertiserStats(id);
const { is_blocked: isBlocked, name = '' } = data ?? {};
const ref = useRef(null);
useOnClickOutside(ref, () => setVisible(false));
const { isMobile } = useDevice();

return (
<div className='block-dropdown' ref={ref}>
<Button color='white' variant='outlined'>
<LabelPairedEllipsisVerticalMdRegularIcon
data-testid='dt_block_dropdown_icon'
onClick={() => setVisible(prevState => !prevState)}
/>
</Button>
{visible && (
<div className='block-dropdown__list'>
<Button
className='block-dropdown__list-item'
color='black'
onClick={() => {
showModal('BlockUnblockUserModal');
setVisible(false);
}}
variant='ghost'
>
<Text className='block-dropdown__list-item__label' size={isMobile ? 'md' : 'sm'}>
<Localize i18n_default_text='Block' />
</Text>
</Button>
</div>
)}
<div className='block-dropdown'>
<Dropdown
className='block-dropdown__header-dropdown'
dropdownIcon={<LabelPairedEllipsisVerticalXlRegularIcon data-testid='dt_block_dropdown_icon' />}
list={[
{
text: localize('Block'),
value: 'block',
},
]}
name='block-user-dropdown'
onSelect={() => showModal('BlockUnblockUserModal')}
/>
{isModalOpenFor('BlockUnblockUserModal') && (
<BlockUnblockUserModal
advertiserName={name}
Expand Down
1 change: 1 addition & 0 deletions src/hooks/custom-hooks/useAdvertiserStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const useAdvertiserStats = (advertiserId?: string) => {
localStorage.removeItem(`p2p_advertiser_info_${advertiserId}`);
unsubscribe();
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const transformedData = useMemo(() => {
Expand Down

0 comments on commit b1ffbe6

Please sign in to comment.