11import React , { useMemo } from "react" ;
22import styled , { css } from "styled-components" ;
33
4- import { AlertMessage , DropdownCascader } from "@kleros/ui-components-library" ;
4+ import { AlertMessage , DropdownCascader , DropdownSelect } from "@kleros/ui-components-library" ;
55
66import { useNewDisputeContext } from "context/NewDisputeContext" ;
77import { rootCourtToItems , useCourtTree } from "hooks/queries/useCourtTree" ;
8+ import { useSupportedDisputeKits } from "queries/useSupportedDisputeKits" ;
9+ import { getDisputeKitName } from "consts/index" ;
810import { isUndefined } from "utils/index" ;
911
1012import { landscapeStyle } from "styles/landscapeStyle" ;
@@ -49,28 +51,52 @@ const AlertMessageContainer = styled.div`
4951 margin-top : 24px ;
5052` ;
5153
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+
5264const Court : React . FC = ( ) => {
5365 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 } ) ;
5975 } ;
6076
77+ const handleDisputeKitChange = ( newValue : string | number ) =>
78+ setDisputeData ( { ...disputeData , disputeKitId : Number ( newValue ) } ) ;
79+
6180 return (
6281 < Container >
6382 < Header text = "Select a court to arbitrate the case" />
6483 { items ? (
6584 < StyledDropdownCascader
6685 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 ( ) ! ) }
6887 placeholder = "Select Court"
6988 value = { `/courts/${ disputeData . courtId } ` }
7089 />
7190 ) : (
7291 < StyledSkeleton width = { 240 } height = { 42 } />
7392 ) }
93+ < StyledDropdownSelect
94+ items = { disputeKitOptions }
95+ disabled = { ! disputeData . courtId }
96+ placeholder = { { text : "Select Dispute Kit" } }
97+ defaultValue = { disputeData . disputeKitId ?? 1 }
98+ callback = { handleDisputeKitChange }
99+ />
74100 < AlertMessageContainer >
75101 < AlertMessage
76102 title = "Check the courts available beforehand"
@@ -82,4 +108,5 @@ const Court: React.FC = () => {
82108 </ Container >
83109 ) ;
84110} ;
111+
85112export default Court ;
0 commit comments