Skip to content

Commit 20522a1

Browse files
authored
refactor: add default placeholder for date type fields in profile fulfilling (#7668)
1 parent 9a0611b commit 20522a1

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

packages/console/src/pages/SignInExperience/PageContent/CollectUserProfile/data-parser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export const getInitialRequestPayloadByFieldName = (name: string) => {
100100
required: true,
101101
config: {
102102
format: cond(type === CustomProfileFieldType.Date && SupportedDateFormat.US),
103+
placeholder: cond(type === CustomProfileFieldType.Date && SupportedDateFormat.US),
103104
parts: getDefaultParts(type),
104105
options: getDefaultOptions(name),
105106
...cond(type === CustomProfileFieldType.Text && { minLength: 1, maxLength: 100 }),

packages/console/src/pages/SignInExperience/PageContent/components/DateFormatSelector/index.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { SupportedDateFormat } from '@logto/schemas';
2-
import { useEffect } from 'react';
32
import { Controller, useFormContext } from 'react-hook-form';
43
import { Trans, useTranslation } from 'react-i18next';
54

@@ -32,16 +31,6 @@ function DateFormatSelector({ index }: Props) {
3231
const formatValue = watch(`${fieldPrefix}format`);
3332
const formErrors = index === undefined ? errors : errors.parts?.[index];
3433

35-
useEffect(() => {
36-
if (!formatValue) {
37-
setValue(`${fieldPrefix}format`, SupportedDateFormat.US);
38-
return;
39-
}
40-
if (formatValue !== SupportedDateFormat.Custom) {
41-
setValue(`${fieldPrefix}customFormat`, '');
42-
}
43-
}, [fieldPrefix, formatValue, setValue]);
44-
4534
return (
4635
<div className={styles.dateFormatSelector}>
4736
<Controller
@@ -56,7 +45,14 @@ function DateFormatSelector({ index }: Props) {
5645
{ value: SupportedDateFormat.Custom, title: t('custom_date_format') },
5746
]}
5847
value={value}
59-
onChange={onChange}
48+
onChange={(value) => {
49+
onChange(value);
50+
setValue(
51+
`${fieldPrefix}placeholder`,
52+
value === SupportedDateFormat.Custom ? '' : value,
53+
{ shouldDirty: true }
54+
);
55+
}}
6056
/>
6157
)}
6258
/>

packages/console/src/pages/SignInExperience/PageContent/components/ProfileFieldPartSubForm/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ function ProfileFieldPartSubForm({ index }: Props) {
101101
}}
102102
/>
103103
</FormField>
104+
{type === CustomProfileFieldType.Date && (
105+
<FormField title="sign_in_exp.custom_profile_fields.details.date_format">
106+
<DateFormatSelector />
107+
</FormField>
108+
)}
104109
<FormField
105110
isRequired={!isBuiltInFieldName}
106111
title="sign_in_exp.custom_profile_fields.details.label"
@@ -184,11 +189,6 @@ function ProfileFieldPartSubForm({ index }: Props) {
184189
/>
185190
</FormField>
186191
)}
187-
{type === CustomProfileFieldType.Date && (
188-
<FormField title="sign_in_exp.custom_profile_fields.details.date_format">
189-
<DateFormatSelector />
190-
</FormField>
191-
)}
192192
{type === CustomProfileFieldType.Checkbox && (
193193
<FormField title="sign_in_exp.custom_profile_fields.details.default_value">
194194
<Controller

0 commit comments

Comments
 (0)