Skip to content

Commit d7caad3

Browse files
authored
feat: update DOB Pattern to Date Pattern and add Date Picker Configuration (TCKT-572) (#623)
* refactor: update DOB pattern to Date pattern TCKT-572 * refactor: update config files for DOB pattern TCKT-572 * feat: add config file for Date picker pattern TCKT-572 * test: add config tests for Date picker pattern TCKT-572 * feat: update types and add Date picker pattern to dropdown menu TCKT-572 * chore: update imports to reflect component name change from DOB to Date TCKT-572
1 parent 6d5a376 commit d7caad3

18 files changed

Lines changed: 301 additions & 63 deletions

File tree

packages/common/src/locales/en/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ export const en = {
9494
hint: '',
9595
errorTextMustContainChar: 'String must contain at least 1 character(s)',
9696
},
97-
dateOfBirth: {
97+
date: {
9898
...defaults,
99-
displayName: 'Date of birth',
99+
displayName: 'Date',
100100
fieldLabel: 'Question text',
101101
hintLabel: 'Hint text (optional)',
102102
hint: 'For example: January 19 2000',

packages/design/src/Form/components/DateOfBirth/DateOfBirth.stories.tsx renamed to packages/design/src/Form/components/Date/Date.stories.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import React from 'react';
22
import { FormProvider, useForm } from 'react-hook-form';
33
import { type Meta, type StoryObj } from '@storybook/react';
44

5-
import { DateOfBirthPattern } from './DateOfBirth.js';
5+
import { DatePattern } from './Date.js';
66

7-
const meta: Meta<typeof DateOfBirthPattern> = {
7+
const meta: Meta<typeof DatePattern> = {
88
title: 'patterns/DateOfBirthPattern',
9-
component: DateOfBirthPattern,
9+
component: DatePattern,
1010
decorators: [
1111
(Story, args) => {
1212
const FormDecorator = () => {
@@ -33,7 +33,7 @@ const meta: Meta<typeof DateOfBirthPattern> = {
3333

3434
export default meta;
3535

36-
export const Default: StoryObj<typeof DateOfBirthPattern> = {
36+
export const Default: StoryObj<typeof DatePattern> = {
3737
args: {
3838
_patternId: '',
3939
type: 'date-of-birth',
@@ -46,7 +46,7 @@ export const Default: StoryObj<typeof DateOfBirthPattern> = {
4646
},
4747
};
4848

49-
export const WithoutHint: StoryObj<typeof DateOfBirthPattern> = {
49+
export const WithoutHint: StoryObj<typeof DatePattern> = {
5050
args: {
5151
_patternId: '',
5252
type: 'date-of-birth',
@@ -59,7 +59,7 @@ export const WithoutHint: StoryObj<typeof DateOfBirthPattern> = {
5959
},
6060
};
6161

62-
export const WithError: StoryObj<typeof DateOfBirthPattern> = {
62+
export const WithError: StoryObj<typeof DatePattern> = {
6363
args: {
6464
_patternId: '',
6565
type: 'date-of-birth',
@@ -76,7 +76,7 @@ export const WithError: StoryObj<typeof DateOfBirthPattern> = {
7676
},
7777
};
7878

79-
export const Required: StoryObj<typeof DateOfBirthPattern> = {
79+
export const Required: StoryObj<typeof DatePattern> = {
8080
args: {
8181
_patternId: '',
8282
type: 'date-of-birth',

packages/design/src/Form/components/DateOfBirth/DateOfBirth.tsx renamed to packages/design/src/Form/components/Date/Date.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import classNames from 'classnames';
33
import { useFormContext } from 'react-hook-form';
4-
import { type DateOfBirthProps } from '@gsa-tts/forms-core';
4+
import { type DateProps } from '@gsa-tts/forms-core';
55
import { type PatternComponent } from '../../index.js';
66

77
const months = [
@@ -27,7 +27,7 @@ const getAriaDescribedBy = (
2727
return ids || undefined;
2828
};
2929

30-
export const DateOfBirthPattern: PatternComponent<DateOfBirthProps> = ({
30+
export const DatePattern: PatternComponent<DateProps> = ({
3131
monthId,
3232
dayId,
3333
yearId,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { DatePattern } from './Date.js';
2+
3+
export default DatePattern;

packages/design/src/Form/components/DateOfBirth/index.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/design/src/Form/components/Fieldset/Fieldset.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Fieldset from './index.js';
55
import { FormProvider, useForm } from 'react-hook-form';
66
import { defaultPatternComponents } from '../index.js';
77
import type {
8-
DateOfBirthProps,
8+
DateProps,
99
EmailInputProps,
1010
FieldsetProps,
1111
} from '@gsa-tts/forms-core';
@@ -35,7 +35,7 @@ const mockChildComponents = (index: number, hasError: boolean) => [
3535
message: 'Invalid date of birth',
3636
}
3737
: undefined,
38-
} as DateOfBirthProps,
38+
} as DateProps,
3939
children: [],
4040
},
4141
{

packages/design/src/Form/components/Repeater/Repeater.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Repeater from './index.js';
44
import { FormProvider, useForm } from 'react-hook-form';
55
import { defaultPatternComponents } from '../index.js';
66
import type {
7-
DateOfBirthProps,
7+
DateProps,
88
EmailInputProps,
99
RepeaterProps,
1010
} from '@gsa-tts/forms-core';
@@ -28,7 +28,7 @@ const mockChildComponents = (index: number) => [
2828
monthId: `3fdb2cb6-5d65-4de1-b773-3fb8636f5d09.${index}.a6c217f0-fe84-44ef-b606-69142ecb3365.month`,
2929
yearId: `3fdb2cb6-5d65-4de1-b773-3fb8636f5d09.${index}.a6c217f0-fe84-44ef-b606-69142ecb3365.year`,
3030
required: false,
31-
} as DateOfBirthProps,
31+
} as DateProps,
3232
children: [],
3333
},
3434
{

packages/design/src/Form/components/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import Attachment from './Attachment/index.js';
55
import Address from './Address/index.js';
66
import Checkbox from './Checkbox/index.js';
77
import CheckboxGroup from './CheckboxGroup/index.js';
8-
import DateOfBirth from './DateOfBirth/index.js';
8+
import Date from './Date/index.js';
99
import EmailInput from './EmailInput/index.js';
1010
import Fieldset from './Fieldset/index.js';
1111
import FormSummary from './FormSummary/index.js';
@@ -33,7 +33,8 @@ export const defaultPatternComponents: ComponentForPattern = {
3333
address: Address as PatternComponent,
3434
checkbox: Checkbox as PatternComponent,
3535
'checkbox-group': CheckboxGroup as PatternComponent,
36-
'date-of-birth': DateOfBirth as PatternComponent,
36+
'date-of-birth': Date as PatternComponent,
37+
'date-picker': Date as PatternComponent,
3738
'email-input': EmailInput as PatternComponent,
3839
fieldset: Fieldset as PatternComponent,
3940
'form-summary': FormSummary as PatternComponent,

packages/design/src/FormManager/FormEdit/AddPatternDropdown.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ const sidebarPatterns: DropdownPattern[] = [
135135
['page', defaultFormConfig.patterns['page'], 'Form structure'],
136136
['rich-text', defaultFormConfig.patterns['rich-text'], 'Other'],
137137
['attachment', defaultFormConfig.patterns['attachment'], 'Other'],
138+
['date-picker', defaultFormConfig.patterns['date-picker'], 'Other'],
138139
['package-download', defaultFormConfig.patterns['package-download'], 'Other'],
139140
] as const;
140141

packages/design/src/FormManager/FormEdit/components/DateOfBirthPatternEdit/DateOfBirthPatternEdit.stories.tsx renamed to packages/design/src/FormManager/FormEdit/components/DatePatternEdit/DatePatternEdit.stories.tsx

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const pattern: DateOfBirthPattern = {
1111
id: 'date-of-birth-1',
1212
type: 'date-of-birth',
1313
data: {
14-
label: message.patterns.dateOfBirth.displayName,
14+
label: message.patterns.date.displayName,
1515
required: false,
1616
hint: undefined,
1717
},
@@ -32,19 +32,13 @@ export const Basic: StoryObj<typeof FormEdit> = {
3232
const updatedLabel = 'Date of birth update';
3333
const updatedHint = 'Updated hint for Date of birth';
3434

35-
await userEvent.click(
36-
canvas.getByText(message.patterns.dateOfBirth.displayName)
37-
);
35+
await userEvent.click(canvas.getByText(message.patterns.date.displayName));
3836

39-
const labelInput = canvas.getByLabelText(
40-
message.patterns.dateOfBirth.fieldLabel
41-
);
37+
const labelInput = canvas.getByLabelText(message.patterns.date.fieldLabel);
4238
await userEvent.clear(labelInput);
4339
await userEvent.type(labelInput, updatedLabel);
4440

45-
const hintInput = canvas.getByLabelText(
46-
message.patterns.dateOfBirth.hintLabel
47-
);
41+
const hintInput = canvas.getByLabelText(message.patterns.date.hintLabel);
4842
await userEvent.clear(hintInput);
4943
await userEvent.type(hintInput, updatedHint);
5044

@@ -61,13 +55,9 @@ export const WithoutHint: StoryObj<typeof FormEdit> = {
6155
const canvas = within(canvasElement);
6256
const updatedLabel = 'Date of birth update';
6357

64-
await userEvent.click(
65-
canvas.getByText(message.patterns.dateOfBirth.displayName)
66-
);
58+
await userEvent.click(canvas.getByText(message.patterns.date.displayName));
6759

68-
const labelInput = canvas.getByLabelText(
69-
message.patterns.dateOfBirth.fieldLabel
70-
);
60+
const labelInput = canvas.getByLabelText(message.patterns.date.fieldLabel);
7161
await userEvent.clear(labelInput);
7262
await userEvent.type(labelInput, updatedLabel);
7363

@@ -76,7 +66,7 @@ export const WithoutHint: StoryObj<typeof FormEdit> = {
7666

7767
await expect(await canvas.findByText(updatedLabel)).toBeInTheDocument();
7868
await expect(
79-
await canvas.queryByLabelText(message.patterns.dateOfBirth.hintLabel)
69+
await canvas.queryByLabelText(message.patterns.date.hintLabel)
8070
).toBeNull();
8171
},
8272
};
@@ -85,20 +75,14 @@ export const Error: StoryObj<typeof FormEdit> = {
8575
play: async ({ canvasElement }) => {
8676
const canvas = within(canvasElement);
8777

88-
await userEvent.click(
89-
canvas.getByText(message.patterns.dateOfBirth.displayName)
90-
);
78+
await userEvent.click(canvas.getByText(message.patterns.date.displayName));
9179

92-
const labelInput = canvas.getByLabelText(
93-
message.patterns.dateOfBirth.fieldLabel
94-
);
80+
const labelInput = canvas.getByLabelText(message.patterns.date.fieldLabel);
9581
await userEvent.clear(labelInput);
9682
labelInput.blur();
9783

9884
await expect(
99-
await canvas.findByText(
100-
message.patterns.dateOfBirth.errorTextMustContainChar
101-
)
85+
await canvas.findByText(message.patterns.date.errorTextMustContainChar)
10286
).toBeInTheDocument();
10387
},
10488
};

0 commit comments

Comments
 (0)