Skip to content

Add form deletion with confirmation and clean up form settings layout - #428

Merged
bcw117 merged 1 commit into
mainfrom
bcw117/add-form-removal
Sep 23, 2026
Merged

bcw117 merged 1 commit into
mainfrom
bcw117/add-form-removal

Conversation

@bcw117

@bcw117 bcw117 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

Features and Changes

Admins can now delete a form from its Settings tab.
Because a form can hold applicant data, deletion needs extra confirmation when the form has responses.
The Settings tab layout was also cleaned up, since its sections used mismatched widths, spacing, and header styles.

Form deletion flow

  • A new "Danger zone" section at the bottom of Settings has a "Delete form" button that opens a dialog (deleteFormSection.tsx).
  • Step 1 asks "Are you sure you want to delete this form?".
    On confirm, the submission count is fetched from the server, so the check never relies on stale client state.
  • If the form has no submissions, it is deleted right away.
  • If it has submissions, step 2 shows a red warning with the number of responses and says that every response, application, and status history entry will be erased.
    The same screen has a text box, and "Delete form permanently" (and Enter) stays disabled until delete form is typed.
  • After deleting, a toast confirms it and the page redirects to the forms list with router.replace, so Back does not return to the deleted form.

Server actions (src/app/portal/admin/actions.ts)

  • getFormSubmissionCount(id): admin-only count of all submissions for the form, including pending ones.
  • deleteForm(id, confirmation?): admin-only.
    It counts submissions again on the server and refuses to delete a form that has any unless confirmation matches delete form, so the typed check cannot be skipped by calling the action directly.
  • The delete is a single db.forms.delete.
    Submissions, applications, and application_status_history rows are removed by the existing ON DELETE CASCADE foreign keys.
  • revalidatePath("/portal/admin", "layout") clears the router cache so the forms list does not show the deleted form.
  • The DELETE_FORM_CONFIRMATION constant lives in src/lib/utils/forms/helpers.ts, because a "use server" file may only export async functions.

Settings layout

  • The page is one centered max-w-4xl column with even spacing between sections.
    It replaces a mix of full-width and narrow blocks, stacked px-4 padding, and sticky headers with no background.
  • A new SettingsSection component gives every section the same heading, description, optional action button, and divider.
    Its styling follows the redesigned forms list (font-heading, text-neutral-400, border-background-500).
  • Email templates:
    • "New template" moved into the section header and hides while the new-template form is open.
    • The 100-emails-per-day limit is now in the section description, and the template tag list stays in a collapsible panel.
    • Field labels are consistent, "Template fields used" shows "None" when empty, and forms with no templates show an empty-state message.
  • Status portal preview: the "What are these previews?" panel became a section description, the status picker and email search share one row on desktop, and an empty-state message shows when the form has no statuses.

Bug fixes found along the way

  • Clicking "Preview" on one email template opened a preview dialog for every expanded template, stacked on top of each other.
    Preview state now tracks which template was clicked.
  • In the status portal preview, "Clear" ran the search again instead of clearing.
    It now clears both the selected applicant and the search box.

Screenshots / Screen Recordings

None yet.
This PR changes the UI, so screenshots of the new Settings layout and both delete dialogs should be added before review.

Testing your changes

  • npx eslint on the settings folder and actions.ts: no errors.
  • npx prettier --check on the changed files: passes.
  • npx tsc --noEmit: no errors in the new files.
    The settings files have the same type errors (implicit any, unknown template configs) before and after this change, confirmed by comparing error lists with main.
    next.config.mjs sets ignoreBuildErrors: true.
  • The app was not run, and the UI and delete flow were not checked in a browser.

Steps on how to test your changes

  1. Log in as an admin and create a throwaway form with no submissions.
  2. Open its Settings tab, click "Delete form", and confirm.
    It should be deleted after one confirmation and you should land on the forms list without it.
  3. Create or clone another throwaway form and submit at least one response to it.
  4. Click "Delete form" and confirm step 1.
    The warning should show the correct response count.
  5. Check that "Delete form permanently" stays disabled until delete form is typed, then delete.
    The form and its submissions should be gone, and Back should not return to the deleted form.
  6. Check that Cancel or closing the dialog at any step resets it back to step 1.
  7. Look over the rest of the Settings tab: expand multiple email templates, click Preview on one (only one dialog should open), and try Search then Clear in the status portal preview.

Other Notes

  • Deletion is permanent, with no soft delete or undo.
    If recovery is ever needed, a soft-delete flag would be a follow-up.
  • The count used for the warning includes pending (in-progress) submissions, since those are still applicant data.

@netlify

netlify Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for ubclaunchpad ready!

Name Link
🔨 Latest commit c038e3f
🔍 Latest deploy log https://app.netlify.com/projects/ubclaunchpad/deploys/6ab20067134633000880a23f
😎 Deploy Preview https://deploy-preview-428--ubclaunchpad.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@vercel

vercel Bot commented Sep 22, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
lp-website Ignored Ignored Sep 22, 2026 4:13am UTC

@bcw117 bcw117 self-assigned this Sep 22, 2026
@bcw117
bcw117 requested a balanced review from Copilot September 22, 2026 23:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bcw117

bcw117 commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@bcw117
bcw117 merged commit 0b28fde into main Sep 23, 2026
8 checks passed
@bcw117
bcw117 deleted the bcw117/add-form-removal branch September 23, 2026 00:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants