Skip to content

Commit 02f0be7

Browse files
committed
checkin populate device form
1 parent 1721e02 commit 02f0be7

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/components/CustomAutoComplete.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import classes from '*.module.css';
22
import { createStyles, makeStyles, Theme } from '@material-ui/core';
3-
import { Autocomplete } from '@material-ui/lab';
3+
import { Autocomplete, createFilterOptions } from '@material-ui/lab';
44
import { RootState } from 'app/rootReducer';
55
import * as React from 'react'
66
import { useDispatch, useSelector } from 'react-redux';
@@ -23,6 +23,8 @@ const useStyles = makeStyles((theme: Theme) => createStyles({
2323
}
2424
}))
2525

26+
const filter = createFilterOptions<any>();
27+
2628
export const CustomAutoComplete: React.FC<any> = (props) => {
2729

2830
const classes = useStyles()
@@ -43,6 +45,32 @@ export const CustomAutoComplete: React.FC<any> = (props) => {
4345
onInputChange={(event, newInputValue) => {
4446
onChange(newInputValue);
4547
}}
48+
clearOnBlur
49+
selectOnFocus
50+
handleHomeEndKeys
51+
filterOptions={(options: any, params: any) => {
52+
const filtered = filter(options, params);
53+
// Suggest the creation of a new value
54+
if (params.inputValue !== '') {
55+
filtered.push({
56+
inputValue: params.inputValue,
57+
title: `Add "${params.inputValue}"`,
58+
});
59+
}
60+
return filtered;
61+
}}
62+
getOptionLabel={(option: any) => {
63+
// Value selected with enter, right from the input
64+
if (typeof option === 'string') {
65+
return option;
66+
}
67+
// Add "xxx" option created dynamically
68+
if (option.inputValue) {
69+
return option.inputValue;
70+
}
71+
// Regular option
72+
return option.title;
73+
}}
4674
options={options}
4775
id="custom-input-demo"
4876
forcePopupIcon={false}

src/features/Settings/DeviceForm.tsx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import CustomButton from "components/Button";
1313
import TextInput from "components/TextInput";
1414
import { saveDevice, setCurrentDevice } from './deviceSlice';
1515
import { RootState } from 'app/rootReducer';
16+
import { CustomAutoComplete } from 'components/CustomAutoComplete';
17+
import { fetchCheckInPoints } from 'features/SalesAndOrganisation/checkInPointSlice';
1618

1719
const useStyles = makeStyles((theme: Theme) => createStyles({
1820
paper: {
@@ -80,6 +82,9 @@ const DeviceForm: FunctionComponent<Props> = (props) => {
8082
devicesById,
8183
error
8284
} = useSelector((state: RootState) => state.devices)
85+
const {
86+
checkInPoints
87+
} = useSelector((state: RootState) => state.checkinpoints)
8388

8489
const {
8590
devicename,
@@ -104,6 +109,11 @@ const DeviceForm: FunctionComponent<Props> = (props) => {
104109
}
105110
}, [id])
106111

112+
useEffect(() => {
113+
dispatch(fetchCheckInPoints())
114+
}, [dispatch])
115+
116+
107117
const handleChange = (e: any) => setInputState({
108118
...inputState,
109119
[e.target.name]: e.target.value
@@ -121,6 +131,13 @@ const DeviceForm: FunctionComponent<Props> = (props) => {
121131
}), () => setInputState(defaultInputState)))
122132
}
123133

134+
const handleCheckInPointChange = (checkinPointname: string) => {
135+
setInputState({
136+
...inputState,
137+
checkinpoint: checkinPointname
138+
});
139+
}
140+
124141

125142
return (
126143
<Grid item style={{ height: '80%', width: '90%' }}>
@@ -172,11 +189,22 @@ const DeviceForm: FunctionComponent<Props> = (props) => {
172189
name="udid"
173190
value={udid} />
174191

175-
<TextInput
192+
{/* <TextInput
176193
required
177194
label="checkinpoint"
178195
onChange={handleChange}
179196
name="checkinpoint"
197+
value={checkinpoint} /> */}
198+
<CustomAutoComplete
199+
style={{
200+
// width: 452,
201+
// marginLeft: i % 2 === 0 ? '64px' : '28px'
202+
}}
203+
required
204+
options={checkInPoints.map(o => o.checkinpoint)}
205+
label="checkinpoint"
206+
name="checkinpoint"
207+
onChange={(value: any) => handleCheckInPointChange(value)}
180208
value={checkinpoint} />
181209
</Grid>
182210
</Grid>

0 commit comments

Comments
 (0)