import React, { useState, useEffect } from 'react'; import { get, cloneDeep, isArray } from 'lodash'; import { IconTrash } from '@tabler/icons'; import { useDispatch } from 'react-redux'; import { useTheme } from 'providers/Theme'; import { addFile as _addFile, updateFile, deleteFile } from 'providers/ReduxStore/slices/collections/index'; import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions'; import StyledWrapper from './StyledWrapper'; import FilePickerEditor from 'components/FilePickerEditor/index'; import SingleLineEditor from 'components/SingleLineEditor/index'; const FileBody = ({ item, collection }) => { const dispatch = useDispatch(); const { storedTheme } = useTheme(); const params = item.draft ? get(item, 'draft.request.body.file') : get(item, 'request.body.file'); const [enabledFileUid, setEnableFileUid] = useState(params && params.length ? params[0].uid : ''); const addFile = () => { dispatch( _addFile({ itemUid: item.uid, collectionUid: collection.uid }) ); }; const onSave = () => dispatch(saveRequest(item.uid, collection.uid)); const handleRun = () => dispatch(sendRequest(item, collection.uid)); const handleParamChange = (e, _param, type) => { const param = cloneDeep(_param); switch (type) { case 'filePath': { param.filePath = e.target.filePath; param.contentType = ''; break; } case 'contentType': { param.contentType = e.target.contentType; break; } case 'selected': { param.selected = e.target.selected; setEnableFileUid(param.uid); break; } } dispatch( updateFile({ param: param, itemUid: item.uid, collectionUid: collection.uid }) ); }; const handleRemoveParams = (param) => { dispatch( deleteFile({ paramUid: param.uid, itemUid: item.uid, collectionUid: collection.uid }) ); }; return ( {params && params.length ? params.map((param, index) => { return ( ); }) : null}
File
Content-Type
Selected
handleParamChange( { target: { filePath: path } }, param, 'filePath' )} collection={collection} displayMode="labelAndIcon" /> handleParamChange( { target: { contentType: newValue } }, param, 'contentType' )} onRun={handleRun} collection={collection} />
handleParamChange(e, param, 'selected')} />
); }; export default FileBody;