-
Notifications
You must be signed in to change notification settings - Fork 0
feat(ui): delete affordance for every primary entity #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
0c3eeab
feat(ui): add shared DeleteConfirmDialog component
Timmyy3000 35c0fdb
feat(signals): UI delete for signals with audit
Timmyy3000 46496fc
feat(notes): UI delete for notes with audit
Timmyy3000 5cc43f1
feat(tasks): UI delete for tasks with audit
Timmyy3000 73e3186
feat(meetings): UI delete for meetings with audit
Timmyy3000 8ce8089
feat(deals): UI delete for deals with audit
Timmyy3000 3faeafe
feat(people): UI delete for people with cascade preview and audit
Timmyy3000 3cbfdd9
feat(companies): UI delete for companies with cascade preview and audit
Timmyy3000 5ed7ea1
feat(companies): wire DeletePersonButton into the people tab
Timmyy3000 acfd233
fix(deletes): address four P2 findings from enkii
Timmyy3000 b4da303
fix(deletes): address second round of enkii P2 findings
Timmyy3000 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| "use client"; | ||
|
|
||
| import { Trash2 } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { DeleteConfirmDialog } from "@/components/delete-confirm-dialog"; | ||
| import { deleteNoteAction } from "./actions"; | ||
|
|
||
| export function DeleteNoteButton({ noteId }: { noteId: string }) { | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| return ( | ||
| <> | ||
| <button | ||
| type="button" | ||
| aria-label="Delete note" | ||
| onClick={() => setOpen(true)} | ||
| className="rounded p-1 text-text-subtle opacity-0 transition group-hover:opacity-100 hover:bg-surface-hover hover:text-destructive" | ||
| > | ||
| <Trash2 className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <DeleteConfirmDialog | ||
| open={open} | ||
| onOpenChange={setOpen} | ||
| title="Delete note?" | ||
| description="This note will be permanently deleted. This cannot be undone." | ||
| onConfirm={() => deleteNoteAction({ noteId })} | ||
| /> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| "use server"; | ||
|
|
||
| import { revalidatePath } from "next/cache"; | ||
| import { z } from "zod"; | ||
| import { db } from "@/db/client"; | ||
| import { recordAudit, userActor } from "@/lib/audit"; | ||
| import { requireOrgSession } from "@/lib/session"; | ||
| import { deleteSignal } from "@/lib/signals"; | ||
|
|
||
| export async function deleteSignalAction(input: { | ||
| signalId: string; | ||
| }): Promise<{ ok: true } | { ok: false; message: string }> { | ||
| const session = await requireOrgSession(); | ||
| const signalId = z.string().uuid().parse(input.signalId); | ||
|
|
||
| const result = await deleteSignal(db(), session.organizationId, signalId); | ||
| if (!result) return { ok: false, message: "Signal not found" }; | ||
|
|
||
| await recordAudit(db(), { | ||
| organizationId: session.organizationId, | ||
| actor: userActor(session.user.id, session.user.name ?? null), | ||
| entityType: "signal", | ||
| entityId: signalId, | ||
| action: "delete", | ||
| changes: { before: result.before }, | ||
| }); | ||
|
|
||
| revalidatePath(`/companies/${result.before.companyId}/signals`); | ||
| revalidatePath(`/companies/${result.before.companyId}`); | ||
| revalidatePath("/companies"); | ||
| return { ok: true }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| "use client"; | ||
|
|
||
| import { Trash2 } from "lucide-react"; | ||
| import { useState } from "react"; | ||
| import { DeleteConfirmDialog } from "@/components/delete-confirm-dialog"; | ||
| import { deleteSignalAction } from "./actions"; | ||
|
|
||
| export function DeleteSignalButton({ | ||
| signalId, | ||
| signalTitle, | ||
| }: { | ||
| signalId: string; | ||
| signalTitle: string; | ||
| }) { | ||
| const [open, setOpen] = useState(false); | ||
|
|
||
| return ( | ||
| <> | ||
| <button | ||
| type="button" | ||
| aria-label="Delete signal" | ||
| onClick={() => setOpen(true)} | ||
| className="rounded p-1 text-text-subtle opacity-0 transition group-hover:opacity-100 hover:bg-surface-hover hover:text-destructive" | ||
| > | ||
| <Trash2 className="h-3.5 w-3.5" /> | ||
| </button> | ||
| <DeleteConfirmDialog | ||
| open={open} | ||
| onOpenChange={setOpen} | ||
| title="Delete signal?" | ||
| description={ | ||
| <> | ||
| “{signalTitle}” will be permanently deleted. This cannot be undone. | ||
| </> | ||
| } | ||
| onConfirm={() => deleteSignalAction({ signalId })} | ||
| /> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| "use server"; | ||
|
|
||
| import { revalidatePath } from "next/cache"; | ||
| import { z } from "zod"; | ||
| import { db } from "@/db/client"; | ||
| import { recordAudit, userActor, type EntityType } from "@/lib/audit"; | ||
| import { | ||
| deleteCompany, | ||
| previewCompanyDelete, | ||
| type CompanyCascadeCounts, | ||
| } from "@/lib/companies"; | ||
| import { requireOrgSession } from "@/lib/session"; | ||
|
|
||
| export async function previewCompanyDeleteAction(input: { | ||
| companyId: string; | ||
| }): Promise<{ ok: true; data: CompanyCascadeCounts } | { ok: false; message: string }> { | ||
| const session = await requireOrgSession(); | ||
| const companyId = z.string().uuid().parse(input.companyId); | ||
| const data = await previewCompanyDelete(db(), session.organizationId, companyId); | ||
| if (!data) return { ok: false, message: "Company not found" }; | ||
| return { ok: true, data }; | ||
| } | ||
|
|
||
| export async function deleteCompanyAction(input: { | ||
| companyId: string; | ||
| }): Promise<{ ok: true } | { ok: false; message: string }> { | ||
| const session = await requireOrgSession(); | ||
| const companyId = z.string().uuid().parse(input.companyId); | ||
|
|
||
| const result = await deleteCompany(db(), session.organizationId, companyId); | ||
| if (!result) return { ok: false, message: "Company not found" }; | ||
|
|
||
| const actor = userActor(session.user.id, session.user.name ?? null); | ||
| const beforeStub = { companyId }; | ||
| const fanouts: Array<{ entityType: EntityType; ids: string[] }> = [ | ||
| { entityType: "deal", ids: result.children.dealIds }, | ||
| { entityType: "signal", ids: result.children.signalIds }, | ||
| { entityType: "meeting", ids: result.children.meetingIds }, | ||
| { entityType: "note", ids: result.children.noteIds }, | ||
| { entityType: "task", ids: result.children.taskIds }, | ||
| ]; | ||
| for (const { entityType, ids } of fanouts) { | ||
| for (const id of ids) { | ||
| await recordAudit(db(), { | ||
| organizationId: session.organizationId, | ||
| actor, | ||
| entityType, | ||
| entityId: id, | ||
| action: "delete", | ||
| changes: { before: beforeStub }, | ||
| }); | ||
| } | ||
| } | ||
| await recordAudit(db(), { | ||
| organizationId: session.organizationId, | ||
| actor, | ||
| entityType: "company", | ||
| entityId: companyId, | ||
| action: "delete", | ||
| changes: { before: result.before }, | ||
| }); | ||
|
|
||
| revalidatePath("/companies"); | ||
| revalidatePath("/deals"); | ||
| revalidatePath("/meetings"); | ||
| revalidatePath("/tasks"); | ||
| revalidatePath("/people"); | ||
| revalidatePath("/"); | ||
| return { ok: true }; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revalidatePathfor deleted company's detail pagedeleteCompanyActioncallsrevalidatePath("/companies")which in Next.js App Router defaults to page-level revalidation and only invalidates the/companieslist page — it does not clear cached RSC payloads for child routes like/companies/${companyId}. After deletion, navigating to the deleted company's URL could serve a stale cached page. AddrevalidatePath(\/companies/${companyId}`)or pass'layout'as the second argument torevalidatePath("/companies", "layout")` to ensure the detail-page cache is purged.