feat: implement delete tag functionality with confirmation dialog

This commit is contained in:
Ardeman
2025-03-13 09:05:29 +08:00
parent eadfccfc0e
commit 2c703de8e5
4 changed files with 171 additions and 15 deletions
@@ -0,0 +1,48 @@
import { data } from 'react-router'
import { XiorError } from 'xior'
import { deleteTagsRequest } from '~/apis/admin/delete-tags'
import { handleCookie } from '~/libs/cookies'
import type { Route } from './+types/actions.admin.advertisements.create'
export const action = async ({ request, params }: Route.ActionArgs) => {
const { staffToken: accessToken } = await handleCookie(request)
const { id } = params
try {
const { data: tagData } = await deleteTagsRequest({
accessToken,
id,
})
return data(
{
success: true,
tagData,
},
{
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 },
)
}
}