2022-08-17 13:11:22 -05:00
|
|
|
import { useState } from 'react'
|
2022-08-16 00:33:35 -05:00
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
import Popout from 'shared/components/popout'
|
|
|
|
import WebLink from 'shared/components/web-link'
|
2022-08-24 12:07:08 -05:00
|
|
|
import {exportTypes, handleExport} from './export-handler'
|
2022-08-16 00:33:35 -05:00
|
|
|
|
|
|
|
const ExportDraft = ({ gist, design, app }) => {
|
|
|
|
|
|
|
|
const [link, setLink] = useState(false)
|
2022-08-24 11:03:11 -05:00
|
|
|
const [error, setError] = useState(false)
|
2022-08-16 00:33:35 -05:00
|
|
|
const [format, setFormat] = useState(false)
|
|
|
|
|
|
|
|
const { t } = useTranslation(['app'])
|
2022-08-21 10:26:35 +01:00
|
|
|
const doExport = (format) => {
|
|
|
|
setLink(false)
|
2022-08-24 12:07:08 -05:00
|
|
|
setError(false)
|
2022-08-21 10:26:35 +01:00
|
|
|
setFormat(format)
|
|
|
|
handleExport(format, gist, design, t, app, (e) => {
|
|
|
|
if (e.data.link) {setLink(e.data.link)}
|
2022-08-24 11:03:11 -05:00
|
|
|
}, (e) => {
|
|
|
|
if (e.data.error) {setError(true)}
|
2022-08-21 10:26:35 +01:00
|
|
|
})
|
|
|
|
}
|
2022-08-16 00:33:35 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="max-w-screen-xl m-auto">
|
|
|
|
<h2>{t('export')}</h2>
|
|
|
|
<p className="text-lg sm:text-xl">{t('exportPattern-txt')}</p>
|
|
|
|
{link && (
|
|
|
|
<Popout link compact>
|
|
|
|
<span className="font-bold mr-4 uppercase text-sm">
|
|
|
|
{format}:
|
|
|
|
</span>
|
|
|
|
<WebLink href={link} txt={link} />
|
|
|
|
</Popout>
|
|
|
|
)}
|
2022-08-24 11:03:11 -05:00
|
|
|
{error && (
|
|
|
|
<Popout warning compact>
|
|
|
|
<span className="font-bold mr-4 uppercase text-sm">
|
|
|
|
{t('error')}:
|
|
|
|
</span>
|
|
|
|
{t('somethingWentWrong')}
|
|
|
|
</Popout>
|
|
|
|
)}
|
2022-08-16 00:33:35 -05:00
|
|
|
<div className="flex flex-row flex-wrap gap-8">
|
2022-08-24 12:07:08 -05:00
|
|
|
{Object.keys(exportTypes).map(type => (
|
2022-08-16 00:33:35 -05:00
|
|
|
<div key={type} className="flex flex-col gap-2 w-full sm:w-auto">
|
|
|
|
<h4>{t(type)}</h4>
|
2022-08-24 12:07:08 -05:00
|
|
|
{exportTypes[type].map(format => (
|
2022-08-16 00:33:35 -05:00
|
|
|
<button key={format}
|
|
|
|
className="btn btn-primary"
|
2022-08-21 10:26:35 +01:00
|
|
|
onClick={() => doExport(format)}
|
2022-08-16 00:33:35 -05:00
|
|
|
>
|
|
|
|
{type === 'exportForPrinting' ? `${format} pdf` : format }
|
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExportDraft
|