43 lines
922 B
TypeScript
43 lines
922 B
TypeScript
import AdminPermission from '@/components/(protected)/admin/auth/permission'
|
|
import {EntityCrudForm} from '@/components/(protected)/admin/entity/crud-form'
|
|
import ProductCreateEditForm from '@/components/(protected)/admin/product/create-edit-form'
|
|
import {getProductById} from '@/lib/data/models/product'
|
|
import {dump} from '@/lib/utils'
|
|
|
|
export default async function Page({
|
|
params
|
|
}: {
|
|
params: Promise<{slug?: string[]}>
|
|
}) {
|
|
const {slug} = await params
|
|
const [method, id] = slug || []
|
|
|
|
let data = null
|
|
|
|
if (id) {
|
|
data = await getProductById(parseInt(id))
|
|
if (data) {
|
|
data = JSON.parse(JSON.stringify(data))
|
|
}
|
|
}
|
|
|
|
switch (method) {
|
|
case 'create':
|
|
return (
|
|
<>
|
|
<AdminPermission />
|
|
<ProductCreateEditForm />
|
|
</>
|
|
)
|
|
case 'update':
|
|
return (
|
|
<>
|
|
<AdminPermission />
|
|
<ProductCreateEditForm data={data} />
|
|
</>
|
|
)
|
|
default:
|
|
return <div>{dump(slug)}</div>
|
|
}
|
|
}
|