Commit c1936b56 authored by Marek Veselý's avatar Marek Veselý
Browse files

fix: authentication error with export import

parent e2616973
Loading
Loading
Loading
Loading
+18 −8
Original line number Diff line number Diff line
import { AnchorButton, Button, ButtonGroup, Section } from '@blueprintjs/core'
import { Button, ButtonGroup, Section } from '@blueprintjs/core'
import { useHost } from '@inject/graphql/connection/host'
import { exportImportUrl } from '@inject/shared/config'
import { notify } from '@inject/shared/notification/engine'
import authenticatedFetch from '@inject/shared/utils/authenticatedFetch'
import { useState } from 'react'
import ImportDialog from './ImportDialog'

@@ -8,6 +10,19 @@ const ExportImport = () => {
  const host = useHost()
  const [isImportOpen, setIsImportOpen] = useState(false)

  const handleExport = () => {
    authenticatedFetch(exportImportUrl(host || ''))
      .then(response => response.blob())
      .then(blob => {
        const url = window.URL.createObjectURL(blob)
        const a = document.createElement('a')
        a.href = url
        a.download = `IXP-export-${new Date().toISOString().substring(0, 18)}.zip`
        a.click()
      })
      .catch(error => notify(error.message, { intent: 'danger' }))
  }

  return (
    <>
      <Section
@@ -19,14 +34,9 @@ const ExportImport = () => {
        }
        rightElement={
          <ButtonGroup>
            <AnchorButton
              icon='export'
              href={exportImportUrl(host || '')}
              target='_blank'
              rel='noreferrer'
            >
            <Button icon='export' onClick={handleExport}>
              Export
            </AnchorButton>
            </Button>
            <Button
              active={isImportOpen}
              onClick={() => setIsImportOpen(true)}
+6 −1
Original line number Diff line number Diff line
@@ -10,14 +10,19 @@ const limitedHeight = css`
  overflow-y: auto;
`

const noMargin = css`
  margin: 0;
`

const ExercisePanel = () => {
  const { isSuperuser } = useAuthIdentity()

  return (
    <>
      {isSuperuser && <ExportImport />}
      <h1 className={noMargin}>Exercise panel</h1>
      <DefinitionManager className={limitedHeight} />
      <ExerciseManager className={limitedHeight} />
      {isSuperuser && <ExportImport />}
      <GitVersion />
    </>
  )