1- import React , { useEffect , useState } from "react" ;
1+ import React , { useEffect , useMemo , useState } from "react" ;
22import styled , { css } from "styled-components" ;
33
44import { useNavigate } from "react-router-dom" ;
@@ -17,15 +17,13 @@ import { isUndefined } from "src/utils";
1717import { landscapeStyle } from "styles/landscapeStyle" ;
1818import { responsiveSize } from "styles/responsiveSize" ;
1919
20- import { Divider } from "components/Divider" ;
21- import LabeledInput from "components/LabeledInput" ;
20+ import Header from "../Header" ;
2221
23- import Header from "./Header " ;
22+ import CreationCard , { CreationMethod } from "./CreationCard " ;
2423
2524const Container = styled . div `
2625 display: flex;
2726 flex-direction: column;
28- gap: 24px;
2927 align-items: center;
3028 width: 84vw;
3129
@@ -34,38 +32,55 @@ const Container = styled.div`
3432 width: ${ responsiveSize ( 442 , 700 , 900 ) } ;
3533
3634 padding-bottom: 240px;
37- gap: 48px;
3835 `
3936 ) }
4037` ;
4138
42- const ErrorMsg = styled . small `
43- font-size: 16px;
44- color: ${ ( { theme } ) => theme . error } ;
39+ const CardContainer = styled . div `
40+ width: 100%;
41+ max-width: 720px;
42+ display: flex;
43+ flex-direction: column;
44+ gap: 16px;
45+ margin-bottom: 32px;
4546` ;
4647
4748const Landing : React . FC = ( ) => {
4849 const navigate = useNavigate ( ) ;
50+ const [ creationMethod , setCreationMethod ] = useState < CreationMethod > ( CreationMethod . Scratch ) ;
4951
5052 const [ disputeID , setDisputeID ] = useState < string > ( ) ;
5153 const [ debouncedDisputeID , setDebouncedDisputeID ] = useState < string > ( ) ;
5254 const { disputeData, setDisputeData } = useNewDisputeContext ( ) ;
5355 useDebounce ( ( ) => setDebouncedDisputeID ( disputeID ) , 500 , [ disputeID ] ) ;
5456
55- const { data : dispute } = useDisputeDetailsQuery ( debouncedDisputeID ) ;
57+ const { data : dispute , isLoading : isLoadingDispute } = useDisputeDetailsQuery ( debouncedDisputeID ) ;
5658 const {
5759 data : populatedDispute ,
5860 isError : isErrorPopulatedDisputeQuery ,
59- isLoading,
61+ isLoading : isPopulatingDispute ,
6062 } = usePopulatedDisputeData ( debouncedDisputeID , dispute ?. dispute ?. arbitrated . id as `0x${string } `) ;
6163
6264 // we want the genesis round's court and numberOfJurors
63- const { data : roundData , isError : isErrorRoundQuery } = useRoundDetailsQuery ( debouncedDisputeID , 0 ) ;
65+ const {
66+ data : roundData ,
67+ isError : isErrorRoundQuery ,
68+ isLoading : isLoadingRound ,
69+ } = useRoundDetailsQuery ( debouncedDisputeID , 0 ) ;
70+
71+ const isLoading = useMemo (
72+ ( ) => isLoadingDispute || isPopulatingDispute || isLoadingRound ,
73+ [ isLoadingDispute , isPopulatingDispute , isLoadingRound ]
74+ ) ;
6475
65- const isInvalidDispute =
66- ! isLoading &&
67- ! isUndefined ( populatedDispute ) &&
68- ( isErrorRoundQuery || isErrorPopulatedDisputeQuery || Object . keys ( populatedDispute ) . length === 0 ) ;
76+ const isInvalidDispute = useMemo ( ( ) => {
77+ if ( isUndefined ( debouncedDisputeID ) || isLoading ) return false ;
78+ if ( dispute ?. dispute === null ) return true ;
79+ if ( ! isUndefined ( populatedDispute ) ) {
80+ return isErrorRoundQuery || isErrorPopulatedDisputeQuery || Object . keys ( populatedDispute ) . length === 0 ;
81+ }
82+ return false ;
83+ } , [ debouncedDisputeID , isLoading , populatedDispute , isErrorRoundQuery , isErrorPopulatedDisputeQuery , dispute ] ) ;
6984
7085 useEffect ( ( ) => {
7186 if ( isUndefined ( populatedDispute ) || isUndefined ( roundData ) || isInvalidDispute ) return ;
@@ -96,31 +111,35 @@ const Landing: React.FC = () => {
96111 answers,
97112 aliasesArray,
98113 } ) ;
114+ // eslint-disable-next-line react-hooks/exhaustive-deps
99115 } , [ populatedDispute , roundData , isInvalidDispute ] ) ;
100116
101- const showContinueButton =
102- ! isUndefined ( disputeData ) && ! isUndefined ( populatedDispute ) && ! isInvalidDispute && ! isUndefined ( roundData ) ;
103117 return (
104118 < Container >
105119 < Header text = "Create a case" />
106- < Button text = "Create from Scratch" onClick = { ( ) => navigate ( "/resolver/title" ) } />
107-
108- < Divider />
109- < LabeledInput
110- value = { disputeID }
111- onChange = { ( e ) => setDisputeID ( e . target . value ) }
112- placeholder = "Dispute ID"
113- label = "Duplicate an exiting case."
114- type = "number"
115- onInput = { ( e ) => {
116- const value = e . currentTarget . value . replace ( / \D / g, "" ) ;
117-
118- e . currentTarget . value = value ;
119- return e ;
120- } }
120+ < CardContainer >
121+ < CreationCard
122+ cardMethod = { CreationMethod . Scratch }
123+ selectedMethod = { creationMethod }
124+ { ...{ disputeID, setDisputeID, setCreationMethod, isInvalidDispute } }
125+ />
126+ < CreationCard
127+ cardMethod = { CreationMethod . Duplicate }
128+ selectedMethod = { creationMethod }
129+ { ...{ disputeID, setDisputeID, setCreationMethod, isInvalidDispute } }
130+ />
131+ </ CardContainer >
132+
133+ < Button
134+ text = "Next"
135+ isLoading = { isLoading }
136+ disabled = {
137+ isLoading ||
138+ isInvalidDispute ||
139+ ( creationMethod === CreationMethod . Duplicate && isUndefined ( debouncedDisputeID ) )
140+ }
141+ onClick = { ( ) => navigate ( "/resolver/title" ) }
121142 />
122- { isInvalidDispute ? < ErrorMsg > Error loading dispute data. Please use another dispute.</ ErrorMsg > : null }
123- { showContinueButton ? < Button small text = "Continue" onClick = { ( ) => navigate ( "/resolver/title" ) } /> : null }
124143 </ Container >
125144 ) ;
126145} ;
0 commit comments