1
1
import * as yup from 'yup'
2
- import { FC } from 'react'
2
+ import { FC , useMemo } from 'react'
3
+ import { useFormContext } from 'react-hook-form'
3
4
import classNames from 'classnames'
4
5
5
6
import {
7
+ categoryByProjectType ,
8
+ ProjectType ,
6
9
ProjectTypeLabels ,
7
10
scorecardCategories ,
8
11
ScorecardStatusLabels ,
@@ -19,7 +22,14 @@ const statusOptions = Object.entries(ScorecardStatusLabels)
19
22
. map ( ( [ value , label ] ) => ( { label, value } ) )
20
23
const typeOptions = Object . entries ( ScorecardTypeLabels )
21
24
. map ( ( [ value , label ] ) => ( { label, value } ) )
22
- const categoryOptions = scorecardCategories . map ( key => ( { label : key , value : key } ) )
25
+ const categoryOptions = ( projectType ?: ProjectType ) : { label : string ; value : string } [ ] => {
26
+ let categories = scorecardCategories
27
+ if ( projectType ) {
28
+ categories = categoryByProjectType [ projectType ]
29
+ }
30
+
31
+ return categories . map ( key => ( { label : key , value : key } ) )
32
+ }
23
33
24
34
export const scorecardInfoSchema = {
25
35
challengeTrack : yup . string ( )
@@ -47,67 +57,73 @@ export const scorecardInfoSchema = {
47
57
. required ( 'Version is required' ) ,
48
58
}
49
59
50
- const ScorecardInfoForm : FC = ( ) => (
51
- < div className = { classNames ( styles . grayWrapper , styles . scorecardInfo ) } >
52
- < InputWrapper
53
- label = 'Scorecard Name'
54
- name = 'name'
55
- className = { styles . mdWidthInput }
56
- >
57
- < input type = 'text' />
58
- </ InputWrapper >
59
- < InputWrapper
60
- label = 'Category'
61
- name = 'challengeType'
62
- className = { styles . mdWidthInput }
63
- >
64
- < BasicSelect options = { categoryOptions } />
65
- </ InputWrapper >
66
- < InputWrapper
67
- label = 'Version'
68
- name = 'version'
69
- className = { styles . mdWidthInput }
70
- >
71
- < input type = 'text' />
72
- </ InputWrapper >
73
- < InputWrapper
74
- label = 'Status'
75
- name = 'status'
76
- className = { styles . mdWidthInput }
77
- >
78
- < BasicSelect options = { statusOptions } />
79
- </ InputWrapper >
80
- < InputWrapper
81
- label = 'Type'
82
- name = 'type'
83
- className = { styles . mdWidthInput }
84
- >
85
- < BasicSelect options = { typeOptions } />
86
- </ InputWrapper >
87
- < div className = { classNames ( styles . mdWidthInput , styles . doubleInputWrap ) } >
60
+ const ScorecardInfoForm : FC = ( ) => {
61
+ const form = useFormContext ( )
62
+ const challengeTrack = form . watch ( 'challengeTrack' )
63
+ const categories = useMemo ( ( ) => categoryOptions ( challengeTrack ) , [ challengeTrack ] )
64
+
65
+ return (
66
+ < div className = { classNames ( styles . grayWrapper , styles . scorecardInfo ) } >
67
+ < InputWrapper
68
+ label = 'Scorecard Name'
69
+ name = 'name'
70
+ className = { styles . mdWidthInput }
71
+ >
72
+ < input type = 'text' />
73
+ </ InputWrapper >
74
+ < InputWrapper
75
+ label = 'Category'
76
+ name = 'challengeType'
77
+ className = { styles . mdWidthInput }
78
+ >
79
+ < BasicSelect options = { categories } />
80
+ </ InputWrapper >
81
+ < InputWrapper
82
+ label = 'Version'
83
+ name = 'version'
84
+ className = { styles . mdWidthInput }
85
+ >
86
+ < input type = 'text' />
87
+ </ InputWrapper >
88
88
< InputWrapper
89
- label = 'Min. Score '
90
- name = 'minScore '
91
- className = { styles . qWidthInput }
89
+ label = 'Status '
90
+ name = 'status '
91
+ className = { styles . mdWidthInput }
92
92
>
93
- < input type = 'number' />
93
+ < BasicSelect options = { statusOptions } />
94
94
</ InputWrapper >
95
95
< InputWrapper
96
- label = 'Max. Score '
97
- name = 'maxScore '
98
- className = { styles . qWidthInput }
96
+ label = 'Type '
97
+ name = 'type '
98
+ className = { styles . mdWidthInput }
99
99
>
100
- < input type = 'number' />
100
+ < BasicSelect options = { typeOptions } />
101
+ </ InputWrapper >
102
+ < div className = { classNames ( styles . mdWidthInput , styles . doubleInputWrap ) } >
103
+ < InputWrapper
104
+ label = 'Min. Score'
105
+ name = 'minScore'
106
+ className = { styles . qWidthInput }
107
+ >
108
+ < input type = 'number' />
109
+ </ InputWrapper >
110
+ < InputWrapper
111
+ label = 'Max. Score'
112
+ name = 'maxScore'
113
+ className = { styles . qWidthInput }
114
+ >
115
+ < input type = 'number' />
116
+ </ InputWrapper >
117
+ </ div >
118
+ < InputWrapper
119
+ label = 'Project Type'
120
+ name = 'challengeTrack'
121
+ className = { styles . mdWidthInput }
122
+ >
123
+ < BasicSelect options = { projectTypeOptions } />
101
124
</ InputWrapper >
102
125
</ div >
103
- < InputWrapper
104
- label = 'Project Type'
105
- name = 'challengeTrack'
106
- className = { styles . mdWidthInput }
107
- >
108
- < BasicSelect options = { projectTypeOptions } />
109
- </ InputWrapper >
110
- </ div >
111
- )
126
+ )
127
+ }
112
128
113
129
export default ScorecardInfoForm
0 commit comments