diff --git a/src/app/views/events/forms/EventForm.jsx b/src/app/views/events/forms/EventForm.jsx index 6124b5e5..d968d6c0 100644 --- a/src/app/views/events/forms/EventForm.jsx +++ b/src/app/views/events/forms/EventForm.jsx @@ -45,6 +45,12 @@ const EventForm = () => { const { id } = useParams(); const { user } = useAuth(); const history = useHistory(); + const [host, setHost] = useState({ + id: '', + email: '', + first_name: '', + last_name: '', + }); useEffect(() => { if (!id) setSlug(slugify(title).toLowerCase()); @@ -379,14 +385,43 @@ const EventForm = () => { Host - setHost(userData)} name="host" size="small" fullWidth variant="outlined" - value={values.host} - onChange={handleChange} + value={host} + debounced + filterOptions={(options) => options} + renderOption={(option) => (option.newUser + ? option.newUser + : `${option.first_name} ${option.last_name}, (${option.email})`)} + getOptionLabel={(option) => option.first_name} + asyncSearch={(searchTerm) => bc.auth().getAllUsers({ like: searchTerm || '' })} + getOptions={(options, params) => { + const filtered = filter(options, params); + if (params.inputValue !== '') { + filtered.push({ + newUser: ( +
{ + e.stopPropagation(); + setShowForm(true); + values.showForm = true; + if (params.inputValue.includes('@')) setFieldValue('email', params.inputValue); + else setFieldValue('first_name', params.inputValue); + }} + > + {`Invite ${params.inputValue} to 4Geeks.`} +
+ ), + }); + } + return filtered; + }} />