Skip to content

Commit cf90176

Browse files
committed
Refactor registration module to utilize useExtensionPoint for form extension and streamline field management
1 parent 2882149 commit cf90176

File tree

2 files changed

+64
-79
lines changed
  • src/VirtoCommerce.MarketplaceRegistrationModule.Web/vcmp-registration/src/modules/registration

2 files changed

+64
-79
lines changed

src/VirtoCommerce.MarketplaceRegistrationModule.Web/vcmp-registration/src/modules/registration/composables/useRegistrationForm/index.ts

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { ref, computed } from "vue";
2-
import { useExtensionData } from "@vc-shell/framework";
32

43
export interface IFormField {
54
name: string;
@@ -14,37 +13,79 @@ export interface IFormField {
1413
priority?: number;
1514
}
1615

17-
export function useRegistrationForm() {
18-
const { data, updateData, getValue, setValue } = useExtensionData("registration-form");
16+
const defaultFields: IFormField[] = [
17+
{
18+
name: "firstName",
19+
type: "text",
20+
component: "VcInput",
21+
label: "VCMP_VENDOR_REGISTRATION.LABELS.FIRST_NAME",
22+
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.FIRST_NAME",
23+
required: true,
24+
rules: "required",
25+
priority: 10,
26+
},
27+
{
28+
name: "lastName",
29+
type: "text",
30+
component: "VcInput",
31+
label: "VCMP_VENDOR_REGISTRATION.LABELS.LAST_NAME",
32+
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.LAST_NAME",
33+
required: true,
34+
rules: "required",
35+
priority: 20,
36+
},
37+
{
38+
name: "organizationName",
39+
type: "text",
40+
component: "VcInput",
41+
label: "VCMP_VENDOR_REGISTRATION.LABELS.ORGANIZATION",
42+
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.ORGANIZATION",
43+
required: true,
44+
rules: "required",
45+
priority: 30,
46+
},
47+
{
48+
name: "contactEmail",
49+
type: "email",
50+
component: "VcInput",
51+
label: "VCMP_VENDOR_REGISTRATION.LABELS.EMAIL",
52+
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.EMAIL",
53+
hint: "VCMP_VENDOR_REGISTRATION.HINTS.EMAIL",
54+
required: true,
55+
rules: "emailWithServerValidation",
56+
priority: 40,
57+
},
58+
{
59+
name: "contactPhone",
60+
type: "tel",
61+
component: "VcInput",
62+
label: "VCMP_VENDOR_REGISTRATION.LABELS.PHONE",
63+
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.PHONE",
64+
rules: "phone",
65+
priority: 50,
66+
},
67+
];
68+
69+
// Module-level reactive state — other plugins can extend via extendForm()
70+
const fields = ref<IFormField[]>([...defaultFields]);
1971

20-
// Local form data
72+
export function useRegistrationForm() {
2173
const formData = ref<Record<string, unknown>>({});
2274

23-
// Fields from extension system
2475
const formConfig = computed(() => ({
25-
fields: (data.value.fields || []).sort((a: IFormField, b: IFormField) => (a.priority || 0) - (b.priority || 0)),
76+
fields: [...fields.value].sort((a, b) => (a.priority || 0) - (b.priority || 0)),
2677
}));
2778

2879
const extendForm = (newFields: IFormField[]) => {
29-
const currentFields = data.value.fields || [];
30-
updateData({
31-
fields: [...currentFields, ...newFields],
32-
});
80+
fields.value.push(...newFields);
3381
};
3482

3583
const removeField = (fieldName: string) => {
36-
const currentFields = data.value.fields || [];
37-
updateData({
38-
fields: currentFields.filter((field: IFormField) => field.name !== fieldName),
39-
});
84+
fields.value = fields.value.filter((f) => f.name !== fieldName);
4085
};
4186

4287
const updateField = (fieldName: string, updates: Partial<IFormField>) => {
43-
const currentFields = data.value.fields || [];
44-
const updatedFields = currentFields.map((field: IFormField) =>
45-
field.name === fieldName ? { ...field, ...updates } : field,
46-
);
47-
updateData({ fields: updatedFields });
88+
fields.value = fields.value.map((f) => (f.name === fieldName ? { ...f, ...updates } : f));
4889
};
4990

5091
const updateFormData = (fieldName: string, value: unknown) => {
Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as locales from "./locales";
2-
import { i18n, useExtensionData, useExtensionSlot } from "@vc-shell/framework";
2+
import { i18n, useExtensionPoint } from "@vc-shell/framework";
33
import { Router } from "vue-router";
44
import { App } from "vue";
55
import { routes } from "./router";
@@ -28,72 +28,16 @@ export default {
2828
});
2929
}
3030

31-
const { addComponent } = useExtensionSlot("login-after-form");
31+
const { add } = useExtensionPoint("auth:after-form");
3232

33-
addComponent({
33+
add({
3434
id: "registration-button",
3535
component: RegistrationButton,
3636
props: {
3737
text: "Register",
3838
},
3939
priority: 10,
40-
});
41-
42-
const { updateData } = useExtensionData("registration-form");
43-
44-
updateData({
45-
fields: [
46-
{
47-
name: "firstName",
48-
type: "text",
49-
component: "VcInput",
50-
label: "VCMP_VENDOR_REGISTRATION.LABELS.FIRST_NAME",
51-
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.FIRST_NAME",
52-
required: true,
53-
rules: "required",
54-
priority: 10,
55-
},
56-
{
57-
name: "lastName",
58-
type: "text",
59-
component: "VcInput",
60-
label: "VCMP_VENDOR_REGISTRATION.LABELS.LAST_NAME",
61-
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.LAST_NAME",
62-
required: true,
63-
rules: "required",
64-
priority: 20,
65-
},
66-
{
67-
name: "organizationName",
68-
type: "text",
69-
component: "VcInput",
70-
label: "VCMP_VENDOR_REGISTRATION.LABELS.ORGANIZATION",
71-
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.ORGANIZATION",
72-
required: true,
73-
rules: "required",
74-
priority: 30,
75-
},
76-
{
77-
name: "contactEmail",
78-
type: "email",
79-
component: "VcInput",
80-
label: "VCMP_VENDOR_REGISTRATION.LABELS.EMAIL",
81-
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.EMAIL",
82-
hint: "VCMP_VENDOR_REGISTRATION.HINTS.EMAIL",
83-
required: true,
84-
rules: "emailWithServerValidation",
85-
priority: 40,
86-
},
87-
{
88-
name: "contactPhone",
89-
type: "tel",
90-
component: "VcInput",
91-
label: "VCMP_VENDOR_REGISTRATION.LABELS.PHONE",
92-
placeholder: "VCMP_VENDOR_REGISTRATION.PLACEHOLDERS.PHONE",
93-
rules: "phone",
94-
priority: 50,
95-
},
96-
],
40+
meta: { type: "action", intent: "navigate" },
9741
});
9842
},
9943
};

0 commit comments

Comments
 (0)