Merge commit '9c9d127dfb1a8e3633f803f527c27bbfc6346b4d'

* commit '9c9d127dfb1a8e3633f803f527c27bbfc6346b4d':
  feat: add delete functionality for news articles with confirmation dialog
This commit is contained in:
Ardeman
2025-03-19 18:21:19 +08:00
3 changed files with 115 additions and 12 deletions
@@ -0,0 +1,48 @@
import { data } from 'react-router'
import { XiorError } from 'xior'
import { deleteContentsRequest } from '~/apis/admin/delete-contents'
import { handleCookie } from '~/libs/cookies'
import type { Route } from './+types/actions.admin.contents.delete.$id'
export const action = async ({ request, params }: Route.ActionArgs) => {
const { staffToken: accessToken } = await handleCookie(request)
const { id } = params
try {
const { data: newsData } = await deleteContentsRequest({
accessToken,
id,
})
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 },
)
}
}