Skip to content

Commit

Permalink
Farzin/85855/Refactor ToggleMenuDrawer component to use useStore
Browse files Browse the repository at this point in the history
…hook (#7365)

* Shayan/52349/react17 migration (#6908)

* refactor: react version is upgraded to version 17

* fix: fixed typo

* fix: changed declaration file location

* fix: temporarily commented our two test cases that are failing

* fix: fixed react-content-loader props

* fix: fixed some bugs

* fix: fixed z-index issue for popover in DBot page

* fix: fixed popover position issue in DBot page

* chore: an small change on how to turn string to array

* fix: merge upstream develop into my branch and resolved conflicts

* fix: resolved pr comments

* fix: removed rc-drawer and refactored mobile drawer

* fix: fixed test cases

* fix: resolved pr comments

* fix: resolved pr comment

* fix: fixed typo

* fix: resolved pr comments

* fix: fixed slide-in component bug

* fix: resolved pr comments

* fix: resolved pr comments

* fix: removed unnecessary lines

* fix: resolved pr comments

* Update packages/account/src/Components/personal-details/__tests__/personal-details.spec.js

Co-authored-by: Niloofar Sadeghi <93518187+niloo-fs@users.noreply.github.com>

* Update packages/account/src/Components/personal-details/__tests__/personal-details.spec.js

Co-authored-by: Niloofar Sadeghi <93518187+niloo-fs@users.noreply.github.com>

* Update packages/account/src/Components/personal-details/personal-details.jsx

Co-authored-by: Niloofar Sadeghi <93518187+niloo-fs@users.noreply.github.com>

* fix: fixed mt5 modal not appear on screen when clicking on trade button

* fix: fixed Bug #84787

Co-authored-by: Shayan Khaleghparast <100833613+iman-fs@users.noreply.github.com>
Co-authored-by: Niloofar Sadeghi <93518187+niloo-fs@users.noreply.github.com>

* fix: add optional chaining in getMinDuration function (#7344)

* fix: 🐛 resolved issue with trade. odal (#7291)

* Revert "fix: 🐛 resolved issue with trade. odal (#7291)" (#7364)

This reverts commit b6f7e4c.

* feat(core): ✨ add `@deriv/hooks` and `@deriv/stores` to `@deriv/core`

* refactor(core): 🔥 remove `ToggleMenuDrawer` prop drilling and use `useStore` hook

* refactor(core): 🔥 remove dead props

* refactor(core): 🔥 remove unnecessary ref in `ToggleMenuDrawer`

* refactor(core): 🔥 remove `react-import-loader` from `@deriv/core`

* refactor(core): 🔥 remove `platform_switcher` prop from `ToggleMenuDrawer`

* Farzin/85054/Call `resetWithrawForm` on `CryptoWithdrawForm` component `onunmount` (#7331)

* fix(cashier): 🐛 call `resetWithrawForm` on `CryptoWithdrawForm` component `onunmount`

* test(cashier): ✅ fix failing test

Co-authored-by: Farzin Mirzaie <farzin@deriv.com>

* Niloofar Sadeghi / Task - Refactor tests in the language.spec.js file (#7325)

* refactor: language tests

* fix: typo

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* refactor: proposal tests (#7327)

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* Niloofar Sadeghi / Task - Refactor tests in the error.spec.js file (#7324)

* refactor: errors validator tests

* fix: typo

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* Niloofar Sadeghi / Task - Refactor tests in the binary-link.spec.tsx file (#7288)

* refactor: binary-link tests

* refactor: improve testids namings

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* refactor: money tests (#7353)

* refactor: toggle-positions tests (#7287)

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* refactor: toggle-button tests (#7328)

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* Niloofar Sadeghi / Task - Refactor tests in the toggle-button-group.spec.tsx file (#7330)

* refactor: toggle-button-group tests

* fix: test issue

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* refactor: open-positions-table tests (#7374)

* Niloofar Sadeghi / Task - Refactor tests in the marker-spot-label.spec.tsx file (#7355)

* refactor: remove extra files from reports

* refactor: marker-spot-label tests

* Niloofar Sadeghi / Task - Refactor tests in the binary-link.spec.tsx file (#7286)

* refactor: binary-link tests

* test: added more tests

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* Niloofar Sadeghi / Task - Refactor tests in the contract-type-dialog.spec.tsx file (#7285)

* refactor: contract-type-dialog tests

* test: added more tests

* fix: circle/ci issue

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* Niloofar Sadeghi / Task - Refactor tests in the platform-dropdown.spec.tsx file (#7282)

* refactor: platform-dropdown tests

* refactor: improve testids namings

Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>

* fix(core): 📝 resolve conflicts

* fix(core): 📝 resolve conflicts

Co-authored-by: Shayan Khaleghparast <100833613+shayan-deriv@users.noreply.github.com>
Co-authored-by: Shayan Khaleghparast <100833613+iman-fs@users.noreply.github.com>
Co-authored-by: Niloofar Sadeghi <93518187+niloo-fs@users.noreply.github.com>
Co-authored-by: kate-deriv <121025168+kate-deriv@users.noreply.github.com>
Co-authored-by: Likhith Kolayari <98398322+likhith-deriv@users.noreply.github.com>
Co-authored-by: Farrah Mae Ochoa <farrah@deriv.com>
Co-authored-by: Matin shafiei <matin@deriv.com>
Co-authored-by: Farzin Mirzaie <farzin@deriv.com>
Co-authored-by: Niloofar Sadeghi <93518187+niloofar-deriv@users.noreply.github.com>
Co-authored-by: Niloofar Sadeghi <niloofar.sadeghi@firstsource.tech>
  • Loading branch information
11 people committed Jan 26, 2023
1 parent 39c7fa5 commit f9f735e
Show file tree
Hide file tree
Showing 10 changed files with 573 additions and 857 deletions.
1 change: 0 additions & 1 deletion packages/core/build/loaders-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');

const js_loaders = [
'@deriv/shared/src/loaders/react-import-loader.js',
'@deriv/shared/src/loaders/deriv-account-loader.js',
'@deriv/shared/src/loaders/deriv-cashier-loader.js',
'@deriv/shared/src/loaders/deriv-cfd-loader.js',
Expand Down
4 changes: 3 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@
"@deriv/components": "^1.0.0",
"@deriv/deriv-api": "^1.0.8",
"@deriv/deriv-charts": "1.0.1",
"@deriv/hooks": "^1.0.0",
"@deriv/p2p": "^0.7.3",
"@deriv/reports": "^1.0.0",
"@deriv/stores": "^1.0.0",
"@deriv/shared": "^1.0.0",
"@deriv/trader": "^3.8.0",
"@deriv/translations": "^1.0.0",
Expand Down Expand Up @@ -127,7 +129,7 @@
"react-dom": "^17.0.2",
"react-i18next": "^11.11.0",
"react-loadable": "^5.5.0",
"framer-motion":"^6.5.1",
"framer-motion": "^6.5.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-tiny-popover": "^7.0.1",
Expand Down
1,074 changes: 528 additions & 546 deletions packages/core/src/App/Components/Layout/Header/toggle-menu-drawer.jsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const LoggedInHeader = ({ is_dark_mode }) => {
<React.Fragment>
<Icon icon={'IcNotificationClear'} height={20} width={17} />
<div className='dashboard-header__right--logged-in-separator' />
<ToggleMenuDrawer alignment={'right'} is_logged_in should_allow_authentication title={''} />
<ToggleMenuDrawer />
</React.Fragment>
)}
</div>
Expand Down Expand Up @@ -94,7 +94,7 @@ const LoggedOutHeader = () => {
{isMobile() && (
<React.Fragment>
<div className='dashboard-header__right--logged-out-separator' />
<ToggleMenuDrawer alignment={'right'} should_allow_authentication title={''} />
<ToggleMenuDrawer />
</React.Fragment>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import * as React from 'react';

import { Button, DesktopWrapper, Icon, MobileWrapper, Money, Popover, Text } from '@deriv/components';
import { Localize, localize } from '@deriv/translations';
import { PlatformSwitcher, ToggleNotifications } from 'App/Components/Layout/Header';
import { ToggleNotifications } from 'App/Components/Layout/Header';
import { getPlatformInformation, isMobile, routes } from '@deriv/shared';
import { useHistory, withRouter } from 'react-router-dom';

import { BinaryLink } from 'App/Components/Routes';
import PropTypes from 'prop-types';
import ToggleMenuDrawer from 'App/Components/Layout/Header/toggle-menu-drawer.jsx';
Expand Down Expand Up @@ -97,34 +95,21 @@ const AccountBalance = ({ balance, currency }) => {
};

const DashboardPlatformHeader = ({
account_status,
app_routing_history,
balance,
currency,
disableApp,
enableApp,
header_extension,
is_dark_mode,
is_logged_in,
is_mt5_allowed,
is_notifications_visible,
is_onramp_tab_visible,
is_p2p_enabled,
is_payment_agent_transfer_visible,
is_payment_agent_visible,
is_account_transfer_visible,
is_settings_modal_on,
is_virtual,
location,
logoutClient,
notifications_count,
setDarkMode,
settings_extension,
should_allow_authentication,
toggleNotifications,
toggleSettingsModal,
}) => {
const toggle_menu_drawer_ref = React.useRef(null);
const filterPlatformsForClients = payload =>
payload.filter(config => {
if (config.link_to === routes.mt5) {
Expand All @@ -137,33 +122,7 @@ const DashboardPlatformHeader = ({
<header className='dashboard-platform-header'>
<div className='dashboard-platform-header__menu-left'>
<MobileWrapper>
<ToggleMenuDrawer
ref={toggle_menu_drawer_ref}
should_allow_authentication={should_allow_authentication}
account_status={account_status}
enableApp={enableApp}
disableApp={disableApp}
location={location}
logoutClient={logoutClient}
is_dark_mode={is_dark_mode}
is_logged_in={is_logged_in}
is_p2p_enabled={is_p2p_enabled}
is_payment_agent_transfer_visible={is_payment_agent_transfer_visible}
is_onramp_tab_visible={is_onramp_tab_visible}
is_payment_agent_visible={is_payment_agent_visible}
is_account_transfer_visible={is_account_transfer_visible}
is_virtual={is_virtual}
toggleTheme={setDarkMode}
platform_header={getPlatformInformation(app_routing_history).header}
platform_switcher={
<PlatformSwitcher
app_routing_history={app_routing_history}
is_mobile
platform_config={filterPlatformsForClients(platform_config)}
toggleDrawer={toggle_menu_drawer_ref.current?.toggleDrawer}
/>
}
/>
<ToggleMenuDrawer platform_config={filterPlatformsForClients(platform_config)} />
{header_extension && is_logged_in && <div>{header_extension}</div>}
</MobileWrapper>
<DesktopWrapper>
Expand Down Expand Up @@ -204,55 +163,32 @@ const DashboardPlatformHeader = ({
};

DashboardPlatformHeader.propTypes = {
account_status: PropTypes.object,
app_routing_history: PropTypes.array,
balance: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
currency: PropTypes.string,
disableApp: PropTypes.func,
enableApp: PropTypes.func,
header_extension: PropTypes.any,
is_dark_mode: PropTypes.bool,
is_logged_in: PropTypes.bool,
is_mt5_allowed: PropTypes.bool,
is_notifications_visible: PropTypes.bool,
is_onramp_tab_visible: PropTypes.bool,
is_p2p_enabled: PropTypes.bool,
is_payment_agent_transfer_visible: PropTypes.bool,
is_payment_agent_visible: PropTypes.bool,
is_account_transfer_visible: PropTypes.bool,
is_virtual: PropTypes.bool,
logoutClient: PropTypes.func,
notifications_count: PropTypes.number,
setDarkMode: PropTypes.func,
should_allow_authentication: PropTypes.bool,
toggleNotifications: PropTypes.func,
toggleSettingsModal: PropTypes.func,
location: PropTypes.object,
settings_extension: PropTypes.array,
is_settings_modal_on: PropTypes.bool,
};

export default connect(({ client, common, modules, notifications, ui }) => ({
account_status: client.account_status,
export default connect(({ client, common, notifications, ui }) => ({
app_routing_history: common.app_routing_history,
balance: client.balance,
currency: client.currency,
disableApp: ui.disableApp,
enableApp: ui.enableApp,
header_extension: ui.header_extension,
is_dark_mode: ui.is_dark_mode_on,
is_logged_in: client.is_logged_in,
is_mt5_allowed: client.is_mt5_allowed,
is_notifications_visible: notifications.is_notifications_visible,
is_onramp_tab_visible: modules.cashier.onramp.is_onramp_tab_visible,
is_p2p_enabled: modules.cashier.general_store.is_p2p_enabled,
is_payment_agent_transfer_visible: modules.cashier.payment_agent_transfer.is_payment_agent_transfer_visible,
is_payment_agent_visible: modules.cashier.payment_agent.is_payment_agent_visible,
is_account_transfer_visible: modules.cashier.account_transfer.is_account_transfer_visible,
is_virtual: client.is_virtual,
logoutClient: client.logout,
notifications_count: notifications.notifications.length,
setDarkMode: ui.setDarkMode,
should_allow_authentication: client.should_allow_authentication,
toggleNotifications: notifications.toggleNotificationsModal,
}))(withRouter(DashboardPlatformHeader));
78 changes: 2 additions & 76 deletions packages/core/src/App/Containers/Layout/header/default-header.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AccountActions, MenuLinks, PlatformSwitcher } from 'App/Components/Layout/Header';
import { DesktopWrapper, Icon, MobileWrapper, Text } from '@deriv/components';
import { PlatformContext, getDecimalPlaces, getPlatformInformation, isMobile, platforms, routes } from '@deriv/shared';

import { PlatformContext, getDecimalPlaces, isMobile, platforms, routes } from '@deriv/shared';
import { AccountsInfoLoader } from 'App/Components/Layout/Header/Components/Preloader';
import { BinaryLink } from 'App/Components/Routes';
import { Localize } from '@deriv/translations';
Expand All @@ -18,7 +17,6 @@ import { withRouter } from 'react-router-dom';

const DefaultHeader = ({
acc_switcher_disabled_message,
account_status,
account_type,
addNotificationMessage,
app_routing_history,
Expand All @@ -34,39 +32,25 @@ const DefaultHeader = ({
is_acc_switcher_on,
is_app_disabled,
is_bot_allowed,
is_dark_mode,
is_dxtrade_allowed,
is_eu,
is_logged_in,
is_logging_in,
is_mt5_allowed,
is_notifications_visible,
is_onramp_tab_visible,
is_p2p_enabled,
is_payment_agent_transfer_visible,
is_payment_agent_visible,
is_account_transfer_visible,
is_route_modal_on,
is_virtual,
is_risky_client,
location,
logoutClient,
menu_items,
notifications_count,
openRealAccountSignup,
platform,
replaceCashierMenuOnclick,
removeNotificationMessage,
setDarkMode,
should_allow_authentication,
toggleAccountsDialog,
toggleNotifications,
changeCurrentLanguage,
is_trading_assessment_for_existing_user_enabled,
active_account_landing_company,
is_landing_company_loaded,
}) => {
const toggle_menu_drawer_ref = React.useRef(null);
const addUpdateNotification = () => addNotificationMessage(client_notifications.new_version_available);
const removeUpdateNotification = React.useCallback(
() => removeNotificationMessage({ key: 'new_version_available' }),
Expand Down Expand Up @@ -173,39 +157,7 @@ const DefaultHeader = ({
/>
</DesktopWrapper>
<MobileWrapper>
<ToggleMenuDrawer
changeCurrentLanguage={changeCurrentLanguage}
ref={toggle_menu_drawer_ref}
should_allow_authentication={should_allow_authentication}
account_status={account_status}
enableApp={enableApp}
disableApp={disableApp}
location={location}
logoutClient={logoutClient}
is_dark_mode={is_dark_mode}
is_logged_in={is_logged_in}
is_p2p_enabled={is_p2p_enabled}
is_payment_agent_transfer_visible={is_payment_agent_transfer_visible}
is_onramp_tab_visible={is_onramp_tab_visible}
is_payment_agent_visible={is_payment_agent_visible}
is_account_transfer_visible={is_account_transfer_visible}
is_virtual={is_virtual}
is_risky_client={is_risky_client}
toggleTheme={setDarkMode}
platform_header={getPlatformInformation(app_routing_history).header}
active_account_landing_company={active_account_landing_company}
platform_switcher={
<PlatformSwitcher
app_routing_history={app_routing_history}
is_mobile
is_landing_company_loaded={is_landing_company_loaded}
is_logged_in={is_logged_in}
is_logging_in={is_logging_in}
platform_config={filterPlatformsForClients(platform_config)}
toggleDrawer={toggle_menu_drawer_ref.current?.toggleDrawer}
/>
}
/>
<ToggleMenuDrawer platform_config={filterPlatformsForClients(platform_config)} />
{header_extension && is_logged_in && (
<div className='header__menu-left-extensions'>{header_extension}</div>
)}
Expand Down Expand Up @@ -277,8 +229,6 @@ const DefaultHeader = ({
DefaultHeader.propTypes = {
acc_switcher_disabled_message: PropTypes.string,
account_type: PropTypes.string,
should_allow_authentication: PropTypes.bool,
account_status: PropTypes.object,
addNotificationMessage: PropTypes.func,
app_routing_history: PropTypes.array,
balance: PropTypes.string,
Expand All @@ -291,44 +241,30 @@ DefaultHeader.propTypes = {
is_acc_switcher_on: PropTypes.bool,
is_app_disabled: PropTypes.bool,
is_bot_allowed: PropTypes.bool,
is_dark_mode: PropTypes.bool,
is_eu: PropTypes.bool,
is_logged_in: PropTypes.bool,
is_logging_in: PropTypes.bool,
is_mt5_allowed: PropTypes.bool,
is_dxtrade_allowed: PropTypes.bool,
is_notifications_visible: PropTypes.bool,
is_account_transfer_visible: PropTypes.bool,
is_route_modal_on: PropTypes.bool,
is_virtual: PropTypes.bool,
is_trading_assessment_for_existing_user_enabled: PropTypes.bool,
is_risky_client: PropTypes.bool,
logoutClient: PropTypes.func,
notifications_count: PropTypes.number,
openRealAccountSignup: PropTypes.func,
platform: PropTypes.string,
removeNotificationMessage: PropTypes.func,
replaceCashierMenuOnclick: PropTypes.func,
setDarkMode: PropTypes.func,
toggleAccountsDialog: PropTypes.func,
toggleNotifications: PropTypes.func,
country_standpoint: PropTypes.object,
history: PropTypes.object,
is_onramp_tab_visible: PropTypes.bool,
is_p2p_enabled: PropTypes.bool,
is_payment_agent_transfer_visible: PropTypes.bool,
is_payment_agent_visible: PropTypes.bool,
location: PropTypes.object,
menu_items: PropTypes.array,
changeCurrentLanguage: PropTypes.func,
};

export default connect(({ client, common, ui, menu, modules, notifications }) => ({
changeCurrentLanguage: common.changeCurrentLanguage,
acc_switcher_disabled_message: ui.account_switcher_disabled_message,
account_status: client.account_status,
account_type: client.account_type,
should_allow_authentication: client.should_allow_authentication,
addNotificationMessage: notifications.addNotificationMessage,
app_routing_history: common.app_routing_history,
balance: client.balance,
Expand All @@ -342,32 +278,22 @@ export default connect(({ client, common, ui, menu, modules, notifications }) =>
is_acc_switcher_on: !!ui.is_accounts_switcher_on,
is_app_disabled: ui.is_app_disabled,
is_bot_allowed: client.is_bot_allowed,
is_dark_mode: ui.is_dark_mode_on,
is_eu: client.is_eu,
is_logged_in: client.is_logged_in,
is_logging_in: client.is_logging_in,
is_mt5_allowed: client.is_mt5_allowed,
is_dxtrade_allowed: client.is_dxtrade_allowed,
is_notifications_visible: notifications.is_notifications_visible,
is_p2p_enabled: modules.cashier.general_store.is_p2p_enabled,
is_payment_agent_transfer_visible: modules.cashier.payment_agent_transfer.is_payment_agent_transfer_visible,
is_onramp_tab_visible: modules.cashier.onramp.is_onramp_tab_visible,
is_payment_agent_visible: modules.cashier.payment_agent.is_payment_agent_visible,
is_account_transfer_visible: modules.cashier.account_transfer.is_account_transfer_visible,
is_route_modal_on: ui.is_route_modal_on,
is_virtual: client.is_virtual,
is_risky_client: client.is_risky_client,
logoutClient: client.logout,
menu_items: menu.extensions,
notifications_count: notifications.notifications.length,
openRealAccountSignup: ui.openRealAccountSignup,
replaceCashierMenuOnclick: modules.cashier.general_store.replaceCashierMenuOnclick,
platform: common.platform,
removeNotificationMessage: notifications.removeNotificationMessage,
setDarkMode: ui.setDarkMode,
toggleAccountsDialog: ui.toggleAccountsDialog,
toggleNotifications: notifications.toggleNotificationsModal,
is_trading_assessment_for_existing_user_enabled: ui.is_trading_assessment_for_existing_user_enabled,
active_account_landing_company: client.landing_company_shortcode,
is_landing_company_loaded: client.is_landing_company_loaded,
}))(withRouter(DefaultHeader));
Loading

0 comments on commit f9f735e

Please sign in to comment.