Site form requires fields the API and DB do not #628
Replies: 2 comments
-
|
Green light — PR welcome. The form is over-validating and the use cases you listed (cloud-only sites, remote employee home offices, day-one onboarding) are all real. Couple of small preferences on the relaxed schema:
Worth a small note in the modal's empty state ("Address and contact are optional — you can fill these in later") so users don't think the form is broken. |
Beta Was this translation helpful? Give feedback.
-
|
Shipped in #708 (merged |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What I noticed
The "Add Site" / "Edit Site" modal validates ten fields as required client-side:
But the rest of the stack only requires
namefrom the user. The DB hasnameandtimezoneasNOT NULL, buttimezonehas a server-side default of'UTC'. The API zod requiresorgIdandname, butorgIdis set by the parent component from the selected org, not by user input. Net effect: from the form-user's perspective, onlynameis actually needed.Database (
apps/api/src/db/schema/orgs.ts):API zod (
apps/api/src/routes/orgs.ts):So the API accepts
{ orgId, name }and the DB happily stores it (timezone defaults to UTC server-side). The form is the only layer that demands the rest.Why this matters
This bites at the site layer specifically — not the organization layer. Organizations usually have an address you can put on a contract; sites underneath them often don't.
contactPhone: z.string().min(7, ...)floor isn't really a phone-format check — it just refuses any empty value. Plenty of sites have no phone contact and the form should let them say so.The form essentially refuses to create a site for any of those cases, even though the rest of the system has no problem with it.
Proposed change
Relax the frontend
siteSchemainapps/web/src/components/settings/SiteForm.tsxso it only enforces what the API actually requires:Two-line behavior change:
Default on the timezone field stays
'UTC'so users don't have to change it; the API's.default('UTC')makes that even safer.Happy to open a PR if there's interest. Tiny diff, no API or DB change required.
Beta Was this translation helpful? Give feedback.
All reactions