feat: add useEmployeeDetailsForm hook with configurable required fields#1365
Merged
serikjensen merged 4 commits intomainfrom Mar 25, 2026
Merged
feat: add useEmployeeDetailsForm hook with configurable required fields#1365serikjensen merged 4 commits intomainfrom
serikjensen merged 4 commits intomainfrom
Conversation
Implement useEmployeeDetailsForm hook and EmployeeDetailsForm component with schema-driven field metadata and configurable required fields per create/update mode. - Add requiredIf utility and composeFormSchema for conditional field requirements derived from a single fieldValidators source of truth - Update deriveFieldsMetadata to use z.toJSONSchema() for accurate isRequired detection, including requiredIf fields - Add hasSsn schema option to skip SSN requirement when already on file - Refactor compensationSchema to use z.preprocess for toJSONSchema compatibility (stateWcCovered, rate, startDate) and derive types from fieldValidators - Add SwitchHookField, DatePickerField string mode, hasRedactedValue metadata, and employee mock API handlers Made-with: Cursor
- Revert react-dom peerDependency back to "^18.0.0 || ^19.0.0" to support partners on React 18 - Make composeFormSchema generic over fieldValidators type so zodResolver infers the correct form data type without per-hook casts - Remove manual Resolver cast from useEmployeeDetailsForm Made-with: Cursor
Made-with: Cursor
jeffredodd
approved these changes
Mar 25, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds the
useEmployeeDetailsFormhook andEmployeeDetailsFormcomponent with a schema-driven approach to configurable required fields. Partners can specify which fields are required per mode viarequiredFields: { create: ['email'], update: ['ssn'] }, with the schema as the single source of truth for both validation and UI metadata (isRequiredindicators).Key changes
requiredIfutility (src/helpers/requiredIf.ts) — conditionally makes a Zod validator optional usingz.preprocess, compatible withz.toJSONSchema()composeFormSchemautility — reusable schema builder that takesfieldValidators, applies mode-specific API defaults (requiredOnCreate), and partnerrequiredFieldsoverrides viarequiredIfderiveFieldsMetadata— updated to usez.toJSONSchema()for accurateisRequireddetection, making the schema the single source of truth for UI metadatauseEmployeeDetailsFormhook — full create/update lifecycle with self-onboarding toggle, SSN redaction (hasRedactedValuemetadata), andhasSsnschema option to skip SSN requirement when already on fileEmployeeDetailsFormcomponent — reference implementation consuming the hookstateWcCovered,rate, andstartDatefromz.transform/z.date()/z.nan()toz.preprocess/z.iso.date()fortoJSONSchemacompatibility, with types derived from a singlefieldValidatorsobject (same pattern as employee details)DatePickerFieldstring mode — accepts and returns ISO date strings (YYYY-MM-DD) in addition toDateobjectsSwitchHookField— new hook-connected field component for boolean togglesSchema pattern established
All form schemas follow a consistent pattern:
fieldValidatorsobjectFormDatatype fromfieldValidatorsvia mapped typecomposeFormSchema(for configurable fields) or spread + preprocess overrides (for type coercion)superRefineonly for cross-field validations that depend on runtime form valueshasSsn) for static prop-based exceptions resolved at construction timeTest plan
deriveFieldsMetadatawithrequiredIfscenarios (6 new test cases)useEmployeeDetailsFormhook (create, update, validation, self-onboarding, SSN handling — 12 test cases)hasSsnis trueScreen.Recording.2026-03-24.at.11.52.08.PM.mov
Made with Cursor