47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
"use client"
|
|
|
|
// Deleting a note, in two steps. The attached files are not deleted with the note (they are the
|
|
// project's); the confirmation says so.
|
|
|
|
import type { ProjectSlugs } from "@conusai-kit/ui"
|
|
import { useWrite } from "@conusai-kit/ui/data"
|
|
import { ConfirmDialog, usePageNavigation } from "@conusai-kit/ui/patterns"
|
|
import { Button } from "@conusai-kit/ui/primitives"
|
|
import type { ReactElement } from "react"
|
|
|
|
export interface DeleteNoteLabels {
|
|
readonly button: string
|
|
readonly confirm: string
|
|
readonly yes: string
|
|
readonly no: string
|
|
}
|
|
|
|
export function DeleteNote({
|
|
slugs,
|
|
noteId,
|
|
listHref,
|
|
labels,
|
|
}: {
|
|
slugs: ProjectSlugs
|
|
noteId: string
|
|
/** Where to go once the note is gone. */
|
|
listHref: string
|
|
labels: DeleteNoteLabels
|
|
}): ReactElement {
|
|
const navigation = usePageNavigation()
|
|
const deletion = useWrite<Record<string, unknown>, unknown>("notes.note.delete", { org: slugs.org })
|
|
return (
|
|
<ConfirmDialog
|
|
trigger={<Button variant="outline">{labels.button}</Button>}
|
|
title={labels.button}
|
|
description={labels.confirm}
|
|
confirmLabel={labels.yes}
|
|
cancelLabel={labels.no}
|
|
onConfirm={async () => {
|
|
await deletion.mutate({ ...slugs, noteId })
|
|
navigation.navigate(listHref)
|
|
}}
|
|
/>
|
|
)
|
|
}
|