@@ -5,11 +5,13 @@ import { ArrowBackIos } from "@material-ui/icons";
5
5
// import { saveCheckInPoint, setCurrentCheckInPoint } from './checkInPointSlice';
6
6
import { RootState } from 'app/rootReducer' ;
7
7
import CustomButton from "components/Button" ;
8
+ import { CustomAutoComplete } from "components/CustomAutoComplete" ;
8
9
import TextInput from "components/TextInput" ;
9
10
import React , { FunctionComponent , useEffect } from 'react' ;
10
11
import { useDispatch , useSelector } from "react-redux" ;
11
12
import { RouteComponentProps } from 'react-router-dom' ;
12
- import { defaultInputState , saveCheckInPoint , setCurrentCheckInPoint } from './checkInPointSlice' ;
13
+ import { CheckInPointInputState , defaultInputState , saveCheckInPoint , setCurrentCheckInPoint } from './checkInPointSlice' ;
14
+ import { fetchSites } from "./siteSlice" ;
13
15
14
16
const useStyles = makeStyles ( ( theme : Theme ) => createStyles ( {
15
17
paper : {
@@ -66,26 +68,19 @@ const CheckInPointForm: FunctionComponent<Props> = (props) => {
66
68
error
67
69
} = useSelector ( ( state : RootState ) => state . checkinpoints )
68
70
71
+ const { sites} = useSelector ( ( state : RootState ) => state . sites )
72
+
69
73
const {
70
74
sitename,
71
75
device,
72
76
checkinpoint,
73
77
} = currentCheckInPoint
74
78
const inputState = currentCheckInPoint ;
75
79
76
- const setInputState = ( checkInPoint : any ) => {
80
+ const setInputState = ( checkInPoint : CheckInPointInputState ) => {
77
81
dispatch ( setCurrentCheckInPoint ( checkInPoint ) ) ;
78
82
}
79
83
80
- // const id = props.match.params.checkInPointId
81
- // // debugger;
82
- // useEffect(() => {
83
- // // if (checkInPointsById[id]) {
84
- // // const tempId = checkInPointsById[id]
85
- // // //setInputState(tempId)
86
- // // dispatch(setCurrentCheckInPoint(tempId));
87
- // // }
88
- // }, [id])
89
84
90
85
const handleChange = ( e : any ) => setInputState ( {
91
86
...inputState ,
@@ -101,9 +96,19 @@ const CheckInPointForm: FunctionComponent<Props> = (props) => {
101
96
} ) , ( ) => setInputState ( defaultInputState ) ) )
102
97
}
103
98
99
+ const handleSiteChange = ( sitename : string ) => {
100
+ setInputState ( {
101
+ ...inputState ,
102
+ sitename : sitename
103
+ } ) ;
104
+ }
105
+
106
+ useEffect ( ( ) => {
107
+ dispatch ( fetchSites ( ) )
108
+ } , [ dispatch ] )
104
109
105
110
return (
106
- < Grid item style = { { height : '80%' , width : '90%' } } >
111
+ < Grid item xs = { 12 } style = { { marginRight : 30 } } >
107
112
< Paper className = { classes . paper } >
108
113
< form onSubmit = { handleSubmit } >
109
114
< div className = { classes . header } >
@@ -118,10 +123,21 @@ const CheckInPointForm: FunctionComponent<Props> = (props) => {
118
123
< Grid className = { classes . inputGrid } container >
119
124
< Grid item xs = { 6 } >
120
125
{ /*<div>*/ }
121
- < TextInput label = "CheckInPoint Name"
126
+ { /* <TextInput label="Site Name"
122
127
required
123
128
name="sitename"
124
129
onChange={handleChange}
130
+ value={sitename} /> */ }
131
+ < CustomAutoComplete
132
+ style = { {
133
+ // width: 452,
134
+ // marginLeft: i % 2 === 0 ? '64px' : '28px'
135
+ } }
136
+ required
137
+ options = { sites . map ( o => o . sitename ) }
138
+ label = "Site"
139
+ name = "sitename"
140
+ onChange = { ( value : any ) => handleSiteChange ( value ) }
125
141
value = { sitename } />
126
142
< TextInput
127
143
required
0 commit comments