()
| 260 | } |
| 261 | |
| 262 | const saveKey = async () => { |
| 263 | try { |
| 264 | const tempPermissions = Object.keys(selectedPermissions) |
| 265 | .map((category) => { |
| 266 | return Object.keys(selectedPermissions[category]).map((key) => { |
| 267 | if (selectedPermissions[category][key]) { |
| 268 | return key |
| 269 | } |
| 270 | }) |
| 271 | }) |
| 272 | .flat() |
| 273 | .filter(Boolean) |
| 274 | |
| 275 | const saveResp = await apikeyApi.updateAPI(dialogProps.key.id, { |
| 276 | keyName, |
| 277 | permissions: tempPermissions |
| 278 | }) |
| 279 | if (saveResp.data) { |
| 280 | enqueueSnackbar({ |
| 281 | message: 'API Key saved', |
| 282 | options: { |
| 283 | key: new Date().getTime() + Math.random(), |
| 284 | variant: 'success', |
| 285 | action: (key) => ( |
| 286 | <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> |
| 287 | <IconX /> |
| 288 | </Button> |
| 289 | ) |
| 290 | } |
| 291 | }) |
| 292 | onConfirm() |
| 293 | } |
| 294 | } catch (error) { |
| 295 | if (setError) setError(error) |
| 296 | enqueueSnackbar({ |
| 297 | message: `Failed to save API key: ${ |
| 298 | typeof error.response.data === 'object' ? error.response.data.message : error.response.data |
| 299 | }`, |
| 300 | options: { |
| 301 | key: new Date().getTime() + Math.random(), |
| 302 | variant: 'error', |
| 303 | persist: true, |
| 304 | action: (key) => ( |
| 305 | <Button style={{ color: 'white' }} onClick={() => closeSnackbar(key)}> |
| 306 | <IconX /> |
| 307 | </Button> |
| 308 | ) |
| 309 | } |
| 310 | }) |
| 311 | onCancel() |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | const checkDisabled = () => { |
| 316 | if (!keyName || keyName === '') { |
no test coverage detected