-
Notifications
You must be signed in to change notification settings - Fork 4
fix: sponsor forms crud validation #766
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
Conversation
📝 WalkthroughWalkthroughA single validation requirement is added to the FormTemplateForm schema, making the "instructions" field mandatory. This enhances validation by ensuring the field must be provided during form submission. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@src/pages/sponsors/sponsor-forms-list-page/components/form-template/form-template-form.js`:
- Around line 52-55: The instructions field in the validationSchema currently
uses requiredStringValidation(), which accepts Jodit HTML like "<p><br></p>" as
non-empty; import the normalizeJoditEmpty utility and replace/apply it to the
instructions rule by adding a Yup test that runs normalizeJoditEmpty(value) and
ensures it returns a non-empty string (i.e., use the test to call
normalizeJoditEmpty and fail when it yields an empty string) while keeping other
validators (e.g., requiredStringValidation) as needed so validationSchema ->
instructions uses normalizeJoditEmpty to normalize Jodit content before
checking.
| validationSchema: yup.object({ | ||
| code: requiredStringValidation(), | ||
| instructions: requiredStringValidation(), | ||
| opens_at: opensAtValidation(), |
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.
🧩 Analysis chain
🏁 Script executed:
# First, let's locate the file and examine the context
cat -n src/pages/sponsors/sponsor-forms-list-page/components/form-template/form-template-form.js | head -60Repository: fntechgit/summit-admin
Length of output: 2445
🏁 Script executed:
# Find FormikTextEditor implementation
rg -n "FormikTextEditor" -A 5 -B 2Repository: fntechgit/summit-admin
Length of output: 15367
🏁 Script executed:
# Check requiredStringValidation implementation
cat -n src/utils/yup.jsRepository: fntechgit/summit-admin
Length of output: 6358
🏁 Script executed:
# Search for any rich-text or HTML validation patterns
rg -n "stripHtml|richText|required.*html|strip.*markup|empty.*html" -iRepository: fntechgit/summit-admin
Length of output: 208
🏁 Script executed:
# Check FormikTextEditor export and imports
rg -n "export.*FormikTextEditor|import.*FormikTextEditor" -A 3 -B 1Repository: fntechgit/summit-admin
Length of output: 4945
🏁 Script executed:
# Check FormikTextEditor full implementation
cat -n src/components/inputs/formik-text-editor.jsRepository: fntechgit/summit-admin
Length of output: 849
🏁 Script executed:
# Find and examine normalizeJoditEmpty
fd -n "normalizeJoditEmpty" -t fRepository: fntechgit/summit-admin
Length of output: 296
🏁 Script executed:
# Check for TextEditorV3 implementation
rg -n "export.*TextEditorV3|import.*TextEditorV3" -A 5Repository: fntechgit/summit-admin
Length of output: 12151
🏁 Script executed:
# Search for any field normalization or preprocessing in the form
rg -n "normalize|transform|setFieldValue|onChange" src/pages/sponsors/sponsor-forms-list-page/components/form-template/form-template-form.jsRepository: fntechgit/summit-admin
Length of output: 253
🏁 Script executed:
# Find normalizeJoditEmpty files and implementation
find . -type f -name "*normalizeJoditEmpty*"Repository: fntechgit/summit-admin
Length of output: 186
🏁 Script executed:
# Search for normalizeJoditEmpty in the entire codebase
rg "normalizeJoditEmpty" -A 5 -B 2Repository: fntechgit/summit-admin
Length of output: 2060
🏁 Script executed:
# Check if there's any validation or normalization of TextEditorV3 output
rg -n "trim|replace|normalize|stripHtml" src/components/inputs/formik-text-editor.jsRepository: fntechgit/summit-admin
Length of output: 48
🏁 Script executed:
# Check validation schema in other similar forms for comparison
rg -n "instructions.*validation|description.*validation" -B 2 -A 2Repository: fntechgit/summit-admin
Length of output: 1357
🏁 Script executed:
# Check if normalizeJoditEmpty is imported or used anywhere in the codebase
rg "import.*normalizeJoditEmpty|normalizeJoditEmpty" --type jsRepository: fntechgit/summit-admin
Length of output: 729
🏁 Script executed:
# See the full test file to understand expected behavior
cat -n src/components/inputs/utils/__tests__/normalizeJoditEmpty.test.jsRepository: fntechgit/summit-admin
Length of output: 708
🏁 Script executed:
# Check if there are other examples of using normalizeJoditEmpty
rg "normalizeJoditEmpty" -lRepository: fntechgit/summit-admin
Length of output: 182
Apply existing normalizeJoditEmpty utility to validate rich-text fields.
The instructions field uses requiredStringValidation() which only checks for non-empty strings. Rich-text editors like Jodit emit HTML markup for "empty" content (e.g., <p><br></p>), which passes validation despite being visually empty. The codebase already has a normalizeJoditEmpty utility that correctly strips HTML tags and converts empty markup to empty strings. Integrate it into the validation schema:
Recommended approach
Import normalizeJoditEmpty from src/components/inputs/utils/normalizeJoditEmpty.js and apply it as a Yup test:
+import normalizeJoditEmpty from "../../../../../components/inputs/utils/normalizeJoditEmpty";
validationSchema: yup.object({
code: requiredStringValidation(),
- instructions: requiredStringValidation(),
+ instructions: requiredStringValidation().test(
+ "noEmptyMarkup",
+ T.translate("validation.required"),
+ (value) => normalizeJoditEmpty(value).length > 0
+ ),
opens_at: opensAtValidation(),📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| validationSchema: yup.object({ | |
| code: requiredStringValidation(), | |
| instructions: requiredStringValidation(), | |
| opens_at: opensAtValidation(), | |
| import normalizeJoditEmpty from "../../../../../components/inputs/utils/normalizeJoditEmpty"; | |
| validationSchema: yup.object({ | |
| code: requiredStringValidation(), | |
| instructions: requiredStringValidation().test( | |
| "noEmptyMarkup", | |
| T.translate("validation.required"), | |
| (value) => normalizeJoditEmpty(value).length > 0 | |
| ), | |
| opens_at: opensAtValidation(), |
🤖 Prompt for AI Agents
In
`@src/pages/sponsors/sponsor-forms-list-page/components/form-template/form-template-form.js`
around lines 52 - 55, The instructions field in the validationSchema currently
uses requiredStringValidation(), which accepts Jodit HTML like "<p><br></p>" as
non-empty; import the normalizeJoditEmpty utility and replace/apply it to the
instructions rule by adding a Yup test that runs normalizeJoditEmpty(value) and
ensures it returns a non-empty string (i.e., use the test to call
normalizeJoditEmpty and fail when it yields an empty string) while keeping other
validators (e.g., requiredStringValidation) as needed so validationSchema ->
instructions uses normalizeJoditEmpty to normalize Jodit content before
checking.
smarcet
left a comment
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.
LGTM
https://app.clickup.com/t/86b8b14h1
Summary by CodeRabbit
Release Notes
✏️ Tip: You can customize this high-level summary in your review settings.
related to #738