-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a6b4e8a
commit 404b5d5
Showing
6 changed files
with
19 additions
and
25 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,34 +1,30 @@ | ||
import { FC, useMemo } from "react"; | ||
import { FC } from "react"; | ||
import { useCurrentUser, useMutateCurrentUser } from "../hooks/currentUser"; | ||
import { Button, Container, Heading } from "@chakra-ui/react"; | ||
import { Box, Button, Center, Container, Heading, Skeleton } from "@chakra-ui/react"; | ||
import useOrderCloudContext from "../hooks/useOrderCloudContext"; | ||
import { WarningIcon } from "@chakra-ui/icons"; | ||
|
||
const Profile: FC = () => { | ||
const {isLoggedIn} = useOrderCloudContext(); | ||
const { data: user, status, error } = useCurrentUser(); | ||
const { data: user, isError, isPending:isLoading } = useCurrentUser(); | ||
const {mutate, isPending} = useMutateCurrentUser(); | ||
|
||
const content = useMemo(() => { | ||
switch (status) { | ||
case "pending": | ||
return "PENDING"; | ||
case "error": | ||
return <pre>{JSON.stringify(error, null, 2)}</pre>; | ||
case "success": | ||
return isLoggedIn ? ( | ||
|
||
return <Container maxW="full" pt={6} px={8}> | ||
<Skeleton isLoaded={!isLoading}> | ||
{isError ? ( | ||
<Box as={Center}><Heading><WarningIcon/></Heading></Box> | ||
) : isLoggedIn ? ( | ||
<> | ||
<Heading size="md" mb={5}>{`Welcome ${user.FirstName} ${user.LastName}!`}</Heading> | ||
<Heading size="md" mb={5}>{`Welcome ${user?.FirstName} ${user?.LastName}!`}</Heading> | ||
<Button isDisabled={isPending} onClick={() => mutate({FirstName: "Buyer", LastName: "User"})}>Change Name</Button> | ||
</> | ||
) : ( | ||
<> | ||
<Heading size="md">Welcome to the app!</Heading> | ||
</> | ||
); | ||
} | ||
}, [error, isLoggedIn, isPending, mutate, status, user]) | ||
|
||
return <Container maxW="full" pt={6} px={8}>{content}</Container> | ||
)} | ||
</Skeleton> | ||
</Container> | ||
}; | ||
|
||
export default Profile; |
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