wip: page update for removing changelog relation

This commit is contained in:
Lars Hampe 2024-10-24 22:43:27 +02:00
parent 596ead5302
commit 139832ad46
6 changed files with 55 additions and 22 deletions

View File

@ -23,12 +23,12 @@ export const app = new OpenAPIHono<{ Variables: Variables }>({
defaultHook: handleZodError, defaultHook: handleZodError,
}) })
app.use( // app.use(
'*', // '*',
sentry({ // sentry({
dsn: 'https://1d7428bbab0a305078cf4aa380721aa2@o4508167321354240.ingest.de.sentry.io/4508167323648080', // dsn: 'https://1d7428bbab0a305078cf4aa380721aa2@o4508167321354240.ingest.de.sentry.io/4508167323648080',
}), // }),
) // )
app.onError(handleError) app.onError(handleError)
app.use('*', cors()) app.use('*', cors())
app.use('/v1/*', authentication) app.use('/v1/*', authentication)

View File

@ -6,12 +6,23 @@ import {
CardTitle, CardTitle,
} from '@boring.tools/ui' } from '@boring.tools/ui'
import { Link, createLazyFileRoute } from '@tanstack/react-router' import { Link, createLazyFileRoute } from '@tanstack/react-router'
import { PlusCircleIcon } from 'lucide-react' import { CircleMinusIcon, PlusCircleIcon } from 'lucide-react'
import { usePageById } from '../hooks/usePage' import { usePageById, usePageUpdate } from '../hooks/usePage'
const Component = () => { const Component = () => {
const { id } = Route.useParams() const { id } = Route.useParams()
const { data, isPending } = usePageById({ id }) const { data, isPending } = usePageById({ id })
const pageUpdate = usePageUpdate()
const removeChangelog = (id: string) => {
const payload = {
title: data?.title,
description: data?.description,
changelogIds: data?.changelogs
.filter((log) => log.id !== id)
.map((l) => l.id),
}
pageUpdate.mutate({ id, payload })
}
return ( return (
<div className="flex flex-col gap-5"> <div className="flex flex-col gap-5">
@ -33,16 +44,25 @@ const Component = () => {
<div className="flex flex-col gap-1"> <div className="flex flex-col gap-1">
{data.changelogs.map((changelog) => { {data.changelogs.map((changelog) => {
return ( return (
<Link <div className="flex gap-3" key={changelog.id}>
className="hover:bg-muted py-1 px-2 rounded transition flex gap-2 items-center" <Link
to="/changelog/$id" className="hover:bg-muted py-1 px-2 rounded transition flex gap-2 items-center w-full"
params={{ to="/changelog/$id"
id: changelog.id, params={{
}} id: changelog.id,
key={changelog.id} }}
> >
{changelog.title} {changelog.title}
</Link> </Link>
<Button
size={'icon'}
variant={'destructive'}
onClick={() => removeChangelog(changelog.id)}
>
<CircleMinusIcon className="w-4 h-4" />
</Button>
</div>
) )
})} })}
</div> </div>

View File

@ -1,6 +1,6 @@
{ {
"name": "@boring.tools/logger", "name": "@boring.tools/logger",
"module": "src/index.ts", "main": "./src/index.ts",
"type": "module", "type": "module",
"devDependencies": { "devDependencies": {
"@types/bun": "latest" "@types/bun": "latest"

View File

@ -6,7 +6,7 @@ export const PageOutput = z
example: '', example: '',
}), }),
title: z.string(), title: z.string(),
description: z.string(), description: z.string().optional(),
icon: z.string(), icon: z.string(),
}) })
.openapi('Page') .openapi('Page')

View File

@ -5,7 +5,7 @@ export const PageCreateInput = z
title: z.string().min(3).openapi({ title: z.string().min(3).openapi({
example: 'My page', example: 'My page',
}), }),
description: z.string().openapi({ description: z.string().optional().openapi({
example: '', example: '',
}), }),
icon: z.string().optional().openapi({ icon: z.string().optional().openapi({

View File

@ -3,7 +3,20 @@ import { PageOutput } from './base'
import { PageCreateInput } from './create' import { PageCreateInput } from './create'
export const PageUpdateOutput = PageOutput export const PageUpdateOutput = PageOutput
export const PageUpdateInput = PageCreateInput export const PageUpdateInput = z
.object({
title: z.string().min(3).optional().openapi({
example: 'My page',
}),
description: z.string().optional().openapi({
example: '',
}),
icon: z.string().optional().openapi({
example: 'base64...',
}),
changelogIds: z.array(z.string().uuid()).optional(),
})
.openapi('Page')
export const PageUpdateParams = z export const PageUpdateParams = z
.object({ .object({
id: z.string().uuid(), id: z.string().uuid(),