logto
logto copied to clipboard
refactor(experience): improve identifier prefilling
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
useSearchParamsfrom multiple components. - Updated the
IdentifierRegisterForm,IdentifierSignInForm, andPasswordSignInFormcomponents to utilize theusePrefilledIdentifierhook, 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
useLoginHinthook to encapsulate the logic for extracting the login hint from URL parameters. - Remove the redundant
useUpdateEffectlogic fromuse-smart-input-filedlogic, 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
useUpdateEffecthook, 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
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 |