import React, { useMemo, useCallback } from 'react'; import get from 'lodash/get'; import { IconCaretDown } from '@tabler/icons'; import MenuDropdown from 'ui/MenuDropdown'; import { useDispatch } from 'react-redux'; import { updateCollectionAuthMode } from 'providers/ReduxStore/slices/collections'; import { humanizeRequestAuthMode } from 'utils/collections'; import StyledWrapper from './StyledWrapper'; const AuthMode = ({ collection }) => { const dispatch = useDispatch(); const authMode = collection.draft?.root ? get(collection, 'draft.root.request.auth.mode') : get(collection, 'root.request.auth.mode'); const onModeChange = useCallback((value) => { dispatch( updateCollectionAuthMode({ collectionUid: collection.uid, mode: value }) ); }, [dispatch, collection.uid]); const menuItems = useMemo(() => [ { id: 'awsv4', label: 'AWS Sig v4', onClick: () => onModeChange('awsv4') }, { id: 'basic', label: 'Basic Auth', onClick: () => onModeChange('basic') }, { id: 'wsse', label: 'WSSE Auth', onClick: () => onModeChange('wsse') }, { id: 'bearer', label: 'Bearer Token', onClick: () => onModeChange('bearer') }, { id: 'digest', label: 'Digest Auth', onClick: () => onModeChange('digest') }, { id: 'ntlm', label: 'NTLM Auth', onClick: () => onModeChange('ntlm') }, { id: 'oauth1', label: 'OAuth 1.0', onClick: () => onModeChange('oauth1') }, { id: 'oauth2', label: 'OAuth 2.0', onClick: () => onModeChange('oauth2') }, { id: 'apikey', label: 'API Key', onClick: () => onModeChange('apikey') }, { id: 'none', label: 'No Auth', onClick: () => onModeChange('none') } ], [onModeChange]); return (
{humanizeRequestAuthMode(authMode)}
); }; export default AuthMode;