-
-
Notifications
You must be signed in to change notification settings - Fork 441
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experience): improve identifier prefilling (#6508)
- Loading branch information
Showing
8 changed files
with
73 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ExtraParamsKey } from '@logto/schemas'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
const useLoginHint = () => { | ||
const [searchParams] = useSearchParams(); | ||
|
||
return searchParams.get(ExtraParamsKey.LoginHint) ?? undefined; | ||
}; | ||
|
||
export default useLoginHint; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { type SignInIdentifier } from '@logto/schemas'; | ||
import { useContext, useMemo } from 'react'; | ||
|
||
import UserInteractionContext from '@/Providers/UserInteractionContextProvider/UserInteractionContext'; | ||
import { type IdentifierInputValue } from '@/components/InputFields/SmartInputField'; | ||
|
||
import useLoginHint from './use-login-hint'; | ||
|
||
type Options = { | ||
enabledIdentifiers?: SignInIdentifier[]; | ||
}; | ||
|
||
const usePrefilledIdentifier = ({ enabledIdentifiers }: Options = {}) => { | ||
const { identifierInputValue, getIdentifierInputValueByTypes } = | ||
useContext(UserInteractionContext); | ||
|
||
const loginHint = useLoginHint(); | ||
|
||
const cachedInputIdentifier = useMemo(() => { | ||
return enabledIdentifiers | ||
? getIdentifierInputValueByTypes(enabledIdentifiers) | ||
: identifierInputValue; | ||
}, [enabledIdentifiers, getIdentifierInputValueByTypes, identifierInputValue]); | ||
|
||
return useMemo<IdentifierInputValue>(() => { | ||
/** | ||
* First, check if there's a cached input identifier | ||
* If there's no cached input identifier, check if there's a valid login hint | ||
* If there's neither, return empty | ||
*/ | ||
return cachedInputIdentifier ?? { value: loginHint ?? '' }; | ||
}, [cachedInputIdentifier, loginHint]); | ||
}; | ||
|
||
export default usePrefilledIdentifier; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters