@@ -42,6 +42,11 @@ import {
4242import { joinThread } from './utils/joinThread' ;
4343import { getEndpointUrl } from './utils/getEndpointUrl' ;
4444import { refreshToken } from './utils/refreshToken' ;
45+ import {
46+ getDisplayNameFromLocalStorage ,
47+ localStorageAvailable ,
48+ saveDisplayNameToLocalStorage
49+ } from './utils/localStorage' ;
4550
4651// These props are set by the caller of ConfigurationScreen in the JSX and not found in context
4752export interface ConfigurationScreenProps {
@@ -90,6 +95,14 @@ export default (props: ConfigurationScreenProps): JSX.Element => {
9095 const theme = useTheme ( ) ;
9196 const { joinChatHandler, setToken, setUserId, setDisplayName, setThreadId, setEndpointUrl } = props ;
9297
98+ useEffect ( ( ) => {
99+ // Get display name from local storage if available
100+ const defaultDisplayName = localStorageAvailable ? getDisplayNameFromLocalStorage ( ) : null ;
101+ if ( defaultDisplayName ) {
102+ setName ( defaultDisplayName ) ;
103+ }
104+ } , [ ] ) ;
105+
93106 // Used when new user is being registered.
94107 const setupAndJoinChatThreadWithNewUser = useCallback ( ( ) => {
95108 const internalSetupAndJoinChatThread = async ( ) : Promise < void > => {
@@ -179,6 +192,7 @@ export default (props: ConfigurationScreenProps): JSX.Element => {
179192 if ( ! name ) {
180193 setEmptyWarning ( true ) ;
181194 } else {
195+ saveDisplayNameToLocalStorage ( name ) ;
182196 setEmptyWarning ( false ) ;
183197 setDisableJoinChatButton ( true ) ;
184198 setConfigurationScreenState ( CONFIGURATIONSCREEN_SHOWING_SPINNER_INITIALIZE_CHAT ) ;
@@ -246,6 +260,7 @@ export default (props: ConfigurationScreenProps): JSX.Element => {
246260 </ Stack >
247261 </ FocusZone >
248262 < DisplayNameField
263+ defaultName = { name }
249264 setName = { setName }
250265 setEmptyWarning = { setEmptyWarning }
251266 validateName = { validateName }
0 commit comments