0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-04-14 23:11:31 -05:00

fix(console): disable conflicted sign-up identifiers (#7186)

* fix(console): disable conflicted sign-up identifiers

disaable conflicted sign-up identifiers

* style(console): remove hover style

remove hover style of the disabled elements
This commit is contained in:
simeng-li 2025-03-27 09:49:28 +08:00 committed by GitHub
parent 5db244f6fb
commit 880de8567e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 22 deletions

View file

@ -83,35 +83,39 @@ function SignUpIdentifiersEditBox({ syncSignInMethods }: Props) {
Array<{
value: SignUpIdentifier;
label: string;
disabled?: boolean;
}>
>(() => {
const identifiersSet = new Set(signUpIdentifiers.map(({ identifier }) => identifier));
const availableOptions = signUpIdentifierOptions.filter(
({ value }) => !identifiersSet.has(value)
);
return signUpIdentifierOptions.filter(({ value }) => {
// Basic condition: filter out if identifiers include the value
if (identifiersSet.has(value)) {
return false;
return availableOptions.map(({ value, label }) => {
// Disable email and phone options if email or phone is selected
if (value === SignInIdentifier.Email || value === SignInIdentifier.Phone) {
return {
value,
label,
disabled: identifiersSet.has(AlternativeSignUpIdentifier.EmailOrPhone),
};
}
// Condition 2: If identifiers include EmailOrPhone, filter out Email and Phone
if (
identifiersSet.has(AlternativeSignUpIdentifier.EmailOrPhone) &&
(value === SignInIdentifier.Email || value === SignInIdentifier.Phone)
) {
return false;
// Disable emailOrPhone option if email or phone is selected
if (value === AlternativeSignUpIdentifier.EmailOrPhone) {
return {
value,
label,
disabled:
identifiersSet.has(SignInIdentifier.Email) ||
identifiersSet.has(SignInIdentifier.Phone),
};
}
// Condition 3: If identifiers include Email or Phone, filter out EmailOrPhone
if (
(identifiersSet.has(SignInIdentifier.Email) ||
identifiersSet.has(SignInIdentifier.Phone)) &&
value === AlternativeSignUpIdentifier.EmailOrPhone
) {
return false;
}
// If none of the conditions matched, keep the value
return true;
return {
value,
label,
};
});
}, [signUpIdentifiers]);

View file

@ -1,3 +1,5 @@
@use '@/scss/underscore' as _;
.addAnotherIdentifierDropdown {
min-width: 208px;
}
@ -5,3 +7,12 @@
.addIdentifierDropDown {
min-width: unset;
}
.disabledDropdownItem {
cursor: not-allowed;
color: var(--color-placeholder);
&:hover {
background-color: transparent;
}
}

View file

@ -15,6 +15,7 @@ type MethodsType = 'sign-in' | 'sign-up';
type Options<T> = Array<{
value: T;
label: string;
disabled?: boolean;
}>;
type Props<T> = {
@ -60,10 +61,14 @@ function IdentifiersAddButton<T extends SignInIdentifier | SignUpIdentifier>({
)}
isDropdownFullWidth={!hasSelectedIdentifiers}
>
{options.map(({ value, label }) => (
{options.map(({ value, label, disabled }) => (
<DropdownItem
key={value}
className={disabled ? styles.disabledDropdownItem : undefined}
onClick={() => {
if (disabled) {
return;
}
onSelected(value);
}}
>