Skip to content

Commit 57a051c

Browse files
committed
site auto populate in add checkIn
1 parent 0398622 commit 57a051c

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/features/SalesAndOrganisation/CheckInPointForm.tsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import { ArrowBackIos } from "@material-ui/icons";
55
// import { saveCheckInPoint, setCurrentCheckInPoint } from './checkInPointSlice';
66
import { RootState } from 'app/rootReducer';
77
import CustomButton from "components/Button";
8+
import { CustomAutoComplete } from "components/CustomAutoComplete";
89
import TextInput from "components/TextInput";
910
import React, { FunctionComponent, useEffect } from 'react';
1011
import { useDispatch, useSelector } from "react-redux";
1112
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";
1315

1416
const useStyles = makeStyles((theme: Theme) => createStyles({
1517
paper: {
@@ -66,26 +68,19 @@ const CheckInPointForm: FunctionComponent<Props> = (props) => {
6668
error
6769
} = useSelector((state: RootState) => state.checkinpoints)
6870

71+
const {sites} = useSelector((state: RootState) => state.sites)
72+
6973
const {
7074
sitename,
7175
device,
7276
checkinpoint,
7377
} = currentCheckInPoint
7478
const inputState = currentCheckInPoint;
7579

76-
const setInputState = (checkInPoint: any) => {
80+
const setInputState = (checkInPoint: CheckInPointInputState) => {
7781
dispatch(setCurrentCheckInPoint(checkInPoint));
7882
}
7983

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])
8984

9085
const handleChange = (e: any) => setInputState({
9186
...inputState,
@@ -101,9 +96,19 @@ const CheckInPointForm: FunctionComponent<Props> = (props) => {
10196
}), () => setInputState(defaultInputState)))
10297
}
10398

99+
const handleSiteChange = (sitename: string) => {
100+
setInputState({
101+
...inputState,
102+
sitename: sitename
103+
});
104+
}
105+
106+
useEffect(() => {
107+
dispatch(fetchSites())
108+
}, [dispatch])
104109

105110
return (
106-
<Grid item style={{ height: '80%', width: '90%' }}>
111+
<Grid item xs={12} style={{ marginRight: 30 }}>
107112
<Paper className={classes.paper}>
108113
<form onSubmit={handleSubmit}>
109114
<div className={classes.header}>
@@ -118,10 +123,21 @@ const CheckInPointForm: FunctionComponent<Props> = (props) => {
118123
<Grid className={classes.inputGrid} container>
119124
<Grid item xs={6}>
120125
{/*<div>*/}
121-
<TextInput label="CheckInPoint Name"
126+
{/* <TextInput label="Site Name"
122127
required
123128
name="sitename"
124129
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)}
125141
value={sitename} />
126142
<TextInput
127143
required

src/features/SalesAndOrganisation/checkInPointSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const checkInPoint = createSlice({
7676
state.checkInPoints.map(checkInPoint => (state.checkInPointsById[checkInPoint.checkInPoint_id] = checkInPoint))
7777
},
7878
getCheckInPointsFailure: loadingFailed,
79-
setCurrentCheckInPoint(state, { payload }: PayloadAction<any>) {
79+
setCurrentCheckInPoint(state, { payload }: PayloadAction<CheckInPointInputState>) {
8080
state.currentCheckInPoint = payload
8181
}
8282
}

0 commit comments

Comments
 (0)