-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: create stablecoin form validation triggered on opening the form #523
fix: create stablecoin form validation triggered on opening the form #523
Conversation
ENG-2229 Fix create stablecoin form
CleanShot 2025-01-16 at 18.03.482x.png
|
Reviewer's Guide by SourceryThis pull request addresses an issue where form validation was triggered on form opening, leading to errors before any user interaction. The solution involves removing the manual trigger of form validation and implementing a Zod schema validation to determine the validity of the form step. Sequence diagram: Form validation flow before and after changessequenceDiagram
participant U as User
participant F as Form Component
participant V as Validation
rect rgb(240, 240, 240)
Note over U,V: Before Changes
F->>V: Trigger validation on mount
V-->>F: Return validation errors
F->>U: Show validation errors
end
rect rgb(200, 255, 200)
Note over U,V: After Changes
F->>F: Mount component
U->>F: Input field value
F->>V: Validate with Zod schema
V-->>F: Return validation result
F->>U: Update UI based on validation
end
Class diagram: Form component structure changesclassDiagram
class FormStep {
+form: UseFormReturn
+fields: TName[]
+validatePage(fields, formValues)
+title: string
+withSheetClose: boolean
-getIsValidPage()
}
class CreateTokenSchema {
+tokenName: string
+tokenSymbol: string
+decimals: number
+isin: string?
+admin: string
+collateralProofValidity: number
+validateCreateTokenSchemaFields()
}
FormStep --> CreateTokenSchema: uses
State diagram: Form validation statesstateDiagram-v2
[*] --> FormMounted
FormMounted --> AwaitingInput
AwaitingInput --> Validating: User inputs data
Validating --> Valid: Zod schema validates
Validating --> Invalid: Zod schema fails
Valid --> NextStepEnabled
Invalid --> NextStepDisabled
NextStepEnabled --> [*]: User proceeds
NextStepDisabled --> AwaitingInput: User corrects input
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
@@ -152,7 +85,7 @@ export const FormStep = < | |||
<Button | |||
type="button" | |||
className={cn({ hidden: currentStep === totalSteps })} | |||
disabled={(!isValid && isNavigate) || (!isValidPage && !isNavigate)} | |||
disabled={!getIsValidPage()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pmualaba I removed the isNavigate
field because I couldn't find where it was used, please let me know if i need to add it back? and where it is used?
@@ -1,11 +1,10 @@ | |||
'use client'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was getting Props must be serializable for components in the "use client" entry file...
Removed the 'use client' here because we use this component in a client component, related issue: vercel/next.js#46795
…-stablecoin-panel
On opening the form, the validation was getting triggered and I was getting errors without having touched any fields. We were manually triggering the form validation when the component was rendered. Now:
Something like
isFieldValid = !field.invalid && field.isDirty
works when a default value is not provided, but when a default value is providedisDirty
isfalse
soisFieldValid
is alwaysfalse
even though there is a valid value. So using the zod schema covers all the cases hereSummary by Sourcery
Remove manual form validation and use Zod schema validation to determine if a form step is valid.
Bug Fixes:
Enhancements: