11import { Heading , Spinner , Text , Container , Box } from "@chakra-ui/react" ;
22import { useRouter } from "next/router" ;
3- import { Fragment , useMemo } from "react" ;
3+ import { FC , Fragment , useMemo } from "react" ;
44import { useGetEventById } from "../../hooks/useEventManager" ;
55import LoginRequired from "../../components/atoms/web3/LoginRequired" ;
66import { useLocale } from "../../hooks/useLocale" ;
@@ -9,15 +9,13 @@ import { MintForm } from "src/components/organisms/nft/MintForm";
99import { useAddress } from "@thirdweb-dev/react" ;
1010import { useGetOwnedNFTByAddress } from "src/hooks/useMintNFT" ;
1111import { NFTItem } from "src/components/atoms/nft/NFTItem" ;
12+ import { Event } from "types/Event" ;
1213
13- const Event = ( ) => {
14- const router = useRouter ( ) ;
15- const { eventid } = router . query ;
16- const { event, loading : fetchingEvent } = useGetEventById ( Number ( eventid ) ) ;
14+ const MintNFTSection : FC < { event : Event . EventRecord } > = ( { event } ) => {
1715 const address = useAddress ( ) ;
18- const { t } = useLocale ( ) ;
1916 const { nfts, isLoading : checkHoldingNFTs } =
2017 useGetOwnedNFTByAddress ( address ) ;
18+
2119 const holdingNFT = useMemo ( ( ) => {
2220 return nfts . find (
2321 ( nft ) =>
@@ -26,6 +24,32 @@ const Event = () => {
2624 ) ;
2725 } , [ nfts , address ] ) ;
2826
27+ return (
28+ < >
29+ { checkHoldingNFTs || ! address ? (
30+ < Spinner />
31+ ) : holdingNFT ? (
32+ < Box maxW = { 200 } mx = "auto" cursor = "pointer" >
33+ < NFTItem
34+ shareURL = { false }
35+ nft = { holdingNFT }
36+ tokenId = { holdingNFT . tokenId }
37+ />
38+ </ Box >
39+ ) : (
40+ < MintForm event = { event } address = { address } />
41+ ) }
42+ </ >
43+ ) ;
44+ } ;
45+
46+ const Event : FC = ( ) => {
47+ const router = useRouter ( ) ;
48+ const { eventid } = router . query ;
49+ const { event, loading : fetchingEvent } = useGetEventById ( Number ( eventid ) ) ;
50+
51+ const { t } = useLocale ( ) ;
52+
2953 return (
3054 < >
3155 < Container maxW = { 800 } py = { 6 } pb = "120px" >
@@ -47,19 +71,7 @@ const Event = () => {
4771 requiredChainID = { + process . env . NEXT_PUBLIC_CHAIN_ID ! }
4872 forbiddenText = { t . SIGN_IN_TO_GET_NFT }
4973 >
50- { checkHoldingNFTs || ! address ? (
51- < Spinner />
52- ) : holdingNFT ? (
53- < Box maxW = { 200 } mx = "auto" cursor = "pointer" >
54- < NFTItem
55- shareURL = { false }
56- nft = { holdingNFT }
57- tokenId = { holdingNFT . tokenId }
58- />
59- </ Box >
60- ) : (
61- < MintForm event = { event } address = { address } />
62- ) }
74+ < MintNFTSection event = { event } />
6375 </ LoginRequired >
6476 </ >
6577 ) }
0 commit comments