Merge remote-tracking branch 'origin/master' into feature/slicing

This commit is contained in:
fredy.siswanto
2025-03-08 04:34:08 +07:00
22 changed files with 308 additions and 137 deletions
@@ -1,4 +1,4 @@
import { CreateCategoryPage } from '~/pages/dashboard-category-create'
import { FormCategoryPage } from '~/pages/form-category'
const DashboardCategoriesCreateLayout = () => <CreateCategoryPage />
const DashboardCategoriesCreateLayout = () => <FormCategoryPage />
export default DashboardCategoriesCreateLayout
@@ -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
@@ -1,4 +1,4 @@
import { ContentsFormPage } from '~/pages/contents-form'
import { FormContentsPage } from '~/pages/form-contents'
const DashboardContentCreateLayout = () => <ContentsFormPage />
const DashboardContentCreateLayout = () => <FormContentsPage />
export default DashboardContentCreateLayout
@@ -1,20 +1,20 @@
import { getNewsBySlug } from '~/apis/common/get-news-by-slug'
import { handleCookie } from '~/libs/cookies'
import { ContentsFormPage } from '~/pages/contents-form'
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 }
}
const DashboardContentUpdateLayout = ({ loaderData }: Route.ComponentProps) => {
const newsData = loaderData.newsData
return <ContentsFormPage newsData={newsData} />
return <FormContentsPage newsData={newsData} />
}
export default DashboardContentUpdateLayout
@@ -8,7 +8,7 @@ import { handleCookie } from '~/libs/cookies'
import {
createCategorySchema,
type TCategorySchema,
} from '~/pages/dashboard-category-create'
} from '~/pages/form-category'
import type { Route } from './+types/actions.register'
@@ -0,0 +1,67 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { data } from 'react-router'
import { getValidatedFormData } from 'remix-hook-form'
import { XiorError } from 'xior'
import { updateCategoryRequest } from '~/apis/admin/update-category'
import { handleCookie } from '~/libs/cookies'
import {
createCategorySchema,
type TCategorySchema,
} from '~/pages/form-category'
import type { Route } from './+types/actions.register'
export const action = async ({ request }: Route.ActionArgs) => {
const { staffToken } = await handleCookie(request)
try {
const {
errors,
data: payload,
receivedValues: defaultValues,
} = await getValidatedFormData<TCategorySchema>(
request,
zodResolver(createCategorySchema),
false,
)
if (errors) {
return data({ success: false, errors, defaultValues }, { status: 400 })
}
const { data: categoryData } = await updateCategoryRequest({
accessToken: staffToken,
payload,
})
return data(
{
success: true,
categoryData,
},
{
status: 200,
statusText: 'OK',
},
)
} catch (error) {
if (error instanceof XiorError) {
return data(
{
success: false,
message: error?.response?.data?.error?.message || error.message,
},
{
status: error?.response?.status || 500,
},
)
}
return data(
{
success: false,
message: 'Internal server error',
},
{ status: 500 },
)
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ import { XiorError } from 'xior'
import { createNewsRequest } from '~/apis/admin/create-news'
import { handleCookie } from '~/libs/cookies'
import { contentSchema, type TContentSchema } from '~/pages/contents-form'
import { contentSchema, type TContentSchema } from '~/pages/form-contents'
import type { Route } from './+types/actions.register'
+1 -1
View File
@@ -5,7 +5,7 @@ import { XiorError } from 'xior'
import { updateNewsRequest } from '~/apis/admin/update-news'
import { handleCookie } from '~/libs/cookies'
import { contentSchema, type TContentSchema } from '~/pages/contents-form'
import { contentSchema, type TContentSchema } from '~/pages/form-contents'
import type { Route } from './+types/actions.register'