-
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.
add station API calls to trade/single form (#141)
* implement GET calls for station names * new react select form component
- Loading branch information
Showing
5 changed files
with
146 additions
and
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { Controller } from 'react-hook-form'; | ||
import { Select as ChakraSelect } from 'chakra-react-select'; | ||
import SelectStyles from '@/app/_hooks/SelectStyles'; | ||
|
||
interface Props { | ||
fieldName: string; | ||
options: string[]; | ||
control: any; | ||
placeholder: string; | ||
} | ||
|
||
// consumes an array of strings {options} and outputs a styled selection component with search functionality | ||
const ChakraReactSelect = ({ | ||
fieldName, | ||
options, | ||
control, | ||
placeholder, | ||
}: Props) => { | ||
const [optionsState, setOptionsState] = useState< | ||
{ label: string; value: string }[] | ||
>([]); | ||
|
||
const formatOptions = () => | ||
options.map((val) => ({ | ||
label: val, | ||
value: val, | ||
})); | ||
|
||
useEffect(() => { | ||
setOptionsState(formatOptions()); | ||
}, [options]); | ||
|
||
return ( | ||
<Controller | ||
control={control} | ||
name={fieldName} | ||
render={({ field: { onChange, onBlur, value, name, ref } }) => ( | ||
<ChakraSelect | ||
isClearable | ||
name={name} | ||
ref={ref} | ||
onChange={onChange} | ||
onBlur={onBlur} | ||
options={optionsState} | ||
placeholder={placeholder} | ||
value={value} | ||
chakraStyles={SelectStyles()} | ||
/> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
export default ChakraReactSelect; |
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