@@ -3,7 +3,7 @@ import { makeStyles } from "@material-ui/core/styles";
3
3
import { Theme } from "@material-ui/core/styles/createMuiTheme" ;
4
4
import { ArrowBackIos , CameraAlt } from "@material-ui/icons" ;
5
5
import { getBackdropStart , getBackdropStop } from 'app/BackdropSlice' ;
6
- import { setCurrentVisitor , defaultVisitor } from 'features/Home/visitorSlice' ;
6
+ import { setCurrentVisitor , defaultVisitor , fetchVisitors } from 'features/Home/visitorSlice' ;
7
7
import React , { FunctionComponent , useEffect } from 'react' ;
8
8
import { useDispatch , useSelector } from "react-redux" ;
9
9
import { RouteComponentProps } from 'react-router-dom' ;
@@ -15,6 +15,7 @@ import TextInput from "../../components/TextInput";
15
15
import { config as VisitorFormConfig } from 'features/Settings/VisitorFormConfig' ;
16
16
import { fetchVisitorConfigs } from "features/Settings/visitorConfigSlice" ;
17
17
import img from 'assets/logo/logo.png'
18
+ import { fetchSites } from "features/SalesAndOrganisation/siteSlice" ;
18
19
19
20
const useStyles = makeStyles ( ( theme : Theme ) => createStyles ( {
20
21
paper : {
@@ -130,9 +131,13 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
130
131
visitors,
131
132
visitorsById,
132
133
currentVisitor,
134
+ purpose : purposeOptions ,
133
135
isLoading : isLoadingVisitor ,
134
136
error
135
137
} = useSelector ( ( state : RootState ) => state . visitors )
138
+ const {
139
+ sites
140
+ } = useSelector ( ( state : RootState ) => state . sites )
136
141
//const inputState = currentVisitor
137
142
const {
138
143
mask
@@ -174,6 +179,11 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
174
179
id != - 1 && dispatch ( setCurrentVisitor ( visitorsById [ id ] || defaultVisitor ) ) ;
175
180
} , [ id ] )
176
181
182
+ useEffect ( ( ) => {
183
+ dispatch ( fetchVisitors ( ) )
184
+ dispatch ( fetchSites ( ) )
185
+ } , [ dispatch ] )
186
+
177
187
const handleSubmit = async ( e : any ) => {
178
188
dispatch ( getBackdropStart ( ) )
179
189
let bodyFormData = new FormData ( ) ;
@@ -216,6 +226,21 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
216
226
. then ( ( ) => dispatch ( getBackdropStop ( ) ) ) . catch ( ( ) => dispatch ( getBackdropStop ( ) ) )
217
227
}
218
228
229
+ const handlePurpose = ( value : any ) => {
230
+ dispatch ( setCurrentVisitor ( {
231
+ ...currentVisitor ,
232
+ purpose : value
233
+ } ) ) ;
234
+ }
235
+
236
+
237
+ const handleAutoComplete = ( obj : any ) => {
238
+ dispatch ( setCurrentVisitor ( {
239
+ ...currentVisitor ,
240
+ ...obj
241
+ } ) ) ;
242
+ }
243
+
219
244
const visitorSectionFields = VisitorFormConfig .
220
245
filter ( i => i . section === "VI" && visitorConfigsById [ i . id ] && visitorConfigsById [ i . id ] . value ) .
221
246
sort ( ( a , b ) => ( a . seq - b . seq ) ) .
@@ -227,9 +252,23 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
227
252
{ /* <TextInput style={{ width: 446, marginLeft: '64px' }} label={o.name} name={o.id} onChange={handleChange}
228
253
//@ts -ignore
229
254
value={currentVisitor[o.id]} /> */ }
230
- < TextInput style = { i % 2 === 0 ? { width : 446 , marginLeft : '64px' } : { width : 446 , marginLeft : '28px' } } label = { o . name } name = { o . id } onChange = { handleChange }
231
- //@ts -ignore
232
- value = { currentVisitor [ o . id ] } />
255
+ { o . component ?
256
+ o . component ( {
257
+ purpose : {
258
+ options : purposeOptions ,
259
+ onChange : handleAutoComplete ,
260
+ value : purpose
261
+ } ,
262
+ style : {
263
+ width : 446 ,
264
+ marginLeft : i % 2 === 0 ? '64px' : '28px'
265
+ }
266
+ } )
267
+ :
268
+ < TextInput style = { i % 2 === 0 ? { width : 446 , marginLeft : '64px' } : { width : 446 , marginLeft : '28px' } } label = { o . name } name = { o . id } onChange = { handleChange }
269
+ //@ts -ignore
270
+ value = { currentVisitor [ o . id ] } />
271
+ }
233
272
</ Grid >
234
273
) )
235
274
const appointmentSectionFields = VisitorFormConfig .
@@ -240,9 +279,23 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
240
279
// style={{ marginTop: '52px' }}
241
280
key = { o . id } >
242
281
{ /* {(o.render && o.render(notificationById[i], handleChange, i + "-" + o.key)) || obj[o.key]} */ }
243
- < TextInput style = { i % 2 === 0 ? { width : 446 , marginLeft : '64px' } : { width : 446 , marginLeft : '28px' } } label = { o . name } name = { o . id } onChange = { handleChange }
244
- //@ts -ignore
245
- value = { currentVisitor [ o . id ] } />
282
+ { o . component ?
283
+ o . component ( {
284
+ site : {
285
+ options : sites . map ( o => o . sitename ) , //siteOptions ||
286
+ onChange : handleAutoComplete ,
287
+ value : site
288
+ } ,
289
+ style : {
290
+ width : 446 ,
291
+ marginLeft : i % 2 === 0 ? '64px' : '28px'
292
+ }
293
+ } )
294
+ :
295
+ < TextInput style = { i % 2 === 0 ? { width : 446 , marginLeft : '64px' } : { width : 446 , marginLeft : '28px' } } label = { o . name } name = { o . id } onChange = { handleChange }
296
+ //@ts -ignore
297
+ value = { currentVisitor [ o . id ] } />
298
+ }
246
299
</ Grid >
247
300
) )
248
301
0 commit comments