@@ -44,6 +44,11 @@ import { getEndpointUrl } from './utils/getEndpointUrl';
4444import { refreshToken } from './utils/refreshToken' ;
4545/* @conditional -compile-remove(rich-text-editor-composite-support) */
4646import { RichTextEditorToggle } from './RichTextEditorToggle' ;
47+ import {
48+ getDisplayNameFromLocalStorage ,
49+ localStorageAvailable ,
50+ saveDisplayNameToLocalStorage
51+ } from './utils/localStorage' ;
4752
4853// These props are set by the caller of ConfigurationScreen in the JSX and not found in context
4954export interface ConfigurationScreenProps {
@@ -94,6 +99,14 @@ export default (props: ConfigurationScreenProps): JSX.Element => {
9499 const theme = useTheme ( ) ;
95100 const { joinChatHandler, setToken, setUserId, setDisplayName, setThreadId, setEndpointUrl } = props ;
96101
102+ useEffect ( ( ) => {
103+ // Get display name from local storage if available
104+ const defaultDisplayName = localStorageAvailable ? getDisplayNameFromLocalStorage ( ) : null ;
105+ if ( defaultDisplayName ) {
106+ setName ( defaultDisplayName ) ;
107+ }
108+ } , [ ] ) ;
109+
97110 // Used when new user is being registered.
98111 const setupAndJoinChatThreadWithNewUser = useCallback ( ( ) => {
99112 const internalSetupAndJoinChatThread = async ( ) : Promise < void > => {
@@ -183,6 +196,7 @@ export default (props: ConfigurationScreenProps): JSX.Element => {
183196 if ( ! name ) {
184197 setEmptyWarning ( true ) ;
185198 } else {
199+ saveDisplayNameToLocalStorage ( name ) ;
186200 setEmptyWarning ( false ) ;
187201 setDisableJoinChatButton ( true ) ;
188202 setConfigurationScreenState ( CONFIGURATIONSCREEN_SHOWING_SPINNER_INITIALIZE_CHAT ) ;
@@ -252,6 +266,7 @@ export default (props: ConfigurationScreenProps): JSX.Element => {
252266 </ Stack >
253267 </ FocusZone >
254268 < DisplayNameField
269+ defaultName = { name }
255270 setName = { setName }
256271 setEmptyWarning = { setEmptyWarning }
257272 validateName = { validateName }
0 commit comments