@@ -34,6 +34,7 @@ import { CustomMenuItem } from 'components/CustomMenuItem';
34
34
import Axios from 'axios' ;
35
35
import { apis , checkout , serverUrl } from 'api/Apis' ;
36
36
import { getBackdropStart , getBackdropStop } from 'app/BackdropSlice' ;
37
+ import CustomizedSwitch from 'components/Switch' ;
37
38
38
39
const useStyles = makeStyles ( ( theme : Theme ) =>
39
40
createStyles ( {
@@ -120,11 +121,14 @@ const ContractorView: FunctionComponent<Props> = (props) => {
120
121
const [ rowPerPage , setRowPerPage ] = useState ( 10 ) ;
121
122
const [ anchorEl , setAnchorEl ] = useState < null | HTMLElement > ( null ) ;
122
123
const [ filter , setFilter ] = useState ( { contractor : "" , purpose : "" , site : "" } )
124
+ const [ inOffice , setInOffice ] = useState ( false ) ;
123
125
const handleClick = ( event : React . MouseEvent < HTMLButtonElement > ) => {
124
126
setAnchorEl ( event . currentTarget ) ;
125
127
} ;
126
128
127
-
129
+ const doFetch = ( page = 0 , count = 10 , visitor = "" , purpose = "" , site = "" ) => {
130
+ inOffice ? dispatch ( fetchInOfficeContractors ( page , count , visitor , purpose , site ) ) : dispatch ( fetchContractors ( page , count , visitor , purpose , site ) )
131
+ }
128
132
const handleFilterChange = ( f : any ) => {
129
133
debugger ;
130
134
const newFilter = { ...filter , ...f }
@@ -135,7 +139,7 @@ const ContractorView: FunctionComponent<Props> = (props) => {
135
139
contractor : contractor1
136
140
} = newFilter
137
141
138
- dispatch ( fetchContractors ( 0 , rowPerPage , contractor1 , purpose1 , site1 ) )
142
+ // dispatch(fetchContractors(0, rowPerPage, contractor1, purpose1, site1))
139
143
}
140
144
const handleClose = ( ) => {
141
145
setAnchorEl ( null ) ;
@@ -173,8 +177,6 @@ const ContractorView: FunctionComponent<Props> = (props) => {
173
177
isSort : true
174
178
} ]
175
179
176
- let tableRows : any = [ ]
177
-
178
180
const dispatch = useDispatch ( )
179
181
180
182
const {
@@ -197,12 +199,23 @@ const ContractorView: FunctionComponent<Props> = (props) => {
197
199
//dispatch(fetchHomeStats())
198
200
} , [ dispatch ] )
199
201
202
+ useEffect ( ( ) => {
203
+
204
+ const {
205
+ purpose : purpose1 ,
206
+ site : site1 ,
207
+ contractor : contractor1
208
+ } = filter
209
+ doFetch ( 0 , rowPerPage , contractor1 , purpose1 , site1 )
210
+ } , [ inOffice , filter ] )
211
+
200
212
const handleCheckOut = async ( id : any ) => {
201
213
dispatch ( getBackdropStart ( ) )
202
214
await checkout ( id )
203
215
. then ( ( ) => {
204
216
//dispatch(fetchHomeStats())
205
- dispatch ( fetchContractors ( 0 , 10 ) )
217
+ //dispatch(fetchContractors(0, 10))
218
+ doFetch ( 0 , 10 )
206
219
dispatch ( getBackdropStop ( ) )
207
220
} )
208
221
. catch ( ( ) => dispatch ( getBackdropStop ( ) ) )
@@ -234,7 +247,7 @@ const ContractorView: FunctionComponent<Props> = (props) => {
234
247
contractor : contractor1
235
248
} = filter
236
249
setRowPerPage ( count )
237
- dispatch ( fetchContractors ( page , count , contractor1 , purpose1 , site1 ) )
250
+ doFetch ( page , count , contractor1 , purpose1 , site1 )
238
251
} ,
239
252
totalCount : pageCount ,
240
253
menuOptions : [ {
@@ -262,14 +275,18 @@ const ContractorView: FunctionComponent<Props> = (props) => {
262
275
< Box display = "flex" justifyContent = "start" >
263
276
< SearchInput style = { { marginTop : '33px' , marginLeft : '27px' } } onChange = { ( e : any ) => { debugger ; handleFilterChange ( { contractor : e . target . value } ) } } value = { filter . contractor } placeholder = "Search contractor" />
264
277
{ /* <SelectInput style={{marginTop: '33px', marginLeft: '27px'}} value="In Office" /> */ }
265
- < Button onClick = { ( ) => { setFilter ( { site : "" , purpose : "" , contractor : "" } ) ; dispatch ( fetchInOfficeContractors ( ) ) } }
278
+ < CustomizedSwitch
279
+ //@ts -ignore
280
+ style = { { marginTop : '33px' , marginLeft : '27px' , height : '36px' } }
281
+ label = { "In Office" } checked = { inOffice } onChange = { ( ) => { setInOffice ( ! inOffice ) } } />
282
+ { /* <Button onClick={() => { setFilter({ site: "", purpose: "", contractor: "" }); dispatch(fetchInOfficeContractors()) }}
266
283
classes={{
267
284
root: classes.buttonRoot, // class name, e.g. `classes-nesting-root-x`
268
285
label: classes.label, // class name, e.g. `classes-nesting-label-x`
269
- } } variant = "contained" style = { { marginTop : '33px' , marginLeft : '27px' , height : '40px' } } > In Office</ Button >
286
+ }} variant="contained" style={{ marginTop: '33px', marginLeft: '27px', height: '40px' }}>In Office</Button> */ }
270
287
< SelectInput style = { { marginTop : '33px' , marginLeft : '27px' } } onChange = { ( e : any ) => { debugger ; handleFilterChange ( { purpose : e . target . value } ) } } menuOptions = { purpose . map ( item => ( { title : item } ) ) } defaultValue = "All Purpose" value = { filter . purpose } />
271
288
< SelectInput style = { { marginTop : '33px' , marginLeft : '27px' } } onChange = { ( e : any ) => { debugger ; handleFilterChange ( { site : e . target . value } ) } } menuOptions = { sites . map ( item => ( { title : item . sitename } ) ) } defaultValue = "All Sites" value = { filter . site } />
272
- < Button onClick = { ( ) => { handleFilterChange ( { site : "" , purpose : "" , contractor : "" } ) } }
289
+ < Button onClick = { ( ) => { setInOffice ( false ) ; handleFilterChange ( { site : "" , purpose : "" , contractor : "" } ) } }
273
290
classes = { {
274
291
root : classes . buttonRoot , // class name, e.g. `classes-nesting-root-x`
275
292
label : classes . label , // class name, e.g. `classes-nesting-label-x`
0 commit comments