feat: refactor category update functionality
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import { getCategories } from '~/apis/common/get-categories'
|
||||
import { handleCookie } from '~/libs/cookies'
|
||||
import { FormCategoryPage } from '~/pages/form-category'
|
||||
|
||||
import type { Route } from './+types/_admin.lg-admin._dashboard.categories.update.$id'
|
||||
|
||||
export const loader = async ({ request, params }: Route.LoaderArgs) => {
|
||||
const { staffToken } = await handleCookie(request)
|
||||
const { data: categoriesData } = await getCategories({
|
||||
accessToken: staffToken,
|
||||
})
|
||||
const categoryData = categoriesData.find(
|
||||
(category) => category.id === params.id,
|
||||
)
|
||||
return { categoryData }
|
||||
}
|
||||
|
||||
const DashboardCategoriesUpdateLayout = ({
|
||||
loaderData,
|
||||
}: Route.ComponentProps) => {
|
||||
const categoryData = loaderData.categoryData
|
||||
return <FormCategoryPage categoryData={categoryData} />
|
||||
}
|
||||
export default DashboardCategoriesUpdateLayout
|
||||
@@ -1,4 +0,0 @@
|
||||
import { UpdateCategoryPage } from '~/pages/dashboard-category-update'
|
||||
|
||||
const DashboardCategoriesUpdateLayout = () => <UpdateCategoryPage />
|
||||
export default DashboardCategoriesUpdateLayout
|
||||
@@ -4,11 +4,11 @@ import { FormContentsPage } from '~/pages/form-contents'
|
||||
|
||||
import type { Route } from './+types/_admin.lg-admin._dashboard.contents.update.$slug'
|
||||
|
||||
export const loader = async ({ request }: Route.LoaderArgs) => {
|
||||
export const loader = async ({ request, params }: Route.LoaderArgs) => {
|
||||
const { staffToken } = await handleCookie(request)
|
||||
const { data: newsData } = await getNewsBySlug({
|
||||
accessToken: staffToken,
|
||||
slug: request.url.split('/').pop() ?? '',
|
||||
slug: params.slug,
|
||||
})
|
||||
return { newsData }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user