-
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.
Integrate backend services updates (#36)
Signed-off-by: Sean Sundberg <[email protected]>
- Loading branch information
Showing
41 changed files
with
1,895 additions
and
704 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,74 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React, {ChangeEvent, CSSProperties} from 'react'; | ||
import {Select, SelectItem} from "@carbon/react"; | ||
import {Loadable} from "jotai/vanilla/utils/loadable"; | ||
|
||
import {FormOptionModel} from "../../models"; | ||
|
||
export interface AtomSelectProps { | ||
id: string; | ||
loadable: Loadable<Promise<FormOptionModel[]>>; | ||
value: string; | ||
invalidText: string; | ||
labelText: string; | ||
required?: boolean; | ||
readOnly?: boolean; | ||
onChange?: (event: ChangeEvent<HTMLInputElement | HTMLSelectElement>) => void; | ||
className?: string; | ||
style?: CSSProperties; | ||
} | ||
|
||
export interface SpecificAtomSelectProps { | ||
id: string; | ||
required?: boolean; | ||
readOnly?: boolean; | ||
value: string; | ||
onChange?: (event: ChangeEvent<HTMLInputElement | HTMLSelectElement>) => void; | ||
className?: string; | ||
style?: CSSProperties; | ||
} | ||
|
||
const loadFormItems = (loadable: Loadable<Promise<FormOptionModel[]>>): FormOptionModel[] => { | ||
const items: FormOptionModel[] = loadable.state === 'hasData' | ||
? loadable.data | ||
: []; | ||
|
||
return items | ||
.filter(item => item.value !== null) | ||
.filter(item => item.text !== undefined) | ||
.filter(item => item.value !== 'null') | ||
.filter(item => item.text !== 'undefined') | ||
} | ||
|
||
export const AtomSelect: React.FunctionComponent<AtomSelectProps> = (props: AtomSelectProps) => { | ||
|
||
const items: FormOptionModel[] = loadFormItems(props.loadable); | ||
|
||
const buildSelectItem = (option: FormOptionModel) => { | ||
const key = `${props.id}-${option.value}`; | ||
|
||
if (option.value === null || option.value === 'null') { | ||
console.log('Option: ', Object.assign({}, option, {key})); | ||
} | ||
|
||
return (<SelectItem key={key} text={option.text} value={option.value} />) | ||
} | ||
|
||
return ( | ||
<Select | ||
id={props.id} | ||
invalidText={props.invalidText} | ||
labelText={props.labelText} | ||
disabled={props.loadable.state !== 'hasData'} | ||
value={props.value} | ||
onChange={props.onChange} | ||
required={props.required} | ||
readOnly={props.readOnly} | ||
className={props.className} | ||
style={props.style} | ||
> | ||
{items.map(buildSelectItem)} | ||
</Select> | ||
) | ||
} |
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 @@ | ||
export * from './AtomSelect'; |
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 |
---|---|---|
@@ -1,41 +1,29 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React, {ChangeEvent, CSSProperties} from 'react'; | ||
import {Select, SelectItem} from "@carbon/react"; | ||
import React from 'react'; | ||
import {useAtomValue} from "jotai"; | ||
import {Loadable} from "jotai/vanilla/utils/loadable"; | ||
|
||
import {AtomSelect, SpecificAtomSelectProps} from "../AtomSelect"; | ||
import {countriesAtomLoadable} from "../../atoms"; | ||
import {FormOptionModel} from "../../models"; | ||
|
||
export interface CountrySelectProps { | ||
id: string; | ||
required?: boolean; | ||
readOnly?: boolean; | ||
value: string; | ||
onChange?: (event: ChangeEvent<HTMLInputElement | HTMLSelectElement>) => void; | ||
className?: string; | ||
style?: CSSProperties; | ||
} | ||
|
||
export const CountrySelect: React.FunctionComponent<CountrySelectProps> = (props: CountrySelectProps) => { | ||
const countriesLoadable = useAtomValue(countriesAtomLoadable); | ||
|
||
const countries: FormOptionModel[] = countriesLoadable.state === 'hasData' ? countriesLoadable.data : []; | ||
export const CountrySelect: React.FunctionComponent<SpecificAtomSelectProps> = (props: SpecificAtomSelectProps) => { | ||
const countriesLoadable: Loadable<Promise<FormOptionModel[]>> = useAtomValue(countriesAtomLoadable); | ||
|
||
return ( | ||
<Select | ||
<AtomSelect | ||
id={props.id} | ||
invalidText="Invalid country selected" | ||
labelText="Country of residence" | ||
disabled={countriesLoadable.state !== 'hasData'} | ||
value={props.value} | ||
onChange={props.onChange} | ||
required={props.required} | ||
readOnly={props.readOnly} | ||
className={props.className} | ||
style={props.style} | ||
> | ||
{countries.map(option => <SelectItem key={option.value} text={option.text} value={option.value} />)} | ||
</Select> | ||
loadable={countriesLoadable} | ||
/> | ||
) | ||
} |
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,28 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React from 'react'; | ||
import {useAtomValue} from "jotai"; | ||
import {Loadable} from "jotai/vanilla/utils/loadable"; | ||
|
||
import {AtomSelect, SpecificAtomSelectProps} from "../AtomSelect"; | ||
import {entityTypesAtomLoadable} from "../../atoms"; | ||
import {FormOptionModel} from "../../models"; | ||
|
||
export const EntityTypeSelect: React.FunctionComponent<SpecificAtomSelectProps> = (props: SpecificAtomSelectProps) => { | ||
const loadable: Loadable<Promise<FormOptionModel[]>> = useAtomValue(entityTypesAtomLoadable); | ||
|
||
return ( | ||
<AtomSelect | ||
id={props.id} | ||
invalidText="Invalid entity type selected" | ||
labelText="Entity type" | ||
value={props.value} | ||
onChange={props.onChange} | ||
required={props.required} | ||
readOnly={props.readOnly} | ||
className={props.className} | ||
style={props.style} | ||
loadable={loadable} | ||
/> | ||
) | ||
} |
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 @@ | ||
export * from './EntityTypeSelect' |
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,28 @@ | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
import React from 'react'; | ||
import {useAtomValue} from "jotai"; | ||
import {Loadable} from "jotai/vanilla/utils/loadable"; | ||
|
||
import {AtomSelect, SpecificAtomSelectProps} from "../AtomSelect"; | ||
import {industryTypesAtomLoadable} from "../../atoms"; | ||
import {FormOptionModel} from "../../models"; | ||
|
||
export const IndustryTypeSelect: React.FunctionComponent<SpecificAtomSelectProps> = (props: SpecificAtomSelectProps) => { | ||
const loadable: Loadable<Promise<FormOptionModel[]>> = useAtomValue(industryTypesAtomLoadable); | ||
|
||
return ( | ||
<AtomSelect | ||
id={props.id} | ||
invalidText="Invalid industry type selected" | ||
labelText="Industry type" | ||
value={props.value} | ||
onChange={props.onChange} | ||
required={props.required} | ||
readOnly={props.readOnly} | ||
className={props.className} | ||
style={props.style} | ||
loadable={loadable} | ||
/> | ||
) | ||
} |
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 @@ | ||
export * from './IndustryTypeSelect'; |
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
Oops, something went wrong.