11// Libraries
2- import React , { FC , useContext , useState } from 'react'
3- import { Button , IconFont , Overlay , Page } from '@influxdata/clockface'
2+ import React , { FC , useContext , useEffect , useState } from 'react'
3+ import {
4+ Button ,
5+ ComponentSize ,
6+ FlexBox ,
7+ FlexDirection ,
8+ IconFont ,
9+ Input ,
10+ InputType ,
11+ Overlay ,
12+ Page ,
13+ } from '@influxdata/clockface'
414
515// Utils
616import { pageTitleSuffixer } from 'src/shared/utils/pageTitles'
7- import { UserAccountProvider } from 'src/accounts/context/userAccount'
17+ import {
18+ UserAccountContext ,
19+ UserAccountProvider ,
20+ } from 'src/accounts/context/userAccount'
821import AccountTabContainer from 'src/accounts/AccountTabContainer'
922
10- import { UserAccountContext } from 'src/accounts/context/userAccount'
11-
1223import { SwitchAccountOverlay } from 'src/accounts/SwitchAccountOverlay'
1324
1425const AccountAboutPage : FC = ( ) => {
15- const { userAccounts} = useContext ( UserAccountContext )
26+ const { userAccounts, handleRenameActiveAccount} = useContext (
27+ UserAccountContext
28+ )
1629 const [ isSwitchAccountVisible , setSwitchAccountVisible ] = useState ( false )
1730
1831 /**
@@ -22,10 +35,22 @@ const AccountAboutPage: FC = () => {
2235 *
2336 * and one of the accounts has to be active (the one that the user currently
2437 * is logged in as)
38+ *
39+ * but note that at first load, the accounts may not be loaded yet. hence, the useEffect
40+ * to re-initialize the activeAcctName
2541 */
42+ const activeAccount =
43+ userAccounts && userAccounts . filter ( acct => acct . isActive ) [ 0 ]
44+ const [ activeAcctName , setActiveAcctName ] = useState ( activeAccount ?. name )
2645
27- const activeAcctName =
28- userAccounts && userAccounts . filter ( acct => acct . isActive ) [ 0 ] . name
46+ // needed b/c the context updates the page once the active accts are loaded
47+ useEffect ( ( ) => {
48+ setActiveAcctName ( activeAccount ?. name )
49+ } , [ activeAccount ] )
50+
51+ const updateAcctName = evt => {
52+ setActiveAcctName ( evt . target . value )
53+ }
2954
3055 const showSwitchAccountDialog = ( ) => {
3156 setSwitchAccountVisible ( true )
@@ -35,24 +60,45 @@ const AccountAboutPage: FC = () => {
3560 setSwitchAccountVisible ( false )
3661 }
3762
63+ const inputStyle = { width : 250 }
64+ const labelStyle = { marginBottom : 8 }
65+
3866 return (
3967 < Page titleTag = { pageTitleSuffixer ( [ 'About' , 'Account' ] ) } >
4068 < AccountTabContainer activeTab = "about" >
4169 < >
4270 { userAccounts && userAccounts . length >= 2 && (
43- < Button
44- text = "Switch Account"
45- icon = { IconFont . Switch_New }
46- onClick = { showSwitchAccountDialog }
47- testID = "user-account-switch-btn"
48- />
71+ < React . Fragment >
72+ < Button
73+ text = "Switch Account"
74+ icon = { IconFont . Switch_New }
75+ onClick = { showSwitchAccountDialog }
76+ testID = "user-account-switch-btn"
77+ />
78+ < hr />
79+ </ React . Fragment >
4980 ) }
50- < hr />
51- < h2 data-testid = "account-settings--header" > Account Details </ h2 >
52- < div data-testid = "account-active-name--block" >
53- Currently logged in Active Account: { activeAcctName }
54- </ div >
5581
82+ < h2 data-testid = "account-settings--header" > Account Details </ h2 >
83+ < div style = { labelStyle } > Account Name</ div >
84+ < FlexBox direction = { FlexDirection . Row } margin = { ComponentSize . Medium } >
85+ < Input
86+ name = "accountName"
87+ testID = "input--active-account-name"
88+ type = { InputType . Text }
89+ value = { activeAcctName }
90+ onChange = { updateAcctName }
91+ size = { ComponentSize . Medium }
92+ style = { inputStyle }
93+ />
94+ < Button
95+ onClick = { ( ) =>
96+ handleRenameActiveAccount ( activeAccount . id , activeAcctName )
97+ }
98+ testID = "rename-account--button"
99+ text = "Save"
100+ />
101+ </ FlexBox >
56102 < Overlay visible = { isSwitchAccountVisible } >
57103 < SwitchAccountOverlay onDismissOverlay = { closeSwitchAccountDialog } />
58104 </ Overlay >
0 commit comments