Skip to content

Commit

Permalink
Adding error state as AppState
Browse files Browse the repository at this point in the history
  • Loading branch information
teresaqhoang committed Aug 11, 2023
1 parent acb3c9c commit 478bb35
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const useClasses = makeStyles({
enum AppState {
ProbeForBackend,
SettingUserInfo,
ErrorLoadingUserInfo,
LoadingChats,
Chat,
SigningOut,
Expand All @@ -62,8 +63,6 @@ const App: FC = () => {
const { instance, inProgress } = useMsal();
const { activeUserInfo, features } = useAppSelector((state: RootState) => state.app);
const isAuthenticated = useIsAuthenticated();
const defaultUserInfoStatusText = 'Hang tight while we fetch your information...';
const [userInfoStatusText, setUserInfoStatusText] = React.useState<string>(defaultUserInfoStatusText);

const chat = useChat();

Expand All @@ -73,9 +72,7 @@ const App: FC = () => {
if (activeUserInfo === undefined) {
const account = instance.getActiveAccount();
if (!account) {
setUserInfoStatusText(
'Oops, something went wrong. Please try signing out and signing back in.',
);
setAppState(AppState.ErrorLoadingUserInfo);
} else {
dispatch(
setActiveUserInfo({
Expand Down Expand Up @@ -151,12 +148,12 @@ const App: FC = () => {
}}
/>
)}
{appState === AppState.SettingUserInfo &&
(userInfoStatusText === defaultUserInfoStatusText ? (
<Loading text={userInfoStatusText} />
) : (
<Error text={userInfoStatusText} />
))}
{appState === AppState.SettingUserInfo && (
<Loading text={'Hang tight while we fetch your information...'} />
)}
{appState === AppState.ErrorLoadingUserInfo && (
<Error text={'Oops, something went wrong. Please try signing out and signing back in.'} />
)}
{appState === AppState.LoadingChats && <Loading text="Loading Chats..." />}
{appState === AppState.Chat && <ChatView />}
</div>
Expand Down

0 comments on commit 478bb35

Please sign in to comment.