2023-06-06 15:19:11 -05:00
|
|
|
import { useState, useContext } from 'react'
|
2022-08-16 00:33:35 -05:00
|
|
|
import { useTranslation } from 'next-i18next'
|
2023-01-29 18:57:24 +01:00
|
|
|
import { Popout } from 'shared/components/popout.mjs'
|
|
|
|
import { WebLink } from 'shared/components/web-link.mjs'
|
2023-06-06 15:19:11 -05:00
|
|
|
import { LoadingContext } from 'shared/context/loading-context.mjs'
|
|
|
|
import { useToast } from 'shared/hooks/use-toast.mjs'
|
|
|
|
import {
|
|
|
|
exportTypes,
|
|
|
|
handleExport,
|
|
|
|
ns as exportNs,
|
|
|
|
} from 'shared/components/workbench/exporting/export-handler.mjs'
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2023-06-06 15:19:11 -05:00
|
|
|
export const ns = ['exporting', exportNs]
|
|
|
|
|
|
|
|
export const ExportView = ({ settings, ui, design, Design }) => {
|
2022-08-16 00:33:35 -05:00
|
|
|
const [link, setLink] = useState(false)
|
|
|
|
const [format, setFormat] = useState(false)
|
2023-06-06 15:25:23 -05:00
|
|
|
const { startLoading, stopLoading } = useContext(LoadingContext)
|
2023-06-06 15:19:11 -05:00
|
|
|
const toast = useToast()
|
2022-08-16 00:33:35 -05:00
|
|
|
|
2023-06-06 15:19:11 -05:00
|
|
|
const { t } = useTranslation(ns)
|
2022-08-21 10:26:35 +01:00
|
|
|
const doExport = (format) => {
|
|
|
|
setLink(false)
|
|
|
|
setFormat(format)
|
2023-06-06 15:19:11 -05:00
|
|
|
handleExport({
|
|
|
|
format,
|
|
|
|
settings,
|
|
|
|
design,
|
|
|
|
t,
|
|
|
|
Design,
|
|
|
|
ui,
|
|
|
|
startLoading,
|
|
|
|
stopLoading,
|
|
|
|
onComplete: (e) => {
|
|
|
|
if (e.data.link) {
|
|
|
|
setLink(e.data.link)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
onError: (e) => {
|
|
|
|
if (e.data?.error) toast.error(e.data.error.message)
|
|
|
|
},
|
|
|
|
})
|
2022-08-21 10:26:35 +01:00
|
|
|
}
|
2022-08-16 00:33:35 -05:00
|
|
|
|
|
|
|
return (
|
2023-06-06 15:19:11 -05:00
|
|
|
<div className="max-w-screen-xl m-auto py-8">
|
2022-08-16 00:33:35 -05:00
|
|
|
<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>
|
|
|
|
)}
|
|
|
|
<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>
|
|
|
|
)
|
|
|
|
}
|