forked from deriv-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.
[TRAH] Aizad/TRAH-2268/DemoRealAccountSwitcher (deriv-com#12635)
* feat: create real demo switch account on tradershub * fix: added first_real_accounts and demo_loginid inside useTradingAccountList * fix: resolve comments * chore: added open and closing animations when toggle * fix: resolve comments * fix: remove invalid classname * fix: remove headless and replace it with default tailwind * feat: create real demo switch account on tradershub * fix: added first_real_accounts and demo_loginid inside useTradingAccountList * fix: resolve comments * chore: added open and closing animations when toggle * fix: resolve comments * fix: remove invalid classname * fix: remove headless and replace it with default tailwind * chore: update code * fix: remove ButtonGroup export inside of ./components * fix: resolve build fail issue * fix: resolve sonar cloud issue * fix: add type to account * Delete packages/tradershub/package-lock.json
- Loading branch information
1 parent
e64ad9e
commit 38956f9
Showing
6 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
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
84 changes: 84 additions & 0 deletions
84
packages/tradershub/src/components/DemoRealSwitcher/DemoRealSwitcher.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,84 @@ | ||
import React, { useCallback, useEffect, useState } from 'react'; | ||
import { Button, qtMerge, Text } from '@deriv/quill-design'; | ||
import { LabelPairedChevronDownSmRegularIcon } from '@deriv/quill-icons'; | ||
|
||
type TAccount = { | ||
label: string; | ||
value: string; | ||
}; | ||
|
||
const accountTypes = [ | ||
{ label: 'Demo', value: 'demo' }, | ||
{ label: 'Real', value: 'real' }, | ||
]; | ||
|
||
const DemoRealSwitcher = () => { | ||
const [isDropdownOpen, setIsDropdownOpen] = useState(false); | ||
const [selected, setSelected] = useState(accountTypes[0]); | ||
const { label, value } = selected; | ||
|
||
useEffect(() => { | ||
setIsDropdownOpen(false); | ||
}, [selected]); | ||
|
||
const toggleDropdown = useCallback(() => { | ||
setIsDropdownOpen(prevState => !prevState); | ||
}, []); | ||
|
||
const selectAccount = useCallback((account: TAccount) => { | ||
setSelected(account); | ||
}, []); | ||
|
||
return ( | ||
<div className='relative inline-block w-auto'> | ||
<Button | ||
className={qtMerge( | ||
'cursor-pointer w-full py-[3px] px-400 border-75 rounded-200 [&>span]:flex [&>span]:items-center [&>span]:text-[14px]', | ||
value === 'demo' | ||
? 'border-status-light-information text-status-light-information' | ||
: 'border-status-light-success text-status-light-success' | ||
)} | ||
colorStyle='white' | ||
iconPosition='end' | ||
onClick={toggleDropdown} | ||
size='sm' | ||
variant='secondary' | ||
> | ||
{label} | ||
<LabelPairedChevronDownSmRegularIcon | ||
className={qtMerge( | ||
'transform transition duration-200 ease-in-out ml-400', | ||
value === 'demo' ? 'fill-status-light-information' : 'fill-status-light-success', | ||
isDropdownOpen && '-rotate-180' | ||
)} | ||
/> | ||
</Button> | ||
{isDropdownOpen && ( | ||
<div className='absolute top-1400 z-10 rounded-200 bg-system-light-primary-background shadow-320 w-full'> | ||
{accountTypes.map(account => ( | ||
<div | ||
className={qtMerge( | ||
'cursor-pointer hover:bg-system-light-hover-background', | ||
account.value === value && 'bg-system-light-active-background' | ||
)} | ||
key={account.value} | ||
onClick={() => selectAccount(account)} | ||
onKeyDown={event => { | ||
if (event.key === 'Enter') { | ||
selectAccount(account); | ||
} | ||
}} | ||
role='button' | ||
> | ||
<Text bold={account.value === value} className='px-800 py-300 text-center' size='sm'> | ||
{account.label} | ||
</Text> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default DemoRealSwitcher; |
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 @@ | ||
export { default as DemoRealSwitcher } from './DemoRealSwitcher'; |
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
7 changes: 5 additions & 2 deletions
7
packages/tradershub/src/routes/TradersHubRoute/TradersHubRoute.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