Skip to content

Commit 4c5a8a4

Browse files
feat: extended FormField model into input/select/switch subtypes for future use
1 parent d90ebed commit 4c5a8a4

File tree

8 files changed

+82
-30
lines changed

8 files changed

+82
-30
lines changed

.changeset/tangy-kids-clap.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@o2s/integrations.strapi-cms': patch
3+
'@o2s/integrations.mocked': patch
4+
'@o2s/framework': patch
5+
---
6+
7+
extended `FormField` model into input/select/switch subtypes for future use

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/framework/src/utils/models/form-field.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export class FormField {
1+
export class FormFieldBase {
22
id!: string;
33
name!: string;
44
label!: string;
@@ -8,6 +8,28 @@ export class FormField {
88
errorMessages?: ErrorMessage[];
99
}
1010

11+
export type FormField = Input | Select | Switch;
12+
13+
export class Input extends FormFieldBase {
14+
__typename!: 'Input';
15+
}
16+
17+
export class Select extends FormFieldBase {
18+
__typename!: 'Select';
19+
options!: Option<string>[];
20+
}
21+
22+
export class Switch extends FormFieldBase {
23+
__typename!: 'Switch';
24+
options!: [Option<boolean>, Option<boolean>];
25+
}
26+
27+
export class Option<T> {
28+
value!: T;
29+
label!: string;
30+
isDefault?: boolean;
31+
}
32+
1133
export class ErrorMessage {
1234
id!: string;
1335
name!: string;

packages/integrations/mocked/src/modules/cms/mappers/blocks/cms.user-account.mapper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const MOCK_USER_ACCOUNT_BLOCK_EN: CMS.Model.UserAccountBlock.UserAccountBlock =
77
basicInformationDescription: 'Update your personal information to keep your account details current and accurate.',
88
fields: [
99
{
10+
__typename: 'Input',
1011
id: 'first-name-1',
1112
name: 'firstName',
1213
label: 'First Name',
@@ -33,6 +34,7 @@ const MOCK_USER_ACCOUNT_BLOCK_EN: CMS.Model.UserAccountBlock.UserAccountBlock =
3334
],
3435
},
3536
{
37+
__typename: 'Input',
3638
id: 'last-name-1',
3739
name: 'lastName',
3840
label: 'Last Name',
@@ -47,6 +49,7 @@ const MOCK_USER_ACCOUNT_BLOCK_EN: CMS.Model.UserAccountBlock.UserAccountBlock =
4749
],
4850
},
4951
{
52+
__typename: 'Input',
5053
id: 'email-1',
5154
name: 'email',
5255
label: 'Email',
@@ -78,6 +81,7 @@ const MOCK_USER_ACCOUNT_BLOCK_PL: CMS.Model.UserAccountBlock.UserAccountBlock =
7881
'Zaktualizuj swoje dane osobowe, aby utrzymać aktualne i dokładne informacje o koncie.',
7982
fields: [
8083
{
84+
__typename: 'Input',
8185
id: 'first-name-1',
8286
name: 'firstName',
8387
label: 'Imię',
@@ -104,6 +108,7 @@ const MOCK_USER_ACCOUNT_BLOCK_PL: CMS.Model.UserAccountBlock.UserAccountBlock =
104108
],
105109
},
106110
{
111+
__typename: 'Input',
107112
id: 'last-name-1',
108113
name: 'lastName',
109114
label: 'Nazwisko',
@@ -118,6 +123,7 @@ const MOCK_USER_ACCOUNT_BLOCK_PL: CMS.Model.UserAccountBlock.UserAccountBlock =
118123
],
119124
},
120125
{
126+
__typename: 'Input',
121127
id: 'email-1',
122128
name: 'email',
123129
label: 'Email',
@@ -149,6 +155,7 @@ const MOCK_USER_ACCOUNT_BLOCK_DE: CMS.Model.UserAccountBlock.UserAccountBlock =
149155
'Aktualisieren Sie Ihre persönlichen Daten, um Ihre Kontoinformationen aktuell und genau zu halten.',
150156
fields: [
151157
{
158+
__typename: 'Input',
152159
id: 'first-name-1',
153160
name: 'firstName',
154161
label: 'Vorname',
@@ -175,6 +182,7 @@ const MOCK_USER_ACCOUNT_BLOCK_DE: CMS.Model.UserAccountBlock.UserAccountBlock =
175182
],
176183
},
177184
{
185+
__typename: 'Input',
178186
id: 'last-name-1',
179187
name: 'lastName',
180188
label: 'Nachname',
@@ -189,6 +197,7 @@ const MOCK_USER_ACCOUNT_BLOCK_DE: CMS.Model.UserAccountBlock.UserAccountBlock =
189197
],
190198
},
191199
{
200+
__typename: 'Input',
192201
id: 'email-1',
193202
name: 'email',
194203
label: 'E-Mail',

packages/integrations/mocked/src/modules/cms/mappers/cms.login-page.mapper.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const LOGIN_PAGE_PL: CMS.Model.LoginPage.LoginPage = {
44
title: 'Zaloguj się',
55
subtitle: 'Wprowadź swój email i hasło, aby uzyskać dostęp do konta',
66
username: {
7+
__typename: 'Input',
78
id: 'username-1',
89
name: 'username',
910
label: 'Nazwa użytkownika',
@@ -30,6 +31,7 @@ const LOGIN_PAGE_PL: CMS.Model.LoginPage.LoginPage = {
3031
],
3132
},
3233
password: {
34+
__typename: 'Input',
3335
id: 'password-1',
3436
name: 'password',
3537
label: 'Hasło',
@@ -93,6 +95,7 @@ const LOGIN_PAGE_EN: CMS.Model.LoginPage.LoginPage = {
9395
title: 'Sign in',
9496
subtitle: 'Please enter your email and password below to access your account.',
9597
username: {
98+
__typename: 'Input',
9699
id: 'username-1',
97100
name: 'username',
98101
label: 'Username',
@@ -119,6 +122,7 @@ const LOGIN_PAGE_EN: CMS.Model.LoginPage.LoginPage = {
119122
],
120123
},
121124
password: {
125+
__typename: 'Input',
122126
id: 'password-1',
123127
name: 'password',
124128
label: 'Password',
@@ -203,6 +207,7 @@ const LOGIN_PAGE_DE: CMS.Model.LoginPage.LoginPage = {
203207
title: 'Einloggen',
204208
subtitle: 'Geben Sie Ihre E-Mail und Ihr Passwort ein, um auf Ihr Konto zuzugreifen',
205209
username: {
210+
__typename: 'Input',
206211
id: 'username-1',
207212
name: 'username',
208213
label: 'Benutzername',
@@ -229,6 +234,7 @@ const LOGIN_PAGE_DE: CMS.Model.LoginPage.LoginPage = {
229234
],
230235
},
231236
password: {
237+
__typename: 'Input',
232238
id: 'password-1',
233239
name: 'password',
234240
label: 'Passwort',

packages/integrations/strapi-cms/src/modules/cms/mappers/blocks/cms.user-account.mapper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { CMS } from '@o2s/framework/modules';
44

55
import { GetComponentQuery } from '@/generated/strapi';
66

7+
import { mapFormField } from '../cms.form-field.mapper';
8+
79
export const mapUserAccountBlock = (data: GetComponentQuery): CMS.Model.UserAccountBlock.UserAccountBlock => {
810
const component = data.component!.content[0];
911
const configurableTexts = data.configurableTexts!;
@@ -19,7 +21,7 @@ export const mapUserAccountBlock = (data: GetComponentQuery): CMS.Model.UserAcco
1921
title: component.title,
2022
basicInformationTitle: component.basicInformationTitle,
2123
basicInformationDescription: component.basicInformationDescription,
22-
fields: component.inputs,
24+
fields: component.inputs.map(mapFormField),
2325
labels: {
2426
edit: configurableTexts.actions.edit,
2527
save: configurableTexts.actions.save,
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Models } from '@o2s/framework/modules';
2+
3+
import { ErrorMessageComponentFragment, FormFieldComponentFragment } from '@/generated/strapi';
4+
5+
export const mapFormField = (component: FormFieldComponentFragment): Models.FormField.FormField => {
6+
switch (component.__typename) {
7+
case 'ComponentContentFormField':
8+
return {
9+
__typename: 'Input',
10+
id: component.id,
11+
name: component.name,
12+
label: component.label,
13+
placeholder: component.placeholder,
14+
errorMessages: component.errorMessages?.map(mapErrorMessage),
15+
};
16+
}
17+
};
18+
19+
export const mapErrorMessage = (component: ErrorMessageComponentFragment): Models.FormField.ErrorMessage => {
20+
return {
21+
id: component.id,
22+
name: component.name,
23+
type: component.type,
24+
description: component.description,
25+
};
26+
};

packages/integrations/strapi-cms/src/modules/cms/mappers/cms.login-page.mapper.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { CMS } from '@o2s/framework/modules';
22

33
import { GetLoginPageQuery } from '@/generated/strapi';
44

5+
import { mapFormField } from './cms.form-field.mapper';
6+
57
export const mapLoginPage = (data: GetLoginPageQuery, baseURL?: string): CMS.Model.LoginPage.LoginPage => {
68
const loginPage = data.loginPage!;
79
const labels = data.configurableTexts!;
@@ -22,30 +24,8 @@ export const mapLoginPage = (data: GetLoginPageQuery, baseURL?: string): CMS.Mod
2224
subtitle: loginPage.subtitle,
2325
title: loginPage.title,
2426
providers,
25-
username: {
26-
id: loginPage.username.id,
27-
name: loginPage.username.name,
28-
label: loginPage.username.label,
29-
placeholder: loginPage.username.placeholder,
30-
errorMessages: loginPage.username.errorMessages?.map((errorMessage) => ({
31-
id: errorMessage.id,
32-
description: errorMessage.description,
33-
name: errorMessage.name,
34-
type: errorMessage.type,
35-
})),
36-
},
37-
password: {
38-
id: loginPage.password.id,
39-
name: loginPage.password.name,
40-
label: loginPage.password.label,
41-
placeholder: loginPage.password.placeholder,
42-
errorMessages: loginPage.password.errorMessages?.map((errorMessage) => ({
43-
id: errorMessage.id,
44-
description: errorMessage.description,
45-
name: errorMessage.name,
46-
type: errorMessage.type,
47-
})),
48-
},
27+
username: mapFormField(loginPage.username),
28+
password: mapFormField(loginPage.password),
4929
labels: labels.actions,
5030
image: loginPage.image
5131
? {

0 commit comments

Comments
 (0)