logto icon indicating copy to clipboard operation
logto copied to clipboard

refactor(experience): improve identifier prefilling

Open xiaoyijun opened this issue 1 year ago • 1 comments

Summary

This pull request introduces several improvements and refactors in the handling of prefilled identifiers and login hints across multiple form components within the experience package. Key changes include:

Refactoring identifier handling

  • Introduced a new custom hook, usePrefilledIdentifier, to centralize the logic for fetching and setting prefilled identifiers, improving code readability and maintainability.
  • Removed redundant imports and useSearchParams from multiple components.
  • Updated the IdentifierRegisterForm, IdentifierSignInForm, and PasswordSignInForm components to utilize the usePrefilledIdentifier hook, simplifying the logic and ensuring consistency in prefilled identifier handling.
  • Apply prefilled identifier values to the form context rather than the smart input filed, this avoids the smart input filed to re-render redundantly after the cached input identifer changed.

Custom Hook Additions and Cleanup

  • Added useLoginHint hook to encapsulate the logic for extracting the login hint from URL parameters.
  • Remove the redundant useUpdateEffect logic from use-smart-input-filed logic, since it's a bug fix for legancy codes, now the smart input filed will update when the SIE config changes in the preview view from the Console.
  • Deleted the obsolete useUpdateEffect hook, as its functionality is no longer needed after the refactor.

These changes collectively improve the maintainability, readability, and reusability of the codebase, while ensuring that the handling of prefilled identifiers and login hints is more robust and consistent across the application.

Testing

Test locally and all IT passed.

Checklist

  • [ ] .changeset
  • [ ] unit tests
  • [ ] integration tests
  • [x] necessary TSDoc comments

xiaoyijun avatar Aug 23 '24 03:08 xiaoyijun

COMPARE TO master

Total Size Diff :chart_with_upwards_trend: +568 Bytes

Diff by File
Name Diff
packages/experience/src/components/IdentifierRegisterForm/index.tsx :chart_with_upwards_trend: +122 Bytes
packages/experience/src/components/IdentifierSignInForm/index.tsx :chart_with_upwards_trend: +95 Bytes
packages/experience/src/components/InputFields/SmartInputField/use-smart-input-field.ts :chart_with_upwards_trend: +272 Bytes
packages/experience/src/components/PasswordSignInForm/index.tsx :chart_with_upwards_trend: +74 Bytes
packages/experience/src/hooks/use-login-hint.ts :chart_with_upwards_trend: +275 Bytes
packages/experience/src/hooks/use-prefilled-identifier.ts :chart_with_upwards_trend: +1.23 KB
packages/experience/src/hooks/use-update-effect.ts :chart_with_upwards_trend: +489 Bytes
packages/experience/src/pages/ResetPasswordLanding/index.tsx :chart_with_upwards_trend: +67 Bytes

github-actions[bot] avatar Aug 23 '24 03:08 github-actions[bot]