Replace Chakra/Formik with antd Form in user management#7843
Replace Chakra/Formik with antd Form in user management#7843gilluminate merged 11 commits intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
e355ad4 to
4b99954
Compare
There was a problem hiding this comment.
Code Review: antd migration for user management forms
This is a solid, well-scoped migration. The Formik/Chakra removal is consistent across all the targeted forms, the shared passwordRules constant eliminates the duplication that existed in login.tsx, and the loading-state fix in AssignSystemsModal (emptySystems now guards against the loading phase) is a genuine improvement that wasn't there before.
Issues to address
Medium
UserForm.tsx—form.isFieldsTouched()(no argument) enables the Save button after touching any single field, whileDeleteUserModalandNewPasswordModalboth useisFieldsTouched(true). ThegetFieldsError()guard won't cover untouched required fields, so a user could see the Save button enabled while Email Address is still empty. Should align with the pattern used in the other modals.PermissionsForm.tsx—Form.useWatch("roles", form)returnsundefinedon the first render (before theForm.Itemchild registers the field), causingisEqual(undefined, [])to befalseand the Save button to flash as enabled. Fix:const currentRoles = Form.useWatch("roles", form) ?? initialValues.roles.UpdatePasswordModal.tsx— Not migrated to antdForm. It still uses rawuseState/onChangeand a booleanchangePasswordValidationcheck, unlike every other modal in this PR. The old Formik version had password confirmation cross-field validation; this version lost it. Needs a comment explaining why it was left out, or should be brought in line withNewPasswordModal.
Low / Nice to have
PermissionsForm.tsx— The hidden<Input />used to register therolesarray field in the form store is unconventional. It works today, but a programmatic-only field storing an array through a stringInputis fragile. Worth noting for follow-up or replacing with a cleaner approach.RoleOption.tsx—aria-selected="true"on aCard(<div>) has no semantic meaning for assistive technology.aria-pressedoraria-checkedwould be correct for a selection affordance, or the attribute can be dropped sincedata-testid="selected"already covers the test targeting.
What's done well
- Shared
passwordRulesconstant with proper reuse inUserForm,NewPasswordModal, andlogin.tsx - Consistent
Form+Form.Item+dependenciespattern for password confirmation inNewPasswordModal isLoadingpropagation toAssignSystemsTableand theemptySystemsguard fixForm.useWatch([], form)used to trigger re-renders for the disabled-button check — this is the correct antd v5 patternuseChakraDisclosurereplaced with plainuseStatebooleans throughout — cleaner and removes the Chakra dependency
| @@ -216,7 +195,7 @@ const useLogin = () => { | |||
| handleSubmit, | |||
There was a problem hiding this comment.
Good refactor — the local inline rules duplication has been eliminated by importing the shared passwordRules. The rename to loginPasswordRules cleanly avoids the naming conflict with the import. 👍
Migrate all user management forms from Formik + Yup + Chakra UI to antd Form with inline validation rules. Replace all Chakra layout components with antd equivalents and Tailwind CSS. - UserForm: antd Form with Form.useWatch for reactive fields - PermissionsForm + RoleOption: migrate coupled Formik context to antd Form instance passed as prop - NewPasswordModal: antd Form with Input.Password and confirmation matching via dependencies - UpdatePasswordModal: replace Chakra inputs with antd Input.Password - DeleteUserModal: antd Form with Alert and custom username validator - PasswordManagement, RoleDescriptionDrawer: Chakra layout to antd Flex - AssignSystemsModal: Chakra layout to antd Flex + Typography - AssignSystemsTable: Chakra Table to antd Table with columns/dataSource Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
lucanovera
left a comment
There was a problem hiding this comment.
User managements work as expected, code changes & ui look good. Approved!
- Fix unsafe `as FormValues` cast: change onSubmit prop to accept UserCreateExtended, update callers in NewUserForm and EditUserForm - Add validation error check to UserForm Save button (was only checking dirty state, not validity) - Add missing loading state to PermissionsForm Save button - Remove dead `xs:` Tailwind breakpoint class from UserForm - Restore data-testid on table rows in AssignSystemsTable via onRow - Use `color` prop for Carbon icon in RoleOption per conventions - Restore JSDoc on PermissionsForm explaining legacy non-RBAC role - Extract shared passwordRules to common/form/validation.ts, used by UserForm, NewPasswordModal, and login page Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Restore data-testid values to match what Cypress selectors expect: - input-email_address, input-first_name, input-last_name (underscores matching field names, not hyphens) - input-password_login_enabled on Switch (was toggle-allow-password-login) - input-usernameConfirmation on DeleteUserModal Input - input-password and input-passwordConfirmation on NewPasswordModal inputs - Update Cypress error selector to use antd's .ant-form-item-explain-error class (replaces Formik's FormErrorMessage data-testid) The 7 remaining test failures (Permission assignment tests looking for "Permissions" tab) are pre-existing on main -- the RBAC flag now defaults enabled, rendering "Roles" instead. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a reusable command for querying antd Form.Item validation errors by field name. Uses antd's generated #fieldName_help container. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Default useWatch("roles") to initialValues.roles to prevent Save button flash on first render
- Remove semantically incorrect aria-selected from RoleOption Card
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
569b269 to
0b8e556
Compare
Ticket ENG-3168
Description Of Changes
Full migration of user management forms from Formik + Yup + Chakra UI to antd Form with inline validation rules. Replaces all Chakra layout/display components with antd equivalents and Tailwind CSS. Keeps existing form behavior and validation logic intact.
Key changes:
Form.useForm(),Form.useWatch(),onFinish,Form.Itemwithrulesarrays replace Formik's render props, Yup schemas, andCustomTextInput/CustomSwitchwrappersBox/Flex/Stack/HStack/VStack→ antdFlex,Card,Typography, and Tailwind layout classesAssignSystemsTableusescolumns/dataSourcepattern withonRowfor row test IDsuseChakraDisclosure→useState<boolean>for all modal open/close statepasswordRules: extracted tocommon/form/validation.ts, consumed byUserForm,NewPasswordModal, andlogin.tsx(replaces 3 duplicate definitions)cy.getAntFormError(fieldName)inant-support.tsfor querying antd Form.Item validation errorsAlso fixes
UserFormProps.onSubmittype signature to acceptUserCreateExtended(the actual payload shape) instead of using an unsafeascast.Code Changes
UserForm.tsx— Formik/Yup/Chakra → antd Form withForm.useWatchfor reactive password toggle, inline validation rules,Form.Item+Input/SwitchPermissionsForm.tsx— Formik → antd Form withuseEffectforenableReinitialize, added missing loading state on Save buttonRoleOption.tsx—useFormikContext→formprop (FormInstance), ChakraStack→ antdCard/FlexNewPasswordModal.tsx— Formik/Yup → antd Form withInput.Passwordanddependenciesfor confirmation matchingUpdatePasswordModal.tsx— ChakraInput/FormControl/Stack→ antdInput.Password/FlexDeleteUserModal.tsx— Formik/Yup/Chakra Alert → antd Form/Input/Alert with custom username validatorPasswordManagement.tsx— ChakraBox/HStack→ antdFlexRoleDescriptionDrawer.tsx— ChakraBox/VStack→ antdCard/Flex/TypographyAssignSystemsModal.tsx— Chakra layout → antdFlex/TypographyAssignSystemsTable.tsx— Chakra Table → antdTablewith columns/dataSource, restored rowdata-testidviaonRowEditUserForm.tsx/NewUserForm.tsx— UpdatedonSubmittype toUserCreateExtendedcommon/form/validation.ts— Added sharedpasswordRulesantd rules arraypages/login.tsx— Uses sharedpasswordRulesinstead of inline duplicatecypress/support/ant-support.ts— AddedgetAntFormErrorcommandcypress/e2e/user-management.cy.ts— Updated error selector to usegetAntFormErrorSteps to Confirm
/user-managementand verify the user table rendersPre-Merge Checklist
CHANGELOG.mdupdated