Merge remote-tracking branch 'origin/master' into feature/slicing
This commit is contained in:
commit
c46e8fc11b
@ -21,12 +21,9 @@ export const createNewsRequest = async (parameters: TParameter) => {
|
|||||||
const transformedPayload = {
|
const transformedPayload = {
|
||||||
...restPayload,
|
...restPayload,
|
||||||
categories: categories.map((category) => category?.id),
|
categories: categories.map((category) => category?.id),
|
||||||
tags: tags?.map((tag) => tag?.id),
|
tags: tags?.map((tag) => tag?.id) || [],
|
||||||
live_at: new Date(payload?.live_at).toISOString(),
|
live_at: new Date(payload?.live_at).toISOString(),
|
||||||
}
|
}
|
||||||
if (transformedPayload.tags?.length === 0) {
|
|
||||||
delete transformedPayload.tags
|
|
||||||
}
|
|
||||||
const { data } = await HttpServer({ accessToken }).post(
|
const { data } = await HttpServer({ accessToken }).post(
|
||||||
'/api/news/create',
|
'/api/news/create',
|
||||||
transformedPayload,
|
transformedPayload,
|
||||||
|
|||||||
36
app/apis/admin/update-news.ts
Normal file
36
app/apis/admin/update-news.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { z } from 'zod'
|
||||||
|
|
||||||
|
import { HttpServer } from '~/libs/http-server'
|
||||||
|
import type { TContentSchema } from '~/pages/contents-form'
|
||||||
|
|
||||||
|
const newsResponseSchema = z.object({
|
||||||
|
data: z.object({
|
||||||
|
Message: z.string(),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
type TParameter = {
|
||||||
|
accessToken: string
|
||||||
|
payload: TContentSchema
|
||||||
|
}
|
||||||
|
|
||||||
|
export const updateNewsRequest = async (parameters: TParameter) => {
|
||||||
|
const { accessToken, payload } = parameters
|
||||||
|
try {
|
||||||
|
const { categories, tags, id, ...restPayload } = payload
|
||||||
|
const transformedPayload = {
|
||||||
|
...restPayload,
|
||||||
|
categories: categories.map((category) => category?.id),
|
||||||
|
tags: tags?.map((tag) => tag?.id) || [],
|
||||||
|
live_at: new Date(payload?.live_at).toISOString(),
|
||||||
|
}
|
||||||
|
const { data } = await HttpServer({ accessToken }).put(
|
||||||
|
`/api/news/${id}/update`,
|
||||||
|
transformedPayload,
|
||||||
|
)
|
||||||
|
return newsResponseSchema.parse(data)
|
||||||
|
} catch (error) {
|
||||||
|
// eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
|
||||||
|
return Promise.reject(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import type { JSX, SVGProps } from 'react'
|
import { ClipboardDocumentCheckIcon } from '@heroicons/react/20/solid'
|
||||||
|
import type { SVGProps } from 'react'
|
||||||
|
|
||||||
import { ChartIcon } from '~/components/icons/chart'
|
import { ChartIcon } from '~/components/icons/chart'
|
||||||
import { ChatIcon } from '~/components/icons/chat'
|
import { ChatIcon } from '~/components/icons/chat'
|
||||||
@ -6,16 +7,13 @@ import { DocumentIcon } from '~/components/icons/document'
|
|||||||
import { MedicalNotesIcon } from '~/components/icons/medical-notes'
|
import { MedicalNotesIcon } from '~/components/icons/medical-notes'
|
||||||
import { ProfileIcon } from '~/components/icons/profile'
|
import { ProfileIcon } from '~/components/icons/profile'
|
||||||
import { SettingIcon } from '~/components/icons/setting'
|
import { SettingIcon } from '~/components/icons/setting'
|
||||||
import { WalletIcon } from '~/components/icons/wallet'
|
|
||||||
|
|
||||||
type TMenu = {
|
type TMenu = {
|
||||||
group: string
|
group: string
|
||||||
items: {
|
items: {
|
||||||
title: string
|
title: string
|
||||||
url: string
|
url: string
|
||||||
icon: (
|
icon: React.ComponentType<SVGProps<SVGSVGElement>>
|
||||||
properties: JSX.IntrinsicAttributes & SVGProps<SVGSVGElement>,
|
|
||||||
) => JSX.Element
|
|
||||||
}[]
|
}[]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,9 +52,9 @@ export const MENU: TMenu[] = [
|
|||||||
group: 'Others',
|
group: 'Others',
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
title: 'Data Situs',
|
title: 'Kategori',
|
||||||
url: '/lg-admin/site-data',
|
url: '/lg-admin/categories',
|
||||||
icon: WalletIcon,
|
icon: ClipboardDocumentCheckIcon,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Pengaturan',
|
title: 'Pengaturan',
|
||||||
|
|||||||
@ -15,6 +15,7 @@ import { TitleDashboard } from '~/components/ui/title-dashboard'
|
|||||||
import type { loader } from '~/routes/_admin.lg-admin'
|
import type { loader } from '~/routes/_admin.lg-admin'
|
||||||
|
|
||||||
export const contentSchema = z.object({
|
export const contentSchema = z.object({
|
||||||
|
id: z.string().optional(),
|
||||||
categories: z
|
categories: z
|
||||||
.array(
|
.array(
|
||||||
z
|
z
|
||||||
@ -74,6 +75,7 @@ export const ContentsFormPage = (properties: TProperties) => {
|
|||||||
fetcher,
|
fetcher,
|
||||||
resolver: zodResolver(contentSchema),
|
resolver: zodResolver(contentSchema),
|
||||||
values: {
|
values: {
|
||||||
|
id: newsData?.id || '',
|
||||||
categories: newsData?.categories || [],
|
categories: newsData?.categories || [],
|
||||||
tags: newsData?.tags || [],
|
tags: newsData?.tags || [],
|
||||||
title: newsData?.title || '',
|
title: newsData?.title || '',
|
||||||
@ -110,7 +112,7 @@ export const ContentsFormPage = (properties: TProperties) => {
|
|||||||
<fetcher.Form
|
<fetcher.Form
|
||||||
method="post"
|
method="post"
|
||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
action="/actions/admin/contents/update"
|
action={`/actions/admin/contents/${newsData ? 'update' : 'create'}`}
|
||||||
className="space-y-4"
|
className="space-y-4"
|
||||||
>
|
>
|
||||||
{error && (
|
{error && (
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import DataTable from 'datatables.net-dt'
|
import DT from 'datatables.net-dt'
|
||||||
import DT from 'datatables.net-react'
|
import DataTable from 'datatables.net-react'
|
||||||
import { Link, useRouteLoaderData } from 'react-router'
|
import { Link, useRouteLoaderData } from 'react-router'
|
||||||
|
|
||||||
import { Button } from '~/components/ui/button'
|
import { Button } from '~/components/ui/button'
|
||||||
@ -10,9 +10,10 @@ export const CategoriesPage = () => {
|
|||||||
const loaderData = useRouteLoaderData<typeof loader>(
|
const loaderData = useRouteLoaderData<typeof loader>(
|
||||||
'routes/_admin.lg-admin._dashboard.categories._index',
|
'routes/_admin.lg-admin._dashboard.categories._index',
|
||||||
)
|
)
|
||||||
const dataTable = loaderData?.dataCategories
|
const categoriesData = loaderData?.dataCategories
|
||||||
|
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
|
const dataTable = categoriesData
|
||||||
const dataColumns = [
|
const dataColumns = [
|
||||||
{
|
{
|
||||||
title: 'No',
|
title: 'No',
|
||||||
@ -26,11 +27,11 @@ export const CategoriesPage = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Nama Kategori',
|
title: 'Nama',
|
||||||
data: 'name',
|
data: 'name',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Code Katgeori',
|
title: 'Kode',
|
||||||
data: 'code',
|
data: 'code',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -38,7 +39,18 @@ export const CategoriesPage = () => {
|
|||||||
data: 'id',
|
data: 'id',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
const dataSlot = {
|
||||||
|
3: (value: string) => (
|
||||||
|
<Button
|
||||||
|
as="a"
|
||||||
|
href={`/lg-admin/categories/update/${value}`}
|
||||||
|
className="text-md rounded-md"
|
||||||
|
size="sm"
|
||||||
|
>
|
||||||
|
Update Kategori
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
}
|
||||||
const dataOptions = {
|
const dataOptions = {
|
||||||
paging: true,
|
paging: true,
|
||||||
searching: true,
|
searching: true,
|
||||||
@ -46,18 +58,6 @@ export const CategoriesPage = () => {
|
|||||||
info: true,
|
info: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataSlot = {
|
|
||||||
3: (value: string) => (
|
|
||||||
<Button
|
|
||||||
as="a"
|
|
||||||
href={`/lg-admin/category/update/${value}`}
|
|
||||||
className="text-md rounded-md"
|
|
||||||
size="sm"
|
|
||||||
>
|
|
||||||
Lihat Detail
|
|
||||||
</Button>
|
|
||||||
),
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
<TitleDashboard title="Kategori" />
|
<TitleDashboard title="Kategori" />
|
||||||
@ -65,11 +65,11 @@ export const CategoriesPage = () => {
|
|||||||
<div className="flex-1">{/* TODO: Filter */}</div>
|
<div className="flex-1">{/* TODO: Filter */}</div>
|
||||||
<Button
|
<Button
|
||||||
as={Link}
|
as={Link}
|
||||||
to="/lg-admin/category/create"
|
to="/lg-admin/categories/create"
|
||||||
className="text-md h-[42px] rounded-md"
|
className="text-md h-[42px] rounded-md"
|
||||||
size="lg"
|
size="lg"
|
||||||
>
|
>
|
||||||
Create New
|
Buat Kategori
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ export const CategoriesPage = () => {
|
|||||||
columns={dataColumns}
|
columns={dataColumns}
|
||||||
options={dataOptions}
|
options={dataOptions}
|
||||||
slots={dataSlot}
|
slots={dataSlot}
|
||||||
title="Daftar Katgeori"
|
title="Daftar Kategori"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@ -18,7 +18,9 @@ export const ContentsPage = () => {
|
|||||||
const newsData = loaderData?.newsData
|
const newsData = loaderData?.newsData
|
||||||
|
|
||||||
DataTable.use(DT)
|
DataTable.use(DT)
|
||||||
const dataTable = newsData
|
const dataTable = newsData?.sort(
|
||||||
|
(a, b) => new Date(b.live_at).getTime() - new Date(a.live_at).getTime(),
|
||||||
|
)
|
||||||
const dataColumns = [
|
const dataColumns = [
|
||||||
{
|
{
|
||||||
title: 'No',
|
title: 'No',
|
||||||
@ -32,11 +34,11 @@ export const ContentsPage = () => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Tanggal Konten',
|
title: 'Tanggal Live',
|
||||||
data: 'live_at',
|
data: 'live_at',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Nama Penulis',
|
title: 'Penulis',
|
||||||
},
|
},
|
||||||
{ title: 'Judul', data: 'title' },
|
{ title: 'Judul', data: 'title' },
|
||||||
{
|
{
|
||||||
|
|||||||
@ -11,5 +11,6 @@ export const loader = async ({ request }: Route.LoaderArgs) => {
|
|||||||
})
|
})
|
||||||
return { dataCategories }
|
return { dataCategories }
|
||||||
}
|
}
|
||||||
const DashboardCategoriesLayout = () => <CategoriesPage />
|
|
||||||
export default DashboardCategoriesLayout
|
const DashboardCategoriesIndexLayout = () => <CategoriesPage />
|
||||||
|
export default DashboardCategoriesIndexLayout
|
||||||
|
|||||||
@ -0,0 +1,4 @@
|
|||||||
|
import { CreateCategoryPage } from '~/pages/dashboard-category-create'
|
||||||
|
|
||||||
|
const DashboardCategoriesCreateLayout = () => <CreateCategoryPage />
|
||||||
|
export default DashboardCategoriesCreateLayout
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
import { UpdateCategoryPage } from '~/pages/dashboard-category-update'
|
||||||
|
|
||||||
|
const DashboardCategoriesUpdateLayout = () => <UpdateCategoryPage />
|
||||||
|
export default DashboardCategoriesUpdateLayout
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { CreateCategoryPage } from '~/pages/dashboard-category-create'
|
|
||||||
|
|
||||||
const DashboardCategoryLayout = () => <CreateCategoryPage />
|
|
||||||
export default DashboardCategoryLayout
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import { UpdateCategoryPage } from '~/pages/dashboard-category-update'
|
|
||||||
|
|
||||||
const DashboardCategoryUpdateLayout = () => <UpdateCategoryPage />
|
|
||||||
export default DashboardCategoryUpdateLayout
|
|
||||||
64
app/routes/actions.admin.contents.update.ts
Normal file
64
app/routes/actions.admin.contents.update.ts
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import { zodResolver } from '@hookform/resolvers/zod'
|
||||||
|
import { data } from 'react-router'
|
||||||
|
import { getValidatedFormData } from 'remix-hook-form'
|
||||||
|
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 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<TContentSchema>(
|
||||||
|
request,
|
||||||
|
zodResolver(contentSchema),
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (errors) {
|
||||||
|
return data({ success: false, errors, defaultValues }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data: newsData } = await updateNewsRequest({
|
||||||
|
accessToken: staffToken,
|
||||||
|
payload,
|
||||||
|
})
|
||||||
|
|
||||||
|
return data(
|
||||||
|
{
|
||||||
|
success: true,
|
||||||
|
newsData,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
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 },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user