Skip to content

Commit

Permalink
Merge pull request #29 from thisyahlen-deriv/thisyahlen/tradershub_pa…
Browse files Browse the repository at this point in the history
…ge_base_layout

Thisyahlen/chore: add some hooks and base tradershub title for the homepage
  • Loading branch information
thisyahlen-deriv authored Mar 27, 2024
2 parents f39cfbd + a9d47cd commit 048f40f
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 24 deletions.
14 changes: 10 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"prepare": "husky install"
},
"dependencies": {
"@deriv-com/api-hooks": "^0.0.4",
"@deriv-com/api-hooks": "^0.0.8",
"@deriv-com/ui": "latest",
"@deriv-com/utils": "latest",
"@deriv/quill-icons": "latest",
Expand Down
17 changes: 17 additions & 0 deletions src/components/AppContainer/AppContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ReactNode } from 'react';
import { twMerge } from 'tailwind-merge';

type TAppContainerProps = {
children: ReactNode;
className?: string;
};

/**
* `AppContainer` is a component that wraps the entire application with some base styles.
* @param {React.ReactNode} children - The children to be rendered within the `AppContainer`.
* @returns {React.ElementType} The `AppContainer` component.
*/

export const AppContainer = ({ children, className }: TAppContainerProps) => (
<div className={twMerge('font-sans max-w-[600px] lg:max-w-[1280px] mx-auto', className)}>{children}</div>
);
1 change: 1 addition & 0 deletions src/components/AppContainer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AppContainer } from './AppContainer';
9 changes: 9 additions & 0 deletions src/components/TradersHubHeader/TradersHubHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Text } from '@deriv-com/ui';

export const TradersHubHeader = () => {
return (
<div className='flex flex-col gap-4 lg:flex-row w-1/2 lg:w-auto'>
<Text weight='bold'>Trader&apos;s Hub</Text>
</div>
);
};
1 change: 1 addition & 0 deletions src/components/TradersHubHeader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { TradersHubHeader } from './TradersHubHeader';
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './AppContainer';
export * from './TradersHubHeader';
2 changes: 1 addition & 1 deletion src/hooks/__tests__/useQueryParams.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useLocation, useNavigate } from 'react-router-dom';

import { renderHook, waitFor } from '@testing-library/react';

import useQueryParams from '../useQueryParams';
import { useQueryParams } from '../useQueryParams';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { useDerivTradingAccountsList } from './useDerivTradingAccountsList';
export { useActiveDerivTradingAccount } from './useActiveDerivTradingAccount';
export { useQueryParams } from './useQueryParams';
19 changes: 19 additions & 0 deletions src/hooks/useActiveDerivTradingAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useMemo } from 'react';

import { useDerivTradingAccountsList } from './useDerivTradingAccountsList';

/**
* Custom hook to get the active trading account
* @returns {Object} activeTradingAccount - The active trading account
* @returns {Object} rest - The rest of the props from useDerivTradingAccountsList
*
*/
export const useActiveDerivTradingAccount = () => {
const { data, ...rest } = useDerivTradingAccountsList();

const activeTradingAccount = useMemo(() => {
return data?.find(trading => trading.isActive);
}, [data]);

return { data: activeTradingAccount, ...rest };
};
24 changes: 24 additions & 0 deletions src/hooks/useDerivTradingAccountsList.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useMemo } from 'react';

import { useAccountList, useAppData } from '@deriv-com/api-hooks';

/**
* Custom hook to get a list of trading accounts
* @returns {Object} tradingAccounts - List of trading accounts
* @returns {Object} rest - The rest of the props from useAccountList
*/
export const useDerivTradingAccountsList = () => {
const { data, ...rest } = useAccountList();
const { activeLoginid } = useAppData();

const modifiedAccounts = useMemo(() => {
return data?.map(account => {
return {
...account,
isActive: account.loginid === activeLoginid,
};
});
}, [data, activeLoginid]);

return { data: modifiedAccounts, ...rest };
};
4 changes: 1 addition & 3 deletions src/hooks/useQueryParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ModalId =
* openModal('GetADerivAccountDialog');
* closeModal();
*/
const useQueryParams = () => {
export const useQueryParams = () => {
const { search } = useLocation();
const navigate = useNavigate();

Expand Down Expand Up @@ -76,5 +76,3 @@ const useQueryParams = () => {
queryParams,
};
};

export default useQueryParams;
21 changes: 6 additions & 15 deletions src/pages/homepage/homepage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import { Link } from 'react-router-dom';
import { AppContainer, TradersHubHeader } from '../../components';

import derivLogo from '../../static/deriv-logo.svg';

export function Homepage() {
export const Homepage = () => {
return (
<div className='flex flex-col items-center justify-center gap-10'>
<a href='https://deriv.com' target='_blank' rel='noreferrer'>
<img src={derivLogo} className='h-[100px] w-[100px]' alt='Deriv logo' />
</a>
<h1 className='text-5xl font-bold'>Deriv V2</h1>
<Link to='signup'>Click me 💅</Link>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<AppContainer>
<TradersHubHeader />
</AppContainer>
);
}
};

0 comments on commit 048f40f

Please sign in to comment.