11import React , { useEffect , useState } from "react" ;
22import styled from "styled-components" ;
33import ReactMarkdown from "react-markdown" ;
4- import {
5- Routes ,
6- Route ,
7- Navigate ,
8- useParams ,
9- useNavigate ,
10- useLocation ,
11- } from "react-router-dom" ;
4+ import { Routes , Route , Navigate , useParams , useNavigate , useLocation } from "react-router-dom" ;
125import { Tabs } from "@kleros/ui-components-library" ;
136import { useCourtPolicy } from "queries/useCourtPolicy" ;
147
8+ interface IPolicy {
9+ description ?: string ;
10+ requiredSkills ?: string ;
11+ summary ?: string ;
12+ }
13+
1514const TABS = [
1615 {
1716 text : "Purpose" ,
1817 value : 0 ,
1918 path : "purpose" ,
20- isVisible : ( policy : any ) => ! ! policy ?. description ,
19+ isVisible : ( policy : IPolicy ) => ! ! policy ?. description ,
2120 } ,
2221 {
2322 text : "Skills" ,
2423 value : 1 ,
2524 path : "skills" ,
26- isVisible : ( policy : any ) => ! ! policy ?. requiredSkills ,
25+ isVisible : ( policy : IPolicy ) => ! ! policy ?. requiredSkills ,
2726 } ,
2827 {
2928 text : "Policy" ,
3029 value : 2 ,
3130 path : "policy" ,
32- isVisible : ( policy : any ) => ! ! policy ?. summary ,
31+ isVisible : ( policy : IPolicy ) => ! ! policy ?. summary ,
3332 } ,
3433] ;
3534
@@ -38,13 +37,8 @@ const Description: React.FC = () => {
3837 const { data : policy } = useCourtPolicy ( id ) ;
3938 const navigate = useNavigate ( ) ;
4039 const currentPathName = useLocation ( ) . pathname . split ( "/" ) . at ( - 1 ) ;
41- const [ currentTab , setCurrentTab ] = useState (
42- TABS . findIndex ( ( { path } ) => path === currentPathName )
43- ) ;
44- useEffect (
45- ( ) => setCurrentTab ( TABS . findIndex ( ( { path } ) => path === currentPathName ) ) ,
46- [ currentPathName ]
47- ) ;
40+ const [ currentTab , setCurrentTab ] = useState ( TABS . findIndex ( ( { path } ) => path === currentPathName ) ) ;
41+ useEffect ( ( ) => setCurrentTab ( TABS . findIndex ( ( { path } ) => path === currentPathName ) ) , [ currentPathName ] ) ;
4842
4943 const filteredTabs = TABS . filter ( ( { isVisible } ) => isVisible ( policy ) ) ;
5044
@@ -72,11 +66,7 @@ const Description: React.FC = () => {
7266
7367const formatMarkdown = ( markdown ?: string ) =>
7468 markdown ? (
75- < ReactMarkdown >
76- { typeof markdown === "string"
77- ? markdown . replace ( / \n / g, " \n" )
78- : markdown }
79- </ ReactMarkdown >
69+ < ReactMarkdown > { typeof markdown === "string" ? markdown . replace ( / \n / g, " \n" ) : markdown } </ ReactMarkdown >
8070 ) : (
8171 < p > Loading...</ p >
8272 ) ;
0 commit comments