Skip to content

Commit 652e3e1

Browse files
committed
sites and purpose autocomplete
1 parent cd60ae2 commit 652e3e1

File tree

5 files changed

+198
-119
lines changed

5 files changed

+198
-119
lines changed

src/components/CustomAutoComplete.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export const CustomAutoComplete: React.FC<any> = (props) => {
4141
}}
4242
inputValue={value}
4343
onInputChange={(event, newInputValue) => {
44-
onChange(event);
44+
onChange(newInputValue);
4545
}}
4646
options={options}
4747
id="custom-input-demo"

src/features/Home/VisitorDetailsView1.tsx

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { makeStyles } from "@material-ui/core/styles";
33
import { Theme } from "@material-ui/core/styles/createMuiTheme";
44
import { ArrowBackIos, CameraAlt } from "@material-ui/icons";
55
import { getBackdropStart, getBackdropStop } from 'app/BackdropSlice';
6-
import { setCurrentVisitor, defaultVisitor } from 'features/Home/visitorSlice';
6+
import { setCurrentVisitor, defaultVisitor, fetchVisitors } from 'features/Home/visitorSlice';
77
import React, { FunctionComponent, useEffect } from 'react';
88
import { useDispatch, useSelector } from "react-redux";
99
import { RouteComponentProps } from 'react-router-dom';
@@ -15,6 +15,7 @@ import TextInput from "../../components/TextInput";
1515
import { config as VisitorFormConfig } from 'features/Settings/VisitorFormConfig';
1616
import { fetchVisitorConfigs } from "features/Settings/visitorConfigSlice";
1717
import img from 'assets/logo/logo.png'
18+
import { fetchSites } from "features/SalesAndOrganisation/siteSlice";
1819

1920
const useStyles = makeStyles((theme: Theme) => createStyles({
2021
paper: {
@@ -130,9 +131,13 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
130131
visitors,
131132
visitorsById,
132133
currentVisitor,
134+
purpose: purposeOptions,
133135
isLoading: isLoadingVisitor,
134136
error
135137
} = useSelector((state: RootState) => state.visitors)
138+
const {
139+
sites
140+
} = useSelector((state: RootState) => state.sites)
136141
//const inputState = currentVisitor
137142
const {
138143
mask
@@ -174,6 +179,11 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
174179
id != -1 && dispatch(setCurrentVisitor(visitorsById[id] || defaultVisitor));
175180
}, [id])
176181

182+
useEffect(() => {
183+
dispatch(fetchVisitors())
184+
dispatch(fetchSites())
185+
}, [dispatch])
186+
177187
const handleSubmit = async (e: any) => {
178188
dispatch(getBackdropStart())
179189
let bodyFormData = new FormData();
@@ -216,6 +226,21 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
216226
.then(() => dispatch(getBackdropStop())).catch(() => dispatch(getBackdropStop()))
217227
}
218228

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+
219244
const visitorSectionFields = VisitorFormConfig.
220245
filter(i => i.section === "VI" && visitorConfigsById[i.id] && visitorConfigsById[i.id].value).
221246
sort((a, b) => (a.seq - b.seq)).
@@ -227,9 +252,23 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
227252
{/* <TextInput style={{ width: 446, marginLeft: '64px' }} label={o.name} name={o.id} onChange={handleChange}
228253
//@ts-ignore
229254
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+
}
233272
</Grid>
234273
))
235274
const appointmentSectionFields = VisitorFormConfig.
@@ -240,9 +279,23 @@ const VisitorDetailsView: FunctionComponent<Props> = (props) => {
240279
// style={{ marginTop: '52px' }}
241280
key={o.id}>
242281
{/* {(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+
}
246299
</Grid>
247300
))
248301

src/features/Invites/InviteForm.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const InviteForm: FunctionComponent<Props> = (props) => {
9898
name: '',
9999
mobileNo: '',
100100
personToMeet: '',
101-
purpose: '',
101+
purpose: 'default',
102102
email: '',
103103
})
104104

@@ -110,6 +110,10 @@ const InviteForm: FunctionComponent<Props> = (props) => {
110110
...inputState,
111111
'time': date
112112
})
113+
const handlePurpose = (value: any) => setInputState({
114+
...inputState,
115+
purpose: value
116+
})
113117

114118
const handleSubmit = async (e: any) => {
115119
e.preventDefault()
@@ -207,7 +211,7 @@ const InviteForm: FunctionComponent<Props> = (props) => {
207211
options={purpose}
208212
label="Purpose to visit"
209213
name="purpose"
210-
onChange={handleChange}
214+
onChange={handlePurpose}
211215
value={inputState.purpose} />
212216
</Grid>
213217
</Grid>

src/features/Settings/VisitorFormConfig.ts

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)