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-10-23 19:53:08 +02: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)
|
2022-10-23 19:53:08 +02:00
|
|
|
handleExport(
|
|
|
|
format,
|
|
|
|
gist,
|
|
|
|
design,
|
|
|
|
t,
|
|
|
|
app,
|
|
|
|
(e) => {
|
|
|
|
if (e.data.link) {
|
|
|
|
setLink(e.data.link)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
(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>
|
2022-10-23 19:53:08 +02:00
|
|
|
<span className="font-bold mr-4 uppercase text-sm">{format}:</span>
|
2022-08-16 00:33:35 -05:00
|
|
|
<WebLink href={link} txt={link} />
|
|
|
|
</Popout>
|
|
|
|
)}
|
2022-08-24 11:03:11 -05:00
|
|
|
{error && (
|
|
|
|
<Popout warning compact>
|
2022-10-23 19:53:08 +02:00
|
|
|
<span className="font-bold mr-4 uppercase text-sm">{t('error')}:</span>
|
2022-08-24 11:03:11 -05:00
|
|
|
{t('somethingWentWrong')}
|
|
|
|
</Popout>
|
|
|
|
)}
|
2022-08-16 00:33:35 -05:00
|
|
|
<div className="flex flex-row flex-wrap gap-8">
|
2022-10-23 19:53:08 +02: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-10-23 19:53:08 +02:00
|
|
|
{exportTypes[type].map((format) => (
|
|
|
|
<button key={format} className="btn btn-primary" onClick={() => doExport(format)}>
|
|
|
|
{type === 'exportForPrinting' ? `${format} pdf` : format}
|
2022-08-16 00:33:35 -05:00
|
|
|
</button>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ExportDraft
|