Skip to content

Commit 9ba0485

Browse files
authored
refactor(console): improve date type default values handling in profile field configs (#7683)
refactor: improve date type profile field configs in console
1 parent 895dcfa commit 9ba0485

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/console/src/consts/external-links.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ export const retrieveTokenStorage = '/secret-vault/federated-token-set#token-ret
7373

7474
export const addOnPricingExplanationLink =
7575
'https://blog.logto.io/pricing-add-on-a-simple-explanation/';
76+
77+
export const dateFnsDocumentationLink = 'https://date-fns.org/v2.30.0/docs/format';

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { SupportedDateFormat } from '@logto/schemas';
2+
import { useEffect } from 'react';
23
import { Controller, useFormContext } from 'react-hook-form';
34
import { Trans, useTranslation } from 'react-i18next';
45

6+
import { dateFnsDocumentationLink } from '@/consts';
57
import FormField from '@/ds-components/FormField';
68
import Select from '@/ds-components/Select';
79
import TextInput from '@/ds-components/TextInput';
@@ -31,6 +33,21 @@ function DateFormatSelector({ index }: Props) {
3133
const formatValue = watch(`${fieldPrefix}format`);
3234
const formErrors = index === undefined ? errors : errors.parts?.[index];
3335

36+
useEffect(() => {
37+
if (!formatValue) {
38+
setValue(`${fieldPrefix}format`, SupportedDateFormat.US, { shouldDirty: true });
39+
setValue(`${fieldPrefix}placeholder`, SupportedDateFormat.US, { shouldDirty: true });
40+
}
41+
}, [fieldPrefix, formatValue, setValue]);
42+
43+
useEffect(() => {
44+
return () => {
45+
setValue(`${fieldPrefix}format`, '');
46+
setValue(`${fieldPrefix}placeholder`, '');
47+
setValue(`${fieldPrefix}customFormat`, '');
48+
};
49+
}, [fieldPrefix, setValue]);
50+
3451
return (
3552
<div className={styles.dateFormatSelector}>
3653
<Controller
@@ -65,7 +82,7 @@ function DateFormatSelector({ index }: Props) {
6582
description={
6683
<Trans
6784
components={{
68-
a: <TextLink targetBlank href="https://date-fns.org/v2.30.0/docs/format" />,
85+
a: <TextLink targetBlank href={dateFnsDocumentationLink} />,
6986
}}
7087
>
7188
{t('custom_date_format_tip')}

0 commit comments

Comments
 (0)