Skip to content
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

Custom form fields #760

Merged
merged 10 commits into from
Nov 23, 2023
Merged

Custom form fields #760

merged 10 commits into from
Nov 23, 2023

Conversation

rishabhpoddar
Copy link
Contributor

@rishabhpoddar rishabhpoddar commented Nov 11, 2023

Summary of change

  • Exposes inputComponent type in the form fields input which allows users to add custom react components as form fields for the sign up form. Note that this is only exposed to the sign up form.
  • The functions passed to the inputComponent, like onChange, now just take the value. Whereas before, they used to take form id and value. This change is applied to other functions like onInputBlur etc as well.
  • Add a getDefaultValue function as an input to each formField as well. This allows users to pre fill the form field value. This is a function because it allows more flexibility, for example if the value must be read from localstorage, or query param based on some condition.
  • Adds another form field input called nonOptionalErrorMsg, which allows users to replace the default "Field is not optional" error with something else, on a per form field basis. For example, if a form field is a checkbox, then instead of showing "Field is not optional", we can show "Please check this before signing up"

Related issues

Test Plan

TODO

Documentation changes

TODO

Checklist for important updates

  • Changelog has been updated
  • frontendDriverInterfaceSupported.json file has been updated (if needed)
  • Changes to the version if needed
    • In package.json
    • In package-lock.json
    • In lib/ts/version.ts
  • Had run npm run build-pretty
  • Had installed and ran the pre-commit hook
  • Issue this PR against the latest non released version branch.
    • To know which one it is, run find the latest released tag (git tag) in the format vX.Y.Z, and then find the latest branch (git branch --all) whose X.Y is greater than the latest released tag.
    • If no such branch exists, then create one from the latest released branch.
  • If added a new recipe interface, then make sure that the implementation of it uses NON arrow functions only (like someFunc: function () {..}).
  • If I added a new recipe, I also added the recipe entry point into the size-limit section of package.json with the size limit set to the current size rounded up.
  • If I added a new recipe, I also added the recipe entry point into the rollup.config.mjs

amitbadala and others added 3 commits November 3, 2023 17:02
…ssword recipe (#752)

* Add inputComponent to exposed types

* Add inputComponent to normalised fields

* For testing only - use custom type definition for inputComponent

* Input component already present in  FormFieldThemeProps

* Testing if git package is getting installed correctly

* Run build for previous commits

* Remove inputComp from NormalizedFormField

* Add tests for custom fields

* Remove testing ele

* Move the custom fields tests into existing describe

* Update dropdown values to avoid confusion

* Add helper func to set dropdown, better test title, use existing describe hooks

* Use strict equal

* Update request

* A seperate func to fetch custom comp not required

* Move inputComponent to signup types

* Cleanup unwanted imports

* Move inputComponent to signup types

* Clean types

* Update build files

* Use explicit values in validate func

* Minor cleanup of types

* Better type names

* Props suggestions working for inputComponent

* Enforce strict string check on form values, now onChange function for fields only needs value, no need to supply name or id

* Update based on the new onChange func

* Ability to add default value with getDefaultValue prop

* Handle if getDefaultValue is not a function

* instead of form submit apply type test within onChange function itself

* Add tests for default value

* Remove unwanted abort

* Testing email-verification workflow

* Reverting onChange changes

* onChange function to accept only values

* Initialize fieldstates at the start

* Remove useEffect

* Fix race conditions when setting default value

* Add custom default fields to typescript example, plus add tests to show custom error message

* Add tests for incorrect default props in formFields

* Add tests for incorrect usage of onChange prop

* Add change log

* Wrap ternary opeators into seperate func for better readibility

* Wrap inputComponent in a serperate component to avoid unecessary rerenders

* Add change log feedbacks

* Better variable names, include formfields directly in typescript example

* Add more tests for default & onChange func, updated typescript file to show the latest changes

* Add more test, which intercepts request payload

* Cleanup comments

* Minor formatting

* Minor fix

* Clean up helper

* Update change log & versions
* Add getDefaultValue to signin, hence shuffle the existing types

* Add tests for default signin feature

* Add default feature to typescript

* Fix failed test

* Reset password now supports getDefaultValue

* Add tests for resetPassword email field

* Revert "Add tests for resetPassword email field"

This reverts commit 363b575.

* Revert "Reset password now supports getDefaultValue"

This reverts commit be4c00a.
* Add nonOptionalErr types

* Now supports nonOptionalErrorMsg attribute

* Add tests and fix signin types to include nonOptionalMsg

* Enforce no api request are made on blank forms

* Clean up signup

* Throw error if invalid nonOptionalErrorMsg, add tests for the same

* Better error message

* Handle incorrect optional flag

* fixes redundant normalisation

---------

Co-authored-by: rishabhpoddar <[email protected]>
Copy link

github-actions bot commented Nov 11, 2023

size-limit report 📦

Path Size
lib/build/index.js 14.19 KB (0%)
recipe/session/index.js 15.15 KB (0%)
recipe/session/prebuiltui.js 17.77 KB (0%)
recipe/thirdpartyemailpassword/index.js 29.71 KB (+0.19% 🔺)
recipe/thirdparty/index.js 26.43 KB (0%)
recipe/emailpassword/index.js 10.01 KB (+0.66% 🔺)
recipe/emailverification/index.js 7.26 KB (0%)
recipe/passwordless/index.js 63.47 KB (0%)
recipe/thirdpartypasswordless/index.js 84.2 KB (0%)
recipe/emailverification/prebuiltui.js 22.46 KB (0%)
recipe/thirdpartyemailpassword/prebuiltui.js 54.09 KB (+0.54% 🔺)
recipe/thirdparty/prebuiltui.js 38.51 KB (0%)
recipe/emailpassword/prebuiltui.js 27.82 KB (+1.1% 🔺)
recipe/passwordless/prebuiltui.js 103.03 KB (+0.24% 🔺)
recipe/thirdpartypasswordless/prebuiltui.js 130.65 KB (+0.19% 🔺)
recipe/multitenancy/index.js 6.12 KB (0%)

examples/for-tests/src/App.js Outdated Show resolved Hide resolved
examples/for-tests/src/App.js Outdated Show resolved Hide resolved
examples/for-tests/src/App.js Outdated Show resolved Hide resolved
lib/ts/recipe/emailpassword/utils.ts Show resolved Hide resolved
lib/ts/version.ts Outdated Show resolved Hide resolved
test/end-to-end/signin.test.js Show resolved Hide resolved
test/end-to-end/signin.test.js Outdated Show resolved Hide resolved
test/end-to-end/signin.test.js Outdated Show resolved Hide resolved
test/helpers.js Outdated Show resolved Hide resolved
… test structure (#762)

* Show required sign only if label is valid

* Better func names & consistent return type

* Use assert instead of throw error

* Consistent tests description

* Remove unecessary code

* Add correct version number

* Update changelog, add thirdparty example

* Minor fox

* Read from testContext

* Refactor tests to ensure its easy to maintain different configurations

* Update third party tests

* Clean up

* Minor copy update

* Trim the label text

* Add build

* Handle if label is not supplied

* Highlight var in changelog, minor update

* Update custom payload to test for trimmed-version label
@rishabhpoddar rishabhpoddar merged commit 41be764 into 0.35 Nov 23, 2023
21 of 23 checks passed
@rishabhpoddar rishabhpoddar deleted the feat/custom-form-fields branch November 23, 2023 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants