Skip to content

Commit 3062e33

Browse files
Merge pull request #192 from ahmed-deriv/ahmed/DAPI-516/fix--resolve-site-down-api-deriv
Ahmed/dapi 516/fix resolve site down api deriv
2 parents 6221b89 + 4418703 commit 3062e33

File tree

20 files changed

+328
-156
lines changed

20 files changed

+328
-156
lines changed

i18n/en/code.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,5 +1115,8 @@
11151115
},
11161116
"Clear response": {
11171117
"message": "Clear response"
1118+
},
1119+
"The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later.": {
1120+
"message": "The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later."
11181121
}
11191122
}

i18n/fr/code.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,5 +1115,8 @@
11151115
},
11161116
"Clear response": {
11171117
"message": "Effacer la réponse"
1118+
},
1119+
"The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later.": {
1120+
"message": "Le serveur est actuellement incapable de traiter la requête en raison d'une surcharge temporaire ou d'une maintenance du serveur. Veuillez réessayer plus tard."
11181121
}
11191122
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.tooltip_content {
22
border-radius: 4px;
3-
padding: 8px 4px;
3+
padding: 12px;
44
font-size: 12px;
55
line-height: 14px;
66
color: var(--ifm-color-emphasis-100);
@@ -10,10 +10,14 @@
1010
animation-duration: 400ms;
1111
animation-timing-function: cubic-bezier(0.16, 1, 0.3, 1);
1212
will-change: transform, opacity;
13-
max-width: 96px;
13+
max-width: 200px;
1414
text-align: center;
1515
}
1616

1717
.tooltip_arrow {
1818
fill: var(--ifm-color-emphasis-700);
1919
}
20+
21+
div[data-radix-popper-content-wrapper] {
22+
z-index: 9999 !important;
23+
}

src/components/UserNavbarItem/__tests__/item.desktop.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const mockUseAuthContext = useAuthContext as jest.MockedFunction<() => Partial<I
1010

1111
mockUseAuthContext.mockImplementation(() => ({
1212
is_logged_in: true,
13+
siteActive: true,
1314
}));
1415

1516
describe('User Navbar Desktop Item', () => {

src/components/UserNavbarItem/item.desktop.tsx

Lines changed: 83 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import clsx from 'clsx';
3-
import Translate from '@docusaurus/Translate';
3+
import Translate, { translate } from '@docusaurus/Translate';
44
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
55
import { Button } from '@deriv-com/quill-ui';
66
import {
@@ -14,13 +14,21 @@ import { IUserNavbarItemProps } from './item.types';
1414
import styles from './UserNavbarItem.module.scss';
1515
import Cookies from 'js-cookie';
1616
import { useHandleLogin } from '@site/src/hooks/useHandleLogin';
17+
import useAuthContext from '@site/src/hooks/useAuthContext';
18+
import CustomTooltip from '../CustomTooltip';
1719

1820
interface IActionProps {
1921
handleClick: () => void;
2022
isDesktop: boolean;
23+
siteActive: boolean;
2124
}
2225

23-
const DashboardActions: React.FC<IActionProps> = ({ handleClick, isDesktop }) => {
26+
const siteDownErrMsg = translate({
27+
message:
28+
'The server is currently unable to handle the request due to a temporary overload or maintenance of the server. Please try again later.',
29+
});
30+
31+
const DashboardActions: React.FC<IActionProps> = ({ handleClick, isDesktop, siteActive }) => {
2432
const {
2533
i18n: { currentLocale },
2634
} = useDocusaurusContext();
@@ -31,72 +39,105 @@ const DashboardActions: React.FC<IActionProps> = ({ handleClick, isDesktop }) =>
3139
location.assign(pathInfo);
3240
};
3341

34-
return (
35-
<React.Fragment>
36-
<Button
37-
onClick={onClickDashboard}
38-
type='button'
39-
className={styles.dashboardButton}
40-
variant='tertiary'
41-
color='black'
42-
icon={<LabelPairedGridLgRegularIcon />}
43-
data-testid='da_login'
44-
>
45-
<Translate>Dashboard</Translate>
46-
</Button>
47-
{isDesktop && (
42+
const renderDashboardBtn = () => {
43+
return (
44+
<React.Fragment>
4845
<Button
49-
onClick={handleClick}
46+
onClick={onClickDashboard}
5047
type='button'
48+
className={styles.dashboardButton}
5149
variant='tertiary'
5250
color='black'
53-
className={styles.logoutButton}
54-
icon={<StandaloneRightFromBracketBoldIcon />}
55-
data-testid='da_logout'
51+
icon={<LabelPairedGridLgRegularIcon />}
52+
data-testid='da_login'
53+
disabled={!siteActive}
5654
>
57-
<Translate>Log out</Translate>
55+
<Translate>Dashboard</Translate>
5856
</Button>
57+
{isDesktop && (
58+
<Button
59+
onClick={handleClick}
60+
type='button'
61+
variant='tertiary'
62+
color='black'
63+
className={styles.logoutButton}
64+
icon={<StandaloneRightFromBracketBoldIcon />}
65+
data-testid='da_logout'
66+
disabled={!siteActive}
67+
>
68+
<Translate>Log out</Translate>
69+
</Button>
70+
)}
71+
</React.Fragment>
72+
);
73+
};
74+
75+
return (
76+
<React.Fragment>
77+
{siteActive ? (
78+
renderDashboardBtn()
79+
) : (
80+
<CustomTooltip text={siteDownErrMsg}>
81+
<span>{renderDashboardBtn()}</span>
82+
</CustomTooltip>
5983
)}
6084
</React.Fragment>
6185
);
6286
};
6387

64-
const SignedInActions: React.FC<IActionProps> = ({ handleClick, isDesktop }) => {
88+
const SignedInActions: React.FC<IActionProps> = ({ handleClick, isDesktop, siteActive }) => {
6589
const signedInButtonClasses = clsx('navbar__item', styles.UserNavbarItem, styles.SignedInButton);
6690

6791
const { handleLogin } = useHandleLogin({
6892
onClickLogin: handleClick,
6993
});
7094

71-
return (
72-
<nav className='right-navigation'>
73-
<Button
74-
variant='secondary'
75-
color='black'
76-
onClick={handleLogin}
77-
className={signedInButtonClasses}
78-
data-testid='sa_login'
79-
>
80-
<Translate>Log in</Translate>
81-
</Button>
82-
{isDesktop && (
95+
const renderSignupBtn = () => {
96+
return (
97+
<nav className='right-navigation'>
8398
<Button
84-
variant='primary'
85-
onClick={() => location.assign('https://deriv.com/signup/')}
99+
variant='secondary'
100+
color='black'
101+
onClick={handleLogin}
86102
className={signedInButtonClasses}
87-
data-testid='sa_signup'
103+
data-testid='sa_login'
104+
disabled={!siteActive}
88105
>
89-
<Translate>Sign up</Translate>
106+
<Translate>Log in</Translate>
90107
</Button>
108+
{isDesktop && (
109+
<Button
110+
variant='primary'
111+
onClick={() => location.assign('https://deriv.com/signup/')}
112+
className={signedInButtonClasses}
113+
data-testid='sa_signup'
114+
disabled={!siteActive}
115+
>
116+
<Translate>Sign up</Translate>
117+
</Button>
118+
)}
119+
</nav>
120+
);
121+
};
122+
123+
return (
124+
<React.Fragment>
125+
{siteActive ? (
126+
renderSignupBtn()
127+
) : (
128+
<CustomTooltip text={siteDownErrMsg}>
129+
<span>{renderSignupBtn()}</span>
130+
</CustomTooltip>
91131
)}
92-
</nav>
132+
</React.Fragment>
93133
);
94134
};
95135

96136
const UserNavbarDesktopItem = ({ authUrl, is_logged_in }: IUserNavbarItemProps) => {
97137
const { deviceType } = useDeviceType();
98138
const isDesktop = deviceType === 'desktop';
99-
139+
const { siteActive } = useAuthContext();
140+
100141
const handleClick = () => {
101142
location.assign(authUrl);
102143
};
@@ -130,9 +171,9 @@ const UserNavbarDesktopItem = ({ authUrl, is_logged_in }: IUserNavbarItemProps)
130171
}, [isOAuth2Enabled, loggedState, logout, handleLogin, isLoginAccountsPopulated]);
131172

132173
return is_logged_in ? (
133-
<DashboardActions handleClick={logout} isDesktop={isDesktop} />
174+
<DashboardActions handleClick={logout} isDesktop={isDesktop} siteActive={siteActive} />
134175
) : (
135-
<SignedInActions handleClick={handleClick} isDesktop={isDesktop} />
176+
<SignedInActions handleClick={handleClick} isDesktop={isDesktop} siteActive={siteActive} />
136177
);
137178
};
138179

src/contexts/auth/auth.context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface IAuthContext {
1919
updateCurrentLoginAccount: (userAccount: IUserLoginAccount, isValidateAccount?: boolean) => void;
2020
userAccounts: IUserAccounts;
2121
user: IUser;
22+
siteActive: boolean;
2223
}
2324

2425
export const AuthContext = React.createContext<IAuthContext | null>(null);

src/contexts/auth/auth.provider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
USER_SESSION_STORAGE_KEY,
1111
} from '@site/src/utils/constants';
1212
import { findVirtualAccount, getIsBrowser } from '@site/src/utils';
13+
import useServerInfo from '@site/src/hooks/useServerInfo';
1314

1415
type TAuthProviderProps = {
1516
children: ReactNode;
@@ -24,6 +25,7 @@ const AuthProvider = ({ children }: TAuthProviderProps) => {
2425
const [is_authorized, setIsAuthorized] = useState(false);
2526
const [is_switching_account, setisSwitchingAccount] = useState(false);
2627
const [is_connected, setIsConnected] = useState(true);
28+
const { siteActive } = useServerInfo();
2729

2830
const [loginAccounts, setLoginAccounts] = useSessionStorage<IUserLoginAccount[]>(
2931
LOGIN_ACCOUNTS_SESSION_STORAGE_KEY,
@@ -67,7 +69,6 @@ const AuthProvider = ({ children }: TAuthProviderProps) => {
6769

6870
const updateLoginAccounts = useCallback(
6971
(loginAccounts: IUserLoginAccount[], updateCurrentAccount = true) => {
70-
7172
setLoginAccounts(loginAccounts);
7273
if (!updateCurrentAccount) return;
7374

@@ -113,6 +114,7 @@ const AuthProvider = ({ children }: TAuthProviderProps) => {
113114
updateCurrentLoginAccount,
114115
userAccounts,
115116
user,
117+
siteActive,
116118
};
117119
}, [
118120
currentLoginAccount,
@@ -124,6 +126,7 @@ const AuthProvider = ({ children }: TAuthProviderProps) => {
124126
updateLoginAccounts,
125127
userAccounts,
126128
user,
129+
siteActive,
127130
]);
128131

129132
return <AuthContext.Provider value={context_object}>{children}</AuthContext.Provider>;

src/features/Apiexplorer/__tests__/ApiExplorer.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { act } from 'react';
22
import '@testing-library/jest-dom';
3-
import ApiExplorerFeatures from '..';
3+
import ApiExplorerFeatures from '../explorer';
44
import userEvent from '@testing-library/user-event';
55
import useWS from '@site/src/hooks/useWs';
66
import useAuthContext from '@site/src/hooks/useAuthContext';

0 commit comments

Comments
 (0)