-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved from endpint that pulls all data to one that pulls the data you…
… need
- Loading branch information
Showing
28 changed files
with
750 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import { FormControl, FormLabel, TextField, Autocomplete } from '@mui/material'; | ||
import { getDropDrownItems } from '../api-calls'; | ||
import { createFilterOptions } from '@mui/material/Autocomplete'; | ||
|
||
const filter = createFilterOptions(); | ||
|
||
export default function DropdownCompanySimple({ | ||
error, answers, setAnswers, isRequired | ||
}) { | ||
const [ companies, setCompanies ] = useState([]); | ||
const [ selectedCompany, setSelectedCompany ] = useState(null); | ||
|
||
useEffect(() => { | ||
const firstCompany = Array.isArray(answers?.company) ? answers?.company[0] : null; | ||
setSelectedCompany(answers.select_company || firstCompany || null); | ||
}, [ answers?.select_company || answers?.company ]); | ||
|
||
useEffect(() => { | ||
// Fetch the list of companies when the component mounts | ||
async function fetchCompanies() { | ||
try { | ||
const response = await getDropDrownItems('companies'); | ||
setCompanies(response.companies); | ||
} catch (error) { | ||
console.error('Error fetching companies:', error); | ||
} | ||
} | ||
|
||
fetchCompanies(); | ||
}, []); | ||
|
||
return ( | ||
<FormControl fullWidth variant="outlined"> | ||
<FormLabel id="company-label">{isRequired && <>*</>} Company</FormLabel> | ||
<Autocomplete | ||
selectOnFocus | ||
includeInputInList | ||
handleHomeEndKeys | ||
value={selectedCompany} | ||
options={companies} | ||
getOptionLabel={option => { | ||
return typeof option === 'object' ? option.company_name : ''; | ||
}} | ||
isOptionEqualToValue={(option, value) => option?.id === value?.id} | ||
renderOption={(props, option) => ( | ||
<li {...props} key={option.id}> | ||
{option.company_name} | ||
<br /> | ||
{option.company_url} | ||
</li> | ||
)} | ||
filterOptions={(options, params) => { | ||
return filter(options, params); | ||
}} | ||
onChange={(event, newValue) => { | ||
setSelectedCompany(newValue); | ||
setAnswers('select_company', newValue); | ||
setAnswers('company', newValue); | ||
setAnswers('company_id', newValue?.id); | ||
}} | ||
renderInput={params => ( | ||
<TextField {...params} required={isRequired} name="company_name" error={!!error.company_name} inputProps={{ ...params.inputProps }} /> | ||
)} | ||
/> | ||
</FormControl> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Autocomplete, FormControl, FormLabel, TextField } from '@mui/material'; | ||
import { getDropDrownItems } from '../api-calls'; | ||
import { createFilterOptions } from '@mui/material/Autocomplete'; | ||
|
||
const filter = createFilterOptions(); | ||
export default function DropdownCompanyTypes({ isRequired, setAnswers, formErrors }) { | ||
const [ companyTypes, setCompanyTypes ] = useState([]); | ||
|
||
useEffect(() => { | ||
// Fetch the list of companies when the component mounts | ||
async function fetchData() { | ||
try { | ||
const response = await getDropDrownItems('company_types'); | ||
setCompanyTypes(response.company_types); | ||
} catch (error) { | ||
console.error('Error fetching company types:', error); | ||
} | ||
} | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<Autocomplete | ||
id="company_types" | ||
multiple | ||
selectOnFocus | ||
includeInputInList | ||
handleHomeEndKeys | ||
options={companyTypes || []} | ||
renderOption={(props, option) => ( | ||
<li {...props} key={option.id}> | ||
{option.name} | ||
</li> | ||
)} | ||
getOptionLabel={option => { | ||
return option.name; | ||
}} | ||
filterOptions={(options, params) => { | ||
const filtered = filter(options, params); | ||
|
||
const { inputValue } = params; | ||
// Suggest the creation of a new value | ||
const isExisting = options.some(option => inputValue === option.name); | ||
if (inputValue !== '' && !isExisting) { | ||
filtered.push({ | ||
inputValue, | ||
label: `Add "${inputValue}"`, | ||
}); | ||
} | ||
|
||
return filtered; | ||
}} | ||
onChange={(event, value) => setAnswers('company_types', value)} | ||
renderInput={params => <TextField required={isRequired} error={!!formErrors.company_types} name="company_types" {...params} />} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Autocomplete, FormControl, FormLabel, TextField } from '@mui/material'; | ||
import { getDropDrownItems } from '../api-calls'; | ||
import { createFilterOptions } from '@mui/material/Autocomplete'; | ||
|
||
const filter = createFilterOptions(); | ||
export default function DropdownDepartments({ | ||
isRequired, error, setAnswers, handleAutocompleteChange | ||
}) { | ||
const [ departments, setDepartments ] = useState([]); | ||
const [ selectedDepartment, setSelectedDepartment ] = useState(''); | ||
|
||
useEffect(() => { | ||
// Fetch the list of companies when the component mounts | ||
async function fetchDepartments() { | ||
try { | ||
const response = await getDropDrownItems('job_departments'); | ||
setDepartments(response.job_departments); | ||
} catch (error) { | ||
console.error('Error fetching departments:', error); | ||
} | ||
} | ||
|
||
fetchDepartments(); | ||
}, []); | ||
|
||
return ( | ||
<Autocomplete | ||
id="departments-label" | ||
multiple | ||
selectOnFocus | ||
includeInputInList | ||
handleHomeEndKeys | ||
options={departments || []} | ||
isOptionEqualToValue={(option, value) => (option.inputValue && value.inputValue && option.inputValue === value.inputValue) || option === value} | ||
getOptionLabel={option => { | ||
if (typeof option === 'string') { | ||
return option; | ||
} | ||
// Check for the special case where the option has an inputValue property | ||
if (option.inputValue) return option.inputValue; | ||
|
||
// Existing logic | ||
return option.name; | ||
}} | ||
filterOptions={(options, params) => { | ||
const filtered = filter(options, params); | ||
|
||
const { inputValue } = params; | ||
// Suggest the creation of a new value | ||
const isExisting = options.some(option => inputValue === option.name); | ||
if (inputValue !== '' && !isExisting) { | ||
filtered.push({ | ||
inputValue, | ||
name: `Add "${inputValue}"`, | ||
}); | ||
} | ||
|
||
return filtered; | ||
}} | ||
// value={selectedSkill} | ||
onChange={(e, newValue) => { | ||
setSelectedDepartment(newValue); | ||
if (handleAutocompleteChange) { | ||
handleAutocompleteChange('job_department', newValue); | ||
} else { | ||
setAnswers(prevState => ({ | ||
...prevState, | ||
department: newValue, | ||
})); | ||
} | ||
}} | ||
renderOption={(props, option) => <li {...props}>{option.name}</li>} | ||
renderInput={params => <TextField required={isRequired} error={!!error.department} name="job_departments" {...params} />} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { Autocomplete, TextField } from '@mui/material'; | ||
import { getDropDrownItems } from '../api-calls'; | ||
import { createFilterOptions } from '@mui/material/Autocomplete'; | ||
|
||
const filter = createFilterOptions(); | ||
export default function EthicDropdown({ | ||
isRequired, setAnswers, formErrors, handleChange | ||
}) { | ||
const [ ethic, setEthic ] = useState([]); | ||
|
||
useEffect(() => { | ||
// Fetch the list of companies when the component mounts | ||
async function fetchData() { | ||
try { | ||
const response = await getDropDrownItems('ethic'); | ||
setEthic(response.ethic); | ||
} catch (error) { | ||
console.error('Error fetching ethic:', error); | ||
} | ||
} | ||
|
||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<Autocomplete | ||
id="gender" | ||
multiple | ||
selectOnFocus | ||
includeInputInList | ||
handleHomeEndKeys | ||
options={ethic || []} | ||
renderOption={(props, option) => ( | ||
<li {...props} key={option.id}> | ||
{option.ethnicity} | ||
</li> | ||
)} | ||
getOptionLabel={option => { | ||
return option.ethnicity; | ||
}} | ||
filterOptions={(options, params) => { | ||
const filtered = filter(options, params); | ||
|
||
const { inputValue } = params; | ||
// Suggest the creation of a new value | ||
const isExisting = options.some(option => inputValue === option.ethnicity); | ||
if (inputValue !== '' && !isExisting) { | ||
filtered.push({ | ||
inputValue, | ||
label: `Add "${inputValue}"`, | ||
}); | ||
} | ||
|
||
return filtered; | ||
}} | ||
onChange={(event, value) => setAnswers('identity_ethic', value)} | ||
renderInput={params => <TextField required={isRequired} name="ethic" {...params} />} | ||
/> | ||
); | ||
} |
Oops, something went wrong.