diff options
Diffstat (limited to 'src/hooks/useOptions.ts')
-rw-r--r-- | src/hooks/useOptions.ts | 30 |
1 files changed, 0 insertions, 30 deletions
diff --git a/src/hooks/useOptions.ts b/src/hooks/useOptions.ts deleted file mode 100644 index 2a5aee6..0000000 --- a/src/hooks/useOptions.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { useEffect } from 'react'; -import _ from 'lodash'; -import { Option } from '../components/Select'; -import hooks from './useAPIClient'; - -// Load service entities and map them into select options -// setting the default value in formik -const useOptions = ( - service: string, - fields: string[], - values: Record<string, any>, - setFieldValue: (any) => void, - mapper = item => ({ key: item._id, label: item.name }), -): Option[] => { - const { data: items } = hooks[service].useList(); - - const options = items?.map(mapper); - - useEffect(() => { - // Initialize all empty fields - if (items?.length) fields.forEach(field => { - if (!_.get(values, field)) setFieldValue(field, items[0]._id); - }); - }, [items, values, setFieldValue]); - - return options; -}; - - -export default useOptions; |