import React, { useRef, forwardRef } from 'react'; import get from 'lodash/get'; import { IconCaretDown } from '@tabler/icons'; import Dropdown from 'components/Dropdown'; import { useDispatch } from 'react-redux'; import { updateFolderAuthMode } from 'providers/ReduxStore/slices/collections'; import { humanizeRequestAuthMode } from 'utils/collections'; import StyledWrapper from './StyledWrapper'; const AuthMode = ({ collection, folder }) => { const dispatch = useDispatch(); const dropdownTippyRef = useRef(); const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref); const authMode = get(folder, 'root.request.auth.mode'); const Icon = forwardRef((props, ref) => { return (
{humanizeRequestAuthMode(authMode)}
); }); const onModeChange = (value) => { dispatch( updateFolderAuthMode({ mode: value, collectionUid: collection.uid, folderUid: folder.uid }) ); }; return (
} placement="bottom-end">
{ dropdownTippyRef.current.hide(); onModeChange('awsv4'); }} > AWS Sig v4
{ dropdownTippyRef.current.hide(); onModeChange('basic'); }} > Basic Auth
{ dropdownTippyRef.current.hide(); onModeChange('bearer'); }} > Bearer Token
{ dropdownTippyRef.current.hide(); onModeChange('digest'); }} > Digest Auth
{ dropdownTippyRef.current.hide(); onModeChange('ntlm'); }} > NTLM Auth
{ dropdownTippyRef.current.hide(); onModeChange('oauth2'); }} > OAuth 2.0
{ dropdownTippyRef.current.hide(); onModeChange('wsse'); }} > WSSE Auth
{ dropdownTippyRef.current.hide(); onModeChange('apikey'); }} > API Key
{ dropdownTippyRef.current.hide(); onModeChange('inherit'); }} > Inherit
{ dropdownTippyRef.current.hide(); onModeChange('none'); }} > No Auth
); }; export default AuthMode;