-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Request user details on Welcome page load
Previously the page would require state params to be passed from the landing page, otherwise it would redirect back to it. The OAuth flow now returns the user to the Welcome screen after login, so it should make its own request for user info.
- Loading branch information
1 parent
f743966
commit 8b22815
Showing
4 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
import { Box, Heading, Text, VStack } from "@chakra-ui/react"; | ||
import { Box, Heading, Spinner, Text, VStack } from "@chakra-ui/react"; | ||
import { AxiosError } from "axios"; | ||
import { useHistory } from "react-router-dom"; | ||
|
||
import "./Welcome.css"; | ||
import { useUser } from "../../hooks/use-user"; | ||
import { QueryObserverResult } from "react-query"; | ||
import { User } from "../../data/user"; | ||
|
||
function Welcome() { | ||
const history = useHistory(); | ||
const state = history.location.state as WelcomeState; | ||
const user = useUser(); | ||
|
||
if (!state?.user) { | ||
history.replace("/"); | ||
return <></>; | ||
if (!user.data) { | ||
user.refetch().then((result: QueryObserverResult<User, AxiosError>) => { | ||
if (result.error) { | ||
history.replace("/"); | ||
} | ||
}); | ||
} | ||
|
||
if (user.isLoading || !user.data) { | ||
return ( | ||
<VStack spacing="24px"> | ||
<Spinner data-testid="spinner" marginTop={"50px"} /> | ||
</VStack> | ||
); | ||
} | ||
|
||
return ( | ||
<VStack spacing="24px"> | ||
<Heading>Welcome</Heading> | ||
<Box alignContent="left" width="50%"> | ||
<Text>Org id: {state.user.organizationUuid}</Text> | ||
<Text>Display name: {state.user.displayName}</Text> | ||
<Text>Org id: {user.data.organizationUuid}</Text> | ||
<Text>Display name: {user.data.displayName}</Text> | ||
</Box> | ||
</VStack> | ||
); | ||
} | ||
|
||
interface WelcomeState { | ||
user: User; | ||
} | ||
|
||
export default Welcome; |