import React, { useState } from 'react'; import importBrunoCollection from 'utils/importers/bruno-collection'; import importPostmanCollection from 'utils/importers/postman-collection'; import importInsomniaCollection from 'utils/importers/insomnia-collection'; import importOpenapiCollection from 'utils/importers/openapi-collection'; import { toastError } from 'utils/common/error'; import Modal from 'components/Modal'; const ImportCollection = ({ onClose, handleSubmit }) => { const [options, setOptions] = useState({ enablePostmanTranslations: { enabled: true, label: 'Auto translate postman scripts', subLabel: "When enabled, Bruno will try as best to translate the scripts from the imported collection to Bruno's format." } }); const handleImportBrunoCollection = () => { importBrunoCollection() .then((collection) => { handleSubmit(collection); }) .catch((err) => toastError(err, 'Import collection failed')); }; const handleImportPostmanCollection = () => { importPostmanCollection(options) .then((collection) => { handleSubmit(collection); }) .catch((err) => toastError(err, 'Postman Import collection failed')); }; const handleImportInsomniaCollection = () => { importInsomniaCollection() .then((collection) => { handleSubmit(collection); }) .catch((err) => toastError(err, 'Insomnia Import collection failed')); }; const handleImportOpenapiCollection = () => { importOpenapiCollection() .then((collection) => { handleSubmit(collection); }) .catch((err) => toastError(err, 'OpenAPI v3 Import collection failed')); }; const toggleOptions = (event, optionKey) => { setOptions({ ...options, [optionKey]: { ...options[optionKey], enabled: !options[optionKey].enabled } }); }; const CollectionButton = ({ children, className, onClick }) => { return ( {children} ); }; return ( Select the type of your existing collection : Bruno Collection Postman Collection Insomnia Collection OpenAPI V3 Spec {Object.entries(options || {}).map(([key, option]) => ( toggleOptions(e, key)} className="h-3.5 w-3.5 rounded border-zinc-300 dark:ring-offset-zinc-800 bg-transparent text-indigo-600 dark:text-indigo-500 focus:ring-indigo-600 dark:focus:ring-indigo-500" /> {option.label} {option.subLabel} ))} ); }; export default ImportCollection;
{option.subLabel}