2023-09-04 08:40:05 +02:00
|
|
|
// Dependencies
|
|
|
|
import { nsMerge } from 'shared/utils.mjs'
|
2023-06-05 16:07:16 -05:00
|
|
|
import {
|
|
|
|
handleExport,
|
|
|
|
ns as exportNs,
|
|
|
|
} from 'shared/components/workbench/exporting/export-handler.mjs'
|
2023-09-04 08:40:05 +02:00
|
|
|
import { pagesPlugin } from 'shared/plugins/plugin-layout-part.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
import get from 'lodash.get'
|
2023-09-04 08:40:05 +02:00
|
|
|
import { defaultPrintSettings, printSettingsPath } from './config.mjs'
|
|
|
|
// Hooks
|
|
|
|
import { useContext } from 'react'
|
|
|
|
import { useTranslation } from 'next-i18next'
|
|
|
|
// Context
|
|
|
|
import { LoadingStatusContext } from 'shared/context/loading-status-context.mjs'
|
|
|
|
// Components
|
2023-06-04 23:28:43 -05:00
|
|
|
import { MovablePattern } from 'shared/components/workbench/pattern/movable/index.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
import { PrintMenu, ns as menuNs } from './menu.mjs'
|
2023-06-23 17:45:50 -05:00
|
|
|
import { PatternWithMenu, ns as wrapperNs } from '../pattern-with-menu.mjs'
|
2023-06-04 09:59:47 -05:00
|
|
|
|
2023-08-30 17:03:51 +02:00
|
|
|
export const ns = nsMerge(menuNs, wrapperNs, exportNs, 'print', 'status')
|
2023-06-04 09:59:47 -05:00
|
|
|
|
|
|
|
export const PrintView = ({
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
settings,
|
2023-06-23 17:45:50 -05:00
|
|
|
setSettings,
|
2023-06-04 09:59:47 -05:00
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
2023-06-05 16:07:16 -05:00
|
|
|
Design,
|
2023-06-04 09:59:47 -05:00
|
|
|
}) => {
|
2023-06-05 16:07:16 -05:00
|
|
|
const { t } = useTranslation(ns)
|
2023-09-04 08:40:05 +02:00
|
|
|
const { loading, setLoadingStatus } = useContext(LoadingStatusContext)
|
2023-06-04 09:59:47 -05:00
|
|
|
|
2023-06-04 23:28:43 -05:00
|
|
|
const defaultSettings = defaultPrintSettings(settings.units)
|
2023-06-04 09:59:47 -05:00
|
|
|
// add the pages plugin to the draft
|
2023-06-05 16:07:16 -05:00
|
|
|
const pageSettings = {
|
2023-06-04 23:28:43 -05:00
|
|
|
...defaultSettings,
|
2023-06-05 16:07:16 -05:00
|
|
|
...get(ui, printSettingsPath, {}),
|
2023-06-04 09:59:47 -05:00
|
|
|
}
|
|
|
|
|
2023-06-05 16:07:16 -05:00
|
|
|
pattern.use(pagesPlugin(pageSettings))
|
2023-06-04 09:59:47 -05:00
|
|
|
|
2023-06-04 23:28:43 -05:00
|
|
|
let renderProps
|
2023-06-04 09:59:47 -05:00
|
|
|
try {
|
|
|
|
// draft the pattern
|
|
|
|
pattern.draft()
|
2023-06-04 23:28:43 -05:00
|
|
|
renderProps = pattern.getRenderProps()
|
2023-06-04 09:59:47 -05:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
const exportIt = () => {
|
2023-08-30 17:03:51 +02:00
|
|
|
setLoadingStatus([true, 'generatingPdf'])
|
2023-06-05 16:07:16 -05:00
|
|
|
handleExport({
|
2023-08-06 18:24:14 +00:00
|
|
|
format: pageSettings.size,
|
2023-06-05 16:07:16 -05:00
|
|
|
settings,
|
|
|
|
design,
|
|
|
|
t,
|
|
|
|
Design,
|
|
|
|
ui,
|
|
|
|
startLoading: loading.startLoading,
|
|
|
|
stopLoading: loading.stopLoading,
|
2023-08-30 17:03:51 +02:00
|
|
|
onComplete: () => {
|
|
|
|
setLoadingStatus([true, 'pdfReady', true, true])
|
|
|
|
},
|
2023-08-30 17:43:27 +02:00
|
|
|
onError: (err) => {
|
|
|
|
setLoadingStatus([true, 'pdfFailed', true, true])
|
|
|
|
console.log(err)
|
|
|
|
},
|
2023-06-05 16:07:16 -05:00
|
|
|
})
|
2023-06-04 09:59:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2023-08-30 17:03:51 +02:00
|
|
|
<>
|
|
|
|
<PatternWithMenu
|
|
|
|
noHeader
|
|
|
|
{...{
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
control: account.control,
|
|
|
|
account,
|
|
|
|
design,
|
|
|
|
setSettings,
|
|
|
|
title: (
|
|
|
|
<h2 className="text-center lg:text-left capitalize">{t('workbench:printLayout')}</h2>
|
|
|
|
),
|
|
|
|
pattern: (
|
|
|
|
<MovablePattern
|
|
|
|
{...{
|
|
|
|
renderProps,
|
|
|
|
update,
|
|
|
|
immovable: ['pages'],
|
|
|
|
layoutPath: ['layouts', 'print'],
|
|
|
|
showButtons: !ui.hideMovableButtons,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
menu: (
|
|
|
|
<PrintMenu
|
|
|
|
{...{
|
|
|
|
design,
|
|
|
|
pattern,
|
|
|
|
patternConfig,
|
|
|
|
setSettings,
|
|
|
|
settings,
|
|
|
|
ui,
|
|
|
|
update,
|
|
|
|
language,
|
|
|
|
account,
|
|
|
|
DynamicDocs,
|
|
|
|
exportIt,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
),
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
2023-06-04 09:59:47 -05:00
|
|
|
)
|
|
|
|
}
|