()
| 107 | } |
| 108 | |
| 109 | async function handleCreateCollectionClick() { |
| 110 | try { |
| 111 | let response; |
| 112 | if (state.uploadFile) { |
| 113 | const data = new FormData(); |
| 114 | data.append('File', state.uploadFile, 'file'); |
| 115 | |
| 116 | if (state.selectedImport === 'openapi') { |
| 117 | response = await api.importOpenApi(state.basePath, state.groups, data); |
| 118 | } else { |
| 119 | response = await api.importPostman(state.groups, data); |
| 120 | } |
| 121 | } else { |
| 122 | response = await api.createCollection(state.name, state.groups); |
| 123 | } |
| 124 | |
| 125 | if (response.status !== 200) throw new Error(); |
| 126 | const newCollection = (await response.json()) as Collection; |
| 127 | |
| 128 | dispatchCollections({ |
| 129 | type: CollectionsActionType.ADD_COLLECTION, |
| 130 | collection: newCollection, |
| 131 | }); |
| 132 | |
| 133 | saveSelectedEnv(newCollection.id, 'default'); |
| 134 | |
| 135 | successToast('A new collection was created and saved', toast); |
| 136 | onCloseClear(); |
| 137 | } catch (e) { |
| 138 | errorToast('The collection could be not created', toast); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return ( |
| 143 | <Box className={styles.box} bg="panelBg" h="100%" w="100%"> |
nothing calls this directly
no test coverage detected