Tenant improvements on addition and ability to delete#997
Tenant improvements on addition and ability to delete#997
Conversation
|
Preview deployment: https://tenant-improvements.preview.avy-fx.org |
| @@ -0,0 +1,51 @@ | |||
| import type { CollectionBeforeDeleteHook } from 'payload' | |||
|
|
|||
| export const TENANT_SCOPED_COLLECTIONS = [ | |||
There was a problem hiding this comment.
[17:30:01] ERROR (payload): Failed query: delete from "tenants" where "tenants"."id" = ?
params: 2
err: {
"type": "DrizzleQueryError",
"message": "Failed query: delete from "tenants" where "tenants"."id" = ?\nparams: 2: SQLITE_CONSTRAINT_NOTNULL: NOT NULL constraint failed: forms.tenant_id: NOT NULL constraint failed: forms.tenant_id",
There was a problem hiding this comment.
how did you get this error?
There was a problem hiding this comment.
Oh jeez I thought I'd included context here - that's terrible haha.
What I thought I'd written was:
I believe you need to add the forms collection to this list because you get this NOT NULL constraint failed on the form that gets created in our seed data. https://www.loom.com/share/5b53172aed9048ec83b367fcd4412266
There was a problem hiding this comment.
I just pushed that change since it was super quick. 0027fa7
Tenant improvements on addition and ability to delete
Description
While working on onboarding tickets, I though of some improvements we can make for the tenant (avalanche center) creation and deletion (which was broken) experience in the admin UI.
Related Issues
Fixes #976
Key Changes
Slug field: only show unused slugs on creation
TenantSlugFieldcomponent that fetches existing tenants and filters out already-used slugs when creating a new tenant. We can't use Payload's built-infilterOptionshere because it only works onrelationshipfields, notselectfields — the slug is aselectwith a static list of valid avalanche center identifiers, so filtering must happen client-side.Auto-fill name from slug
AutoFillNameFromSlugcomponent syncs the name field to the full avalanche center name when a slug is selected during creation.Delete confirmation with type-to-confirm
DeleteTenantModalcomponent intercepts Payload's default delete modal and replaces it with a custom one that requires typing the tenant name to confirm. This uses Payload'sModaldirectly rather thanConfirmationModalbecause the latter doesn't support controlling button state based on user input.Deprovision hook
beforeDeletehook (deprovisionBeforeDelete) deletes all tenant-scoped data before the tenant record itself is removed, preventing orphaned data and SQLite foreign key constraint errors. This runs regardless of how deletion is triggered (admin UI, API, etc.).How to test
Create a new tenant:
- Above name field now
- The slug dropdown should only show slugs not already in use.
- Edit an existing tenant — all slugs should be visible (field is read-only).
Screenshots / Demo video
https://www.loom.com/share/af64206841684c02ae1c75c44e546ae9
Migration Explanation
No migration needed — no schema changes.
Future enhancements / Questions
How do we feel about the custom slug field?