1
1
import React from "react" ;
2
- import { TextField , Grid , Box } from "@mui/material" ;
2
+ import { TextField , Grid , Box , IconButton } from "@mui/material" ;
3
3
import { FormProvider , useForm } from "react-hook-form" ;
4
4
import * as yup from "yup" ;
5
5
import { yupResolver } from "@hookform/resolvers/yup" ;
@@ -11,7 +11,15 @@ import ControlledSelectV2 from "../shared/controlledInputComponents/ControlledSe
11
11
import { MasterContext } from "../shared/MasterContext" ;
12
12
import proponentService from "../../services/proponentService/proponentService" ;
13
13
import ControlledSwitch from "../shared/controlledInputComponents/ControlledSwitch" ;
14
- import LockClosed from "../../assets/images/lock-closed.svg" ;
14
+ import { When , If , Then , Else } from "react-if" ;
15
+ import {
16
+ SpecialFieldEntityEnum ,
17
+ SpecialFields ,
18
+ } from "../../constants/application-constant" ;
19
+ import Icons from "../icons" ;
20
+ import { IconProps } from "../icons/type" ;
21
+ import { Palette } from "../../styles/theme" ;
22
+ import { SpecialFieldGrid } from "../shared/specialField" ;
15
23
16
24
const schema = yup . object ( ) . shape ( {
17
25
name : yup
@@ -33,10 +41,14 @@ const schema = yup.object().shape({
33
41
} ) ,
34
42
} ) ;
35
43
44
+ const LockClosedIcon : React . FC < IconProps > = Icons [ "LockClosedIcon" ] ;
45
+ const LockOpenIcon : React . FC < IconProps > = Icons [ "LockOpenIcon" ] ;
46
+
36
47
export default function ProponentForm ( { ...props } ) {
37
48
const [ staffs , setStaffs ] = React . useState < Staff [ ] > ( [ ] ) ;
38
49
const [ disabled , setDisabled ] = React . useState < boolean > ( ) ;
39
50
const ctx = React . useContext ( MasterContext ) ;
51
+ const [ specialField , setSpecialField ] = React . useState < string > ( "" ) ;
40
52
41
53
React . useEffect ( ( ) => {
42
54
ctx . setFormId ( "proponent-form" ) ;
@@ -100,17 +112,24 @@ export default function ProponentForm({ ...props }) {
100
112
} }
101
113
>
102
114
< ETFormLabel required > Name</ ETFormLabel >
103
- < ETFormLabel >
104
- < Box
105
- sx = { {
106
- opacity : disabled ? "100" : "0" ,
107
- cursor : "pointer" ,
108
- } }
109
- component = "img"
110
- src = { LockClosed }
111
- alt = "Lock"
112
- />
113
- </ ETFormLabel >
115
+ < When condition = { disabled } >
116
+ < If condition = { specialField === SpecialFields . PROPONENT . NAME } >
117
+ < Then >
118
+ < IconButton onClick = { ( ) => setSpecialField ( "" ) } >
119
+ < LockOpenIcon fill = { Palette . primary . accent . main } />
120
+ </ IconButton >
121
+ </ Then >
122
+ < Else >
123
+ < IconButton
124
+ onClick = { ( ) =>
125
+ setSpecialField ( SpecialFields . PROPONENT . NAME )
126
+ }
127
+ >
128
+ < LockClosedIcon fill = { Palette . primary . accent . main } />
129
+ </ IconButton >
130
+ </ Else >
131
+ </ If >
132
+ </ When >
114
133
</ Box >
115
134
< Box sx = { { paddingTop : "4px" } } >
116
135
< TextField
@@ -126,8 +145,9 @@ export default function ProponentForm({ ...props }) {
126
145
</ Grid >
127
146
< Grid item xs = { 6 } >
128
147
< ETFormLabel > Relationship Holder</ ETFormLabel >
129
- < Box sx = { { paddingTop : "4px " } } >
148
+ < Box sx = { { paddingTop : Boolean ( specialField ) ? "15px" : "11px " } } >
130
149
< ControlledSelectV2
150
+ disabled = { Boolean ( specialField ) }
131
151
placeholder = "Select"
132
152
defaultValue = { ( ctx . item as Proponent ) ?. relationship_holder_id }
133
153
options = { staffs || [ ] }
@@ -137,8 +157,54 @@ export default function ProponentForm({ ...props }) {
137
157
> </ ControlledSelectV2 >
138
158
</ Box >
139
159
</ Grid >
160
+ < Grid item xs = { 12 } >
161
+ < When condition = { Boolean ( specialField ) } >
162
+ < SpecialFieldGrid
163
+ entity = { SpecialFieldEntityEnum . PROPONENT }
164
+ entity_id = { ( ctx . item as Proponent ) ?. id }
165
+ fieldName = { specialField }
166
+ fieldLabel = {
167
+ specialField === SpecialFields . PROPONENT . NAME
168
+ ? "Proponent Name"
169
+ : "Name"
170
+ }
171
+ fieldType = { "text" }
172
+ title = {
173
+ specialField === SpecialFields . PROPONENT . NAME
174
+ ? "Proponet History"
175
+ : ( ctx . item as Proponent ) ?. name
176
+ }
177
+ description = {
178
+ < >
179
+ < When
180
+ condition = {
181
+ specialField === SpecialFields . PROJECT . PROPONENT
182
+ }
183
+ >
184
+ Update the Proponent of this Project.{ " " }
185
+ < a href = "#" > Click this link</ a > for detailed instructions.
186
+ </ When >
187
+ < When
188
+ condition = { specialField === SpecialFields . PROJECT . NAME }
189
+ >
190
+ Update the legal name of the Project and the dates each
191
+ name was in legal use. < a href = "#" > Click this link</ a > for
192
+ detailed instructions
193
+ </ When >
194
+ </ >
195
+ }
196
+ onSave = { ( ) => {
197
+ // TODO: Refresh form field value for the specific field?
198
+ // OR do we just call form save/submit handler
199
+ ctx . setId ( props . proponentId ) ;
200
+ ctx . getById ( props . proponentId ) ;
201
+ } }
202
+ />
203
+ </ When >
204
+ </ Grid >
140
205
< Grid item xs = { 6 } sx = { { paddingTop : "30px !important" } } >
141
206
< ControlledSwitch
207
+ disabled = { Boolean ( specialField ) }
142
208
sx = { { paddingLeft : "0px" , marginRight : "10px" } }
143
209
name = "is_active"
144
210
/>
0 commit comments