11import { ref , computed } from "vue" ;
2- import { useExtensionData } from "@vc-shell/framework" ;
32
43export 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 ) => {
0 commit comments