bruno/renderer/components/RequestPane/SaveRequest/index.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

import React, { useState, useEffect } from 'react';
import { faFolder } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import StyledWrapper from './StyledWrapper';
import Modal from 'components//Modal';
2022-03-22 13:48:20 +01:00
const SaveRequest = ({items, onClose}) => {
const [showFolders, setShowFolders] = useState([]);
useEffect(() => {
2022-03-22 13:48:20 +01:00
setShowFolders(items || []);
}, [items])
const handleFolderClick = (folder) => {
let subFolders = [];
2022-03-22 13:48:20 +01:00
if(folder.items && folder.items.length) {
for (let item of folder.items) {
if (item.items) {
subFolders.push(item)
}
}
if(subFolders.length) {
setShowFolders(subFolders);
}
}
}
return (
2022-03-22 13:48:20 +01:00
<StyledWrapper>
<Modal
size ="md"
title ="Save Request"
confirmText ="Save"
cancelText ="Cancel"
handleCancel = {onClose}
handleConfirm = {onClose}
>
2022-03-22 13:48:20 +01:00
<p className="mb-2">Select a folder to save request:</p>
<div className="folder-list">
{showFolders && showFolders.length ? showFolders.map((folder) => (
<div
key={folder.uid}
className="folder-name"
onClick={() => handleFolderClick(folder)}
>
<FontAwesomeIcon className="mr-3 text-gray-500" icon={faFolder} style={{fontSize: 20}}/>
{folder.name}
</div>
)): null}
</div>
</Modal>
</StyledWrapper>
2022-03-22 13:48:20 +01:00
);
};
2022-03-22 13:48:20 +01:00
export default SaveRequest;