refactor: update loaderData imports in dashboard pages for consistency
This commit is contained in:
parent
05b3af8718
commit
4554cca392
@ -6,9 +6,11 @@ import type { TCategoryResponse } from '~/apis/common/get-categories'
|
|||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
import { UiTable } from '~/components/ui/table'
|
import { UiTable } from '~/components/ui/table'
|
||||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||||
import type { loader } from '~/routes/_admin.lg-admin'
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard'
|
||||||
export const CategoriesPage = () => {
|
export const CategoriesPage = () => {
|
||||||
const loaderData = useRouteLoaderData<typeof loader>('routes/_admin.lg-admin')
|
const loaderData = useRouteLoaderData<typeof loader>(
|
||||||
|
'routes/_admin.lg-admin._dashboard',
|
||||||
|
)
|
||||||
|
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
const dataTable = loaderData?.categoriesData?.sort((a, b) => {
|
const dataTable = loaderData?.categoriesData?.sort((a, b) => {
|
||||||
|
|||||||
@ -5,11 +5,11 @@ import { Link, useRouteLoaderData } from 'react-router'
|
|||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
import { UiTable } from '~/components/ui/table'
|
import { UiTable } from '~/components/ui/table'
|
||||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||||
import type { loader } from '~/routes/_admin.lg-admin._dashboard.tags._index'
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard'
|
||||||
|
|
||||||
export const TagsPage = () => {
|
export const TagsPage = () => {
|
||||||
const loaderData = useRouteLoaderData<typeof loader>(
|
const loaderData = useRouteLoaderData<typeof loader>(
|
||||||
'routes/_admin.lg-admin._dashboard.tags._index',
|
'routes/_admin.lg-admin._dashboard',
|
||||||
)
|
)
|
||||||
const { tagsData: dataTable } = loaderData || {}
|
const { tagsData: dataTable } = loaderData || {}
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ import { Combobox } from '~/components/ui/combobox'
|
|||||||
import { Input } from '~/components/ui/input'
|
import { Input } from '~/components/ui/input'
|
||||||
import { Switch } from '~/components/ui/switch'
|
import { Switch } from '~/components/ui/switch'
|
||||||
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
import { TitleDashboard } from '~/components/ui/title-dashboard'
|
||||||
import type { loader } from '~/routes/_admin.lg-admin'
|
import type { loader } from '~/routes/_admin.lg-admin._dashboard'
|
||||||
|
|
||||||
export const contentSchema = z.object({
|
export const contentSchema = z.object({
|
||||||
id: z.string().optional(),
|
id: z.string().optional(),
|
||||||
@ -64,7 +64,9 @@ export const FormContentsPage = (properties: TProperties) => {
|
|||||||
const { newsData } = properties || {}
|
const { newsData } = properties || {}
|
||||||
const fetcher = useFetcher()
|
const fetcher = useFetcher()
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const loaderData = useRouteLoaderData<typeof loader>('routes/_admin.lg-admin')
|
const loaderData = useRouteLoaderData<typeof loader>(
|
||||||
|
'routes/_admin.lg-admin._dashboard',
|
||||||
|
)
|
||||||
const { categoriesData: categories } = loaderData || {}
|
const { categoriesData: categories } = loaderData || {}
|
||||||
const { tagsData: tags } = loaderData || {}
|
const { tagsData: tags } = loaderData || {}
|
||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
|
|||||||
@ -1,12 +1,4 @@
|
|||||||
import { getTags } from '~/apis/common/get-tags'
|
|
||||||
import { TagsPage } from '~/pages/dashboard-tags'
|
import { TagsPage } from '~/pages/dashboard-tags'
|
||||||
|
|
||||||
import type { Route } from './+types/_admin.lg-admin._dashboard.tags._index'
|
|
||||||
|
|
||||||
export const loader = async ({}: Route.LoaderArgs) => {
|
|
||||||
const { data: tagsData } = await getTags()
|
|
||||||
return { tagsData }
|
|
||||||
}
|
|
||||||
|
|
||||||
const DashboardTagsIndexLayout = () => <TagsPage />
|
const DashboardTagsIndexLayout = () => <TagsPage />
|
||||||
export default DashboardTagsIndexLayout
|
export default DashboardTagsIndexLayout
|
||||||
|
|||||||
@ -1,7 +1,21 @@
|
|||||||
import { Outlet } from 'react-router'
|
import { Outlet } from 'react-router'
|
||||||
|
|
||||||
|
import { getCategories } from '~/apis/common/get-categories'
|
||||||
|
import { getTags } from '~/apis/common/get-tags'
|
||||||
import { AdminDashboardLayout } from '~/layouts/admin/dashboard'
|
import { AdminDashboardLayout } from '~/layouts/admin/dashboard'
|
||||||
|
|
||||||
|
import type { Route } from './+types/_admin.lg-admin._dashboard'
|
||||||
|
|
||||||
|
export const loader = async ({}: Route.LoaderArgs) => {
|
||||||
|
const { data: categoriesData } = await getCategories()
|
||||||
|
const { data: tagsData } = await getTags()
|
||||||
|
|
||||||
|
return {
|
||||||
|
categoriesData,
|
||||||
|
tagsData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const DashboardLayout = () => {
|
const DashboardLayout = () => {
|
||||||
return (
|
return (
|
||||||
<AdminDashboardLayout>
|
<AdminDashboardLayout>
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import { Outlet, redirect } from 'react-router'
|
import { Outlet, redirect } from 'react-router'
|
||||||
|
|
||||||
import { getStaff } from '~/apis/admin/get-staff'
|
import { getStaff } from '~/apis/admin/get-staff'
|
||||||
import { getCategories } from '~/apis/common/get-categories'
|
|
||||||
import { getTags } from '~/apis/common/get-tags'
|
|
||||||
import { AUTH_PAGES } from '~/configs/pages'
|
import { AUTH_PAGES } from '~/configs/pages'
|
||||||
import { AdminDefaultLayout } from '~/layouts/admin/default'
|
import { AdminDefaultLayout } from '~/layouts/admin/default'
|
||||||
import { handleCookie } from '~/libs/cookies'
|
import { handleCookie } from '~/libs/cookies'
|
||||||
@ -29,13 +27,9 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
|
|||||||
})
|
})
|
||||||
staffData = data
|
staffData = data
|
||||||
}
|
}
|
||||||
const { data: categoriesData } = await getCategories()
|
|
||||||
const { data: tagsData } = await getTags()
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
staffData,
|
staffData,
|
||||||
categoriesData,
|
|
||||||
tagsData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user