54 lines
1.7 KiB
Text
54 lines
1.7 KiB
Text
![]() |
// Hooks
|
||
|
import { useEffect, useState, useMemo } from 'react'
|
||
|
import { useAccount } frmo 'shared/hooks/use-account.mjs'
|
||
|
import { useBackend } from 'shared/hooks/use-backend.mjs'
|
||
|
// Dependencies
|
||
|
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'
|
||
|
import { {{ Design }} } from '@freesewing/{{ design }}'
|
||
|
// Components
|
||
|
import { PageWrapper, ns as pageNs } from 'shared/components/wrappers/page.mjs'
|
||
|
import { Workbench, ns as wbNs } from 'shared/components/workbench/index.mjs'
|
||
|
import { WorkbenchLayout } from 'site/components/layouts/workbench.mjs'
|
||
|
import { Null } from 'shared/components/null.mjs'
|
||
|
|
||
|
// Translation namespaces used on this page
|
||
|
const namespaces = [...new Set(['{{ design }}', ...wbNs, ...pageNs])]
|
||
|
|
||
|
const New{{ Design }}FromSetPage = ({ page, id }) => {
|
||
|
const { token } = useAccount()
|
||
|
const backend = useBackend(token)
|
||
|
const [set, setSet] = useState(false)
|
||
|
|
||
|
useEffect(() => {
|
||
|
const getSet = async () => {
|
||
|
const result = await backend.getSet(id)
|
||
|
if (result.success) setSet(result.data.set)
|
||
|
}
|
||
|
// Guard against loops as the backend object is recreated on each render
|
||
|
if (set.id !== id) getSet()
|
||
|
}, [id, backend])
|
||
|
|
||
|
return (
|
||
|
<PageWrapper {...page} title="{{ Design }}" layout={WorkbenchLayout} header={Null}>
|
||
|
<Workbench design="{{ design }}" Design={ {{ Design }} } set={set} />
|
||
|
</PageWrapper>
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export default New{{ Design }}FromSetPage
|
||
|
|
||
|
export async function getStaticProps({ locale, params }) {
|
||
|
return {
|
||
|
props: {
|
||
|
...(await serverSideTranslations(locale, namespaces)),
|
||
|
id: Number(params.id),
|
||
|
page: {
|
||
|
locale,
|
||
|
path: ['new', 'pattern', '{{ design }}', 'set', params.id],
|
||
|
title: '',
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
|