Skip to content

Commit 4617fe2

Browse files
authored
fix(console): use consistent field tags across list page and details page (#7688)
1 parent baa12c2 commit 4617fe2

File tree

3 files changed

+21
-11
lines changed
  • packages/console/src/pages/SignInExperience/PageContent/CollectUserProfile

3 files changed

+21
-11
lines changed

packages/console/src/pages/SignInExperience/PageContent/CollectUserProfile/ProfileFieldDetails/ProfileFieldDetailsForm/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { collectUserProfilePathname } from '../../consts';
2424
import { parseResponseToFormData, parseFormDataToRequestPayload } from '../../data-parser';
2525
import { type ProfileFieldForm } from '../../types';
2626
import useI18nFieldLabel from '../../use-i18n-field-label';
27-
import { isBuiltInCustomProfileFieldKey } from '../../utils';
27+
import { getFieldTags, isBuiltInCustomProfileFieldKey } from '../../utils';
2828

2929
import styles from './index.module.scss';
3030

@@ -120,11 +120,7 @@ function ProfileFieldDetailsForm({ data }: Props) {
120120
title={watch('label') || getI18nLabel(data.name)}
121121
identifier={{
122122
name: t('sign_in_exp.custom_profile_fields.details.key'),
123-
tags: compositionParts
124-
?.filter(({ enabled }) => enabled)
125-
.map(({ name }) => (data.name === 'address' ? `address.${name}` : name)) ?? [
126-
isBuiltInFieldName ? data.name : `customData.${data.name}`,
127-
],
123+
tags: getFieldTags(data.name, compositionParts),
128124
}}
129125
actionMenuItems={[
130126
{

packages/console/src/pages/SignInExperience/PageContent/CollectUserProfile/ProfileFieldList/index.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { trySubmitSafe } from '@/utils/form';
1313

1414
import { collectUserProfilePathname } from '../consts';
1515
import useI18nFieldLabel from '../use-i18n-field-label';
16+
import { getFieldTags } from '../utils';
1617

1718
import styles from './index.module.scss';
1819

@@ -79,11 +80,7 @@ function ProfileFieldList({ data }: Props) {
7980
<div className={styles.cell}>{t(`sign_in_exp.custom_profile_fields.type.${type}`)}</div>
8081
<div className={styles.cell}>
8182
<div className={styles.tags}>
82-
{(
83-
config.parts
84-
?.filter(({ enabled }) => Boolean(enabled))
85-
.map((part) => part.name) ?? [name]
86-
).map((key) => (
83+
{getFieldTags(name, config.parts).map((key) => (
8784
<Tag key={key} variant="cell">
8885
{key}
8986
</Tag>

packages/console/src/pages/SignInExperience/PageContent/CollectUserProfile/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
builtInCustomProfileFieldKeys,
33
CustomProfileFieldType,
4+
type FieldPart,
45
userProfileAddressKeys,
56
} from '@logto/schemas';
67

@@ -48,3 +49,19 @@ export const getProfileFieldTypeByName = (name: string): CustomProfileFieldType
4849
}
4950
}
5051
};
52+
53+
/**
54+
* Generates field tags based on the field name and its composition parts.
55+
* For address fields, it prefixes the field name with 'address.'.
56+
* For custom fields, it prefixes with 'customData.'.
57+
* Other built-in fields are used as-is.
58+
*/
59+
export const getFieldTags = (fieldName: string, compositionParts?: FieldPart[]): string[] => {
60+
if (compositionParts) {
61+
return compositionParts
62+
.filter(({ enabled }) => enabled)
63+
.map(({ name }) => (fieldName === 'address' ? `address.${name}` : name));
64+
}
65+
66+
return isBuiltInCustomProfileFieldKey(fieldName) ? [fieldName] : [`customData.${fieldName}`];
67+
};

0 commit comments

Comments
 (0)