49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import React from 'react'
|
|
import { createFileRoute } from '@tanstack/react-router'
|
|
import { AppContainer, p as MyText } from 'web-components'
|
|
import ProductGroupForm from '../components/ProductGroupForm'
|
|
import { trpc } from '@/lib/trpc-client'
|
|
|
|
export const Route = createFileRoute('/dashboard/product-groupings/$id/edit')({
|
|
component: EditProductGroup,
|
|
})
|
|
|
|
function EditProductGroup() {
|
|
const { id } = Route.useParams()
|
|
|
|
const groupId = parseInt(id as string)
|
|
|
|
const { data: groupsData, isLoading } = trpc.admin.product.getGroups.useQuery()
|
|
const groups = groupsData?.groups || []
|
|
const group = groups.find((g) => g.id === groupId)
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<AppContainer>
|
|
<div className="flex flex-1 items-center justify-center">
|
|
<MyText>Loading group...</MyText>
|
|
</div>
|
|
</AppContainer>
|
|
)
|
|
}
|
|
|
|
if (!group) {
|
|
return (
|
|
<AppContainer>
|
|
<div className="flex flex-1 items-center justify-center">
|
|
<MyText>Group not found</MyText>
|
|
</div>
|
|
</AppContainer>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<AppContainer>
|
|
<ProductGroupForm
|
|
group={group}
|
|
onClose={() => window.history.back()}
|
|
onSuccess={() => window.history.back()}
|
|
/>
|
|
</AppContainer>
|
|
)
|
|
}
|