import React from 'react'; import get from 'lodash/get'; import cloneDeep from 'lodash/cloneDeep'; import { IconTrash } from '@tabler/icons'; import { useDispatch } from 'react-redux'; import { addRequestHeader, updateRequestHeader, deleteRequestHeader } from 'providers/ReduxStore/slices/collections'; import StyledWrapper from './StyledWrapper'; const RequestHeaders = ({item, collection}) => { const dispatch = useDispatch(); const headers = item.draft ? get(item, 'draft.request.headers') : get(item, 'request.headers'); const addHeader = () => { dispatch(addRequestHeader({ itemUid: item.uid, collectionUid: collection.uid, })); }; const handleHeaderValueChange = (e, _header, type) => { const header = cloneDeep(_header); switch(type) { case 'name' : { header.name = e.target.value; break; } case 'value' : { header.value = e.target.value; break; } case 'description' : { header.description = e.target.value; break; } case 'enabled' : { header.enabled = e.target.checked; break; } } dispatch(updateRequestHeader({ header: header, itemUid: item.uid, collectionUid: collection.uid })); }; const handleRemoveHeader = (header) => { dispatch(deleteRequestHeader({ headerUid: header.uid, itemUid: item.uid, collectionUid: collection.uid })); }; return ( {headers && headers.length ? headers.map((header, index) => { return ( ); }) : null}
Key Value Description
handleHeaderValueChange(e, header, 'name')} /> handleHeaderValueChange(e, header, 'value')} /> handleHeaderValueChange(e, header, 'description')} />
handleHeaderValueChange(e, header, 'enabled')} />
) }; export default RequestHeaders;