Skip to content

Commit

Permalink
moved from endpint that pulls all data to one that pulls the data you…
Browse files Browse the repository at this point in the history
… need
  • Loading branch information
DeltaV93 committed Jan 24, 2024
1 parent b22b9a3 commit 9d48b7f
Show file tree
Hide file tree
Showing 28 changed files with 750 additions and 419 deletions.
5 changes: 1 addition & 4 deletions src/api-calls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ export const getMemberData = async memberId => {
const response = await fetch(routes.api.users.getMemberData(memberId));
return response.json();
};
export const getBasicSystemInfo = async memberId => {
const response = await fetch(routes.api.users.basicSystemInfoUpdate());
return response.json();
};

export const getDropDrownItems = async details => {
const response = await fetch(routes.api.users.basicSystemInfoUpdate(details));
return response.json();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useRef } from 'react';
import { FormControl, FormLabel, TextField, Autocomplete } from '@mui/material';
import { getBasicSystemInfo } from '../api-calls';
import { getDropDrownItems } from '../api-calls';
import { createFilterOptions } from '@mui/material/Autocomplete';

const filter = createFilterOptions();
Expand All @@ -20,7 +20,7 @@ export default function CompanyDropdownUpdate({
// Fetch the list of companies when the component mounts
async function fetchCompanies() {
try {
const response = await getBasicSystemInfo();
const response = await getDropDrownItems('companies');
setCompanies(response.company_list);
} catch (error) {
console.error('Error fetching companies:', error);
Expand Down
68 changes: 68 additions & 0 deletions src/compoents/DropdownCompanySimple.jsx
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>
);
}
59 changes: 59 additions & 0 deletions src/compoents/DropdownCompanyTypes.jsx
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} />}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useState, useEffect, useRef } from 'react';
import { FormControl, FormLabel, TextField, Autocomplete } from '@mui/material';
import { getBasicSystemInfo } from '../api-calls';
import { getDropDrownItems } from '../api-calls';
import { createFilterOptions } from '@mui/material/Autocomplete';

const filter = createFilterOptions();

export default function CompanyDropdownUpdate({
error, answers, setAnswers, onCompanySelect
export default function DropdownCompanyUpdate({
error, answers, setAnswers, isRequired, onCompanySelect
}) {
const [ companies, setCompanies ] = useState([]);
const [ selectedCompany, setSelectedCompany ] = useState(answers.select_company || null);
Expand All @@ -19,7 +19,7 @@ export default function CompanyDropdownUpdate({
// Fetch the list of companies when the component mounts
async function fetchCompanies() {
try {
const response = await getBasicSystemInfo();
const response = await getDropDrownItems('companies');
setCompanies(response.company_list);
} catch (error) {
console.error('Error fetching companies:', error);
Expand All @@ -33,7 +33,6 @@ export default function CompanyDropdownUpdate({
<FormControl fullWidth variant="outlined">
<FormLabel id="company-label">* Company</FormLabel>
<Autocomplete
required
selectOnFocus
includeInputInList
handleHomeEndKeys
Expand Down Expand Up @@ -61,7 +60,9 @@ export default function CompanyDropdownUpdate({
company_id: newValue?.id,
}));
}}
renderInput={params => <TextField {...params} name="company_name" error={!!error.company_name} inputProps={{ ...params.inputProps }} />}
renderInput={params => (
<TextField {...params} required={isRequired} name="company_name" error={!!error.company_name} inputProps={{ ...params.inputProps }} />
)}
/>
</FormControl>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import React, { useState, useEffect } from 'react';
import { Autocomplete, FormControl, FormLabel, TextField } from '@mui/material';
import { getBasicSystemInfo } from '../api-calls';
import { getDropDrownItems } from '../api-calls';
import { createFilterOptions } from '@mui/material/Autocomplete';

const filter = createFilterOptions();
export default function DepartmentsDropdown({ isRequired, error, setAnswers }) {
export default function DropdownDepartments({
isRequired, error, setAnswers = false, 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 getBasicSystemInfo();
setDepartments(response.job_department);
const response = await getDropDrownItems('job_departments');
setDepartments(response.job_departments);
} catch (error) {
console.error('Error fetching departments:', error);
}
Expand Down Expand Up @@ -67,10 +69,14 @@ export default function DepartmentsDropdown({ isRequired, error, setAnswers }) {
// value={selectedSkill}
onChange={(e, newValue) => {
setSelectedDepartment(newValue);
setAnswers(prevState => ({
...prevState,
department: newValue,
}));
if (handleAutocompleteChange) {
handleAutocompleteChange('job_department', newValue);
} else {
setAnswers(prevState => ({
...prevState,
department: newValue,
}));
}
}}
renderOption={(props, option) => <li {...props}>{option.name}</li>}
renderInput={params => <TextField error={!!error.department} name="job_departments" {...params} />}
Expand Down
77 changes: 77 additions & 0 deletions src/compoents/DropdownDepartmentsSimple.jsx
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} />}
/>
);
}
61 changes: 61 additions & 0 deletions src/compoents/DropdownEthic.jsx
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} />}
/>
);
}
Loading

0 comments on commit 9d48b7f

Please sign in to comment.