1
1
import React , { useMemo } from "react" ;
2
2
import styled , { css } from "styled-components" ;
3
3
4
- import { AlertMessage , DropdownCascader } from "@kleros/ui-components-library" ;
4
+ import { AlertMessage , DropdownCascader , DropdownSelect } from "@kleros/ui-components-library" ;
5
5
6
6
import { useNewDisputeContext } from "context/NewDisputeContext" ;
7
7
import { rootCourtToItems , useCourtTree } from "hooks/queries/useCourtTree" ;
8
+ import { useSupportedDisputeKits } from "queries/useSupportedDisputeKits" ;
9
+ import { getDisputeKitName } from "consts/index" ;
8
10
import { isUndefined } from "utils/index" ;
9
11
10
12
import { landscapeStyle } from "styles/landscapeStyle" ;
@@ -49,28 +51,52 @@ const AlertMessageContainer = styled.div`
49
51
margin-top : 24px ;
50
52
` ;
51
53
54
+ const StyledDropdownSelect = styled ( DropdownSelect ) `
55
+ width: 84vw;
56
+ margin-top: 24px;
57
+ ${ landscapeStyle (
58
+ ( ) => css `
59
+ width : ${ responsiveSize ( 442 , 700 , 900 ) } ;
60
+ `
61
+ ) }
62
+ ` ;
63
+
52
64
const Court : React . FC = ( ) => {
53
65
const { disputeData, setDisputeData } = useNewDisputeContext ( ) ;
54
- const { data } = useCourtTree ( ) ;
55
- const items = useMemo ( ( ) => ! isUndefined ( data ?. court ) && [ rootCourtToItems ( data . court ) ] , [ data ] ) ;
56
-
57
- const handleWrite = ( courtId : string ) => {
58
- setDisputeData ( { ...disputeData , courtId : courtId } ) ;
66
+ const { data : courtTree } = useCourtTree ( ) ;
67
+ const { data : supportedDisputeKits } = useSupportedDisputeKits ( disputeData . courtId ) ;
68
+ const items = useMemo ( ( ) => ! isUndefined ( courtTree ?. court ) && [ rootCourtToItems ( courtTree . court ) ] , [ courtTree ] ) ;
69
+ const disputeKitOptions = useMemo ( ( ) => {
70
+ const supportedDisputeKitIDs = supportedDisputeKits ?. court ?. supportedDisputeKits . map ( ( k ) => Number ( k . id ) ) || [ ] ;
71
+ return supportedDisputeKitIDs . map ( ( id ) => ( { text : getDisputeKitName ( id ) , value : id } ) ) ;
72
+ } , [ supportedDisputeKits ] ) ;
73
+ const handleCourtWrite = ( courtId : string ) => {
74
+ setDisputeData ( { ...disputeData , courtId, disputeKitId : undefined } ) ;
59
75
} ;
60
76
77
+ const handleDisputeKitChange = ( newValue : string | number ) =>
78
+ setDisputeData ( { ...disputeData , disputeKitId : Number ( newValue ) } ) ;
79
+
61
80
return (
62
81
< Container >
63
82
< Header text = "Select a court to arbitrate the case" />
64
83
{ items ? (
65
84
< StyledDropdownCascader
66
85
items = { items }
67
- onSelect = { ( path : string | number ) => typeof path === "string" && handleWrite ( path . split ( "/" ) . pop ( ) ! ) }
86
+ onSelect = { ( path : string | number ) => typeof path === "string" && handleCourtWrite ( path . split ( "/" ) . pop ( ) ! ) }
68
87
placeholder = "Select Court"
69
88
value = { `/courts/${ disputeData . courtId } ` }
70
89
/>
71
90
) : (
72
91
< StyledSkeleton width = { 240 } height = { 42 } />
73
92
) }
93
+ < StyledDropdownSelect
94
+ items = { disputeKitOptions }
95
+ disabled = { ! disputeData . courtId }
96
+ placeholder = { { text : "Select Dispute Kit" } }
97
+ defaultValue = { disputeData . disputeKitId ?? 1 }
98
+ callback = { handleDisputeKitChange }
99
+ />
74
100
< AlertMessageContainer >
75
101
< AlertMessage
76
102
title = "Check the courts available beforehand"
@@ -82,4 +108,5 @@ const Court: React.FC = () => {
82
108
</ Container >
83
109
) ;
84
110
} ;
111
+
85
112
export default Court ;
0 commit comments