From 11b8c52b304a91d3c4e1ed6400cc60ef57d084e2 Mon Sep 17 00:00:00 2001 From: Gala Date: Mon, 10 Oct 2022 12:03:38 +0200 Subject: [PATCH] pr refactoring suggestion --- nym-wallet/src/components/Tabs.tsx | 22 ++++++++++++++----- .../bonding/node-settings/NodeSettings.tsx | 17 +++++++------- .../node-settings/node-settings.constant.tsx | 8 ++----- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/nym-wallet/src/components/Tabs.tsx b/nym-wallet/src/components/Tabs.tsx index 106ba06f17..a0b0c979f6 100644 --- a/nym-wallet/src/components/Tabs.tsx +++ b/nym-wallet/src/components/Tabs.tsx @@ -1,15 +1,25 @@ import React from 'react'; import { Tab, Tabs as MuiTabs, SxProps } from '@mui/material'; -export const Tabs: React.FC<{ - tabs: string[]; - selectedTab: number; +type Props = { + tabs: readonly string[]; + selectedTab: string; disabled?: boolean; - onChange?: (event: React.SyntheticEvent, tab: number) => void; + onChange?: (event: React.SyntheticEvent, tab: string) => void; disableActiveTabHighlight?: boolean; tabSx?: SxProps; tabIndicatorStyles?: {}; -}> = ({ tabs, selectedTab, disabled, disableActiveTabHighlight, onChange, tabSx, tabIndicatorStyles }) => ( +}; + +export const Tabs = ({ + tabs, + selectedTab, + disabled, + disableActiveTabHighlight, + onChange, + tabSx, + tabIndicatorStyles, +}: Props) => ( {tabs.map((tabName) => ( - + ))} ); diff --git a/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx b/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx index 976ff21864..096e1632a3 100644 --- a/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx +++ b/nym-wallet/src/pages/bonding/node-settings/NodeSettings.tsx @@ -15,7 +15,7 @@ import { AppContext, urls } from 'src/context/main'; import { NodeGeneralSettings } from './settings-pages/general-settings'; import { NodeUnbondPage } from './settings-pages/NodeUnbondPage'; -import { nodeSettingsNav } from './node-settings.constant'; +import { navItems, NodeSettingsNav } from './node-settings.constant'; export const NodeSettings = () => { const theme = useTheme(); @@ -25,15 +25,14 @@ export const NodeSettings = () => { const location = useLocation(); const [confirmationDetails, setConfirmationDetails] = useState(); - const [value, setValue] = React.useState(0); - const handleChange = (event: React.SyntheticEvent, tab: number) => { - setValue(tab); + const [value, setValue] = React.useState('General'); + const handleChange = (event: React.SyntheticEvent, tab: string) => { + setValue(tab as NodeSettingsNav); }; useEffect(() => { if (location.state === 'unbond') { - const unbondIndex = nodeSettingsNav.indexOf('Unbond'); - setValue(unbondIndex); + setValue('Unbond'); } }, [location]); @@ -77,7 +76,7 @@ export const NodeSettings = () => { { } > - {nodeSettingsNav[value] === 'General' && bondedNode && } - {nodeSettingsNav[value] === 'Unbond' && bondedNode && ( + {value === 'General' && bondedNode && } + {value === 'Unbond' && bondedNode && ( )} {confirmationDetails && confirmationDetails.status === 'success' && ( diff --git a/nym-wallet/src/pages/bonding/node-settings/node-settings.constant.tsx b/nym-wallet/src/pages/bonding/node-settings/node-settings.constant.tsx index ccd0b50e26..1b06a9bf0b 100644 --- a/nym-wallet/src/pages/bonding/node-settings/node-settings.constant.tsx +++ b/nym-wallet/src/pages/bonding/node-settings/node-settings.constant.tsx @@ -1,7 +1,3 @@ -enum Options { - General, - Unbond, -} -type NavItem = keyof typeof Options; +export const navItems = ['General', 'Unbond'] as const; -export const nodeSettingsNav: NavItem[] = ['General', 'Unbond']; +export type NodeSettingsNav = typeof navItems[number]; // type NodeSettingsNav = 'General' | 'Unbond';