feat: integrate news data fetching by slug and update ContentsFormPage to utilize fetched data

This commit is contained in:
Ardeman
2025-03-07 13:50:16 +08:00
parent 2c05c543ce
commit 5c716d7210
4 changed files with 58 additions and 12 deletions
@@ -1,4 +1,20 @@
import { getNewsBySlug } from '~/apis/common/get-news-by-slug'
import { handleCookie } from '~/libs/cookies'
import { ContentsFormPage } from '~/pages/contents-form'
const DashboardContentUpdateLayout = () => <ContentsFormPage />
import type { Route } from './+types/_admin.lg-admin._dashboard.contents.update.$slug'
export const loader = async ({ request }: Route.LoaderArgs) => {
const { staffToken } = await handleCookie(request)
const { data: newsData } = await getNewsBySlug({
accessToken: staffToken,
slug: request.url.split('/').pop() ?? '',
})
return { newsData }
}
const DashboardContentUpdateLayout = ({ loaderData }: Route.ComponentProps) => {
const newsData = loaderData.newsData
return <ContentsFormPage newsData={newsData} />
}
export default DashboardContentUpdateLayout