Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions apps/frontend/src/app/components/ConfirmDeleteDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ interface ConfirmDeleteDialogProps {
* (a project's expenses, a donor's donations) — say so explicitly.
*/
consequences?: React.ReactNode;
prompt?: React.ReactNode;
irreversible?: boolean;
confirmLabel?: string;
pendingLabel?: string;
/**
* Gate the confirm button behind retyping `itemName`. For deletes that
* reach into financial history, where a misclick is costly to undo.
Expand All @@ -40,7 +43,10 @@ export default function ConfirmDeleteDialog({
title,
itemName,
consequences,
prompt,
irreversible = true,
confirmLabel = 'Delete',
pendingLabel = 'Deleting…',
requireTypedConfirmation = false,
}: ConfirmDeleteDialogProps) {
const [deleting, setDeleting] = useState(false);
Expand Down Expand Up @@ -114,22 +120,24 @@ export default function ConfirmDeleteDialog({
<Dialog.Body paddingX="24px" paddingTop="24px" paddingBottom="24px">
<div className="flex flex-col !gap-4">
<p className="!text-base">
{itemName ? (
{prompt ?? (itemName ? (
<>
Delete <span className="!font-bold">{itemName}</span>?
</>
) : (
'Are you sure you want to delete this?'
)}
))}
</p>

{consequences && (
<div className="!text-sm !text-black-700">{consequences}</div>
)}

<p className="!text-sm !text-black-700">
This cannot be undone.
</p>
{irreversible && (
<p className="!text-sm !text-black-700">
This cannot be undone.
</p>
)}

{requireTypedConfirmation && itemName && (
<TextInputField
Expand Down Expand Up @@ -159,7 +167,7 @@ export default function ConfirmDeleteDialog({
onClick={handleConfirm}
disabled={confirmDisabled}
isLoading={deleting}
loadingText="Deleting…"
loadingText={pendingLabel}
>
{confirmLabel}
</Button>
Expand Down
14 changes: 12 additions & 2 deletions apps/frontend/src/app/staff/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,21 @@ export default function StaffConsolePage() {
confirmFull ? switchInto(confirmFull, 'full') : undefined
}
title="Act as this user with full access?"
itemName={
confirmFull ? `${confirmFull.name} (${confirmFull.email})` : undefined
prompt={
confirmFull && (
<>
Switch into{' '}
<span className="!font-bold">
{`${confirmFull.name} (${confirmFull.email})`}
</span>{' '}
for one hour?
</>
)
}
consequences="Anything you create, edit, approve or delete is real and is saved as this user. Each change is also recorded against your staff account."
irreversible={false}
confirmLabel="Act as"
pendingLabel="Switching…"
/>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/test/components/StaffConsolePage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ describe('StaffConsolePage', () => {

expect(await screen.findByText('Act as this user with full access?')).toBeInTheDocument();
expect(screen.getByText('Sam Okafor (sam@branch.org)')).toBeInTheDocument();
expect(screen.queryByText(/delete sam okafor/i)).not.toBeInTheDocument();
expect(screen.queryByText('This cannot be undone.')).not.toBeInTheDocument();
// The dialog portals to the end of <body>, so its confirm is the last "Act as".
const confirm = screen.getAllByRole('button', { name: 'Act as' }).at(-1)!;
await userEvent.click(confirm);
Expand Down
Loading