Skip to content

Commit c7bcc6f

Browse files
committed
Add new fields to ContactObject and update App component to include them in the form
1 parent 81effcc commit c7bcc6f

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

examples/msw-object-form/objectstack.config.ts

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,60 @@ export const ContactObject = {
7171
min: 1,
7272
max: 10
7373
},
74+
// New fields for testing all types
75+
salary: {
76+
name: 'salary',
77+
label: 'Salary (Currency)',
78+
type: 'currency',
79+
precision: 2
80+
},
81+
commission_rate: {
82+
name: 'commission_rate',
83+
label: 'Commission Rate (Percent)',
84+
type: 'percent',
85+
precision: 2
86+
},
87+
birthdate: {
88+
name: 'birthdate',
89+
label: 'Birth Date (Date)',
90+
type: 'date'
91+
},
92+
last_contacted: {
93+
name: 'last_contacted',
94+
label: 'Last Contacted (DateTime)',
95+
type: 'datetime'
96+
},
97+
available_time: {
98+
name: 'available_time',
99+
label: 'Preferred Time (Time)',
100+
type: 'time'
101+
},
102+
profile_url: {
103+
name: 'profile_url',
104+
label: 'LinkedIn Profile (URL)',
105+
type: 'url'
106+
},
107+
department: {
108+
name: 'department',
109+
label: 'Department (Select)',
110+
type: 'select',
111+
options: [
112+
{ label: 'Sales', value: 'sales' },
113+
{ label: 'Marketing', value: 'marketing' },
114+
{ label: 'Engineering', value: 'engineering' },
115+
{ label: 'HR', value: 'hr' }
116+
]
117+
},
118+
resume: {
119+
name: 'resume',
120+
label: 'Resume (File)',
121+
type: 'file'
122+
},
123+
avatar: {
124+
name: 'avatar',
125+
label: 'Avatar (Image)',
126+
type: 'image'
127+
},
74128
created_at: {
75129
name: 'created_at',
76130
label: 'Created At',
@@ -125,6 +179,13 @@ export default defineStack({
125179
notes: 'Initial contact from tech conference',
126180
is_active: true,
127181
priority: 8,
182+
salary: 120000,
183+
commission_rate: 0.05,
184+
birthdate: '1990-05-15',
185+
last_contacted: new Date('2024-05-01T10:00:00').toISOString(),
186+
available_time: '09:00:00',
187+
profile_url: 'https://linkedin.com/in/johndoe',
188+
department: 'engineering',
128189
created_at: new Date('2024-01-15').toISOString()
129190
},
130191
{
@@ -137,6 +198,13 @@ export default defineStack({
137198
notes: 'Met at product launch event',
138199
is_active: true,
139200
priority: 7,
201+
salary: 135000,
202+
commission_rate: 0.1,
203+
birthdate: '1988-11-20',
204+
last_contacted: new Date('2024-05-02T14:30:00').toISOString(),
205+
available_time: '14:00:00',
206+
profile_url: 'https://linkedin.com/in/janesmith',
207+
department: 'marketing',
140208
created_at: new Date('2024-02-20').toISOString()
141209
},
142210
{
@@ -149,6 +217,13 @@ export default defineStack({
149217
notes: '',
150218
is_active: false,
151219
priority: 5,
220+
salary: 180000,
221+
commission_rate: 0,
222+
birthdate: '1985-03-30',
223+
last_contacted: new Date('2024-04-15T09:00:00').toISOString(),
224+
available_time: '10:30:00',
225+
profile_url: 'https://linkedin.com/in/bobjohnson',
226+
department: 'engineering',
152227
created_at: new Date('2024-03-10').toISOString()
153228
}
154229
]

examples/msw-object-form/src/App.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,25 @@ export function App() {
125125
objectName: 'contact',
126126
mode: editingContact ? 'edit' : 'create',
127127
recordId: editingContact?.id,
128-
fields: ['name', 'email', 'phone', 'company', 'position', 'priority', 'is_active', 'notes'],
128+
fields: [
129+
'name',
130+
'email',
131+
'phone',
132+
'company',
133+
'position',
134+
'priority',
135+
'salary', // Added
136+
'commission_rate', // Added
137+
'birthdate', // Added
138+
'last_contacted', // Added
139+
'available_time', // Added
140+
'profile_url', // Added
141+
'department', // Added
142+
'resume', // Added
143+
'avatar', // Added
144+
'is_active',
145+
'notes'
146+
],
129147
layout: 'vertical',
130148
columns: 1,
131149
showSubmit: true,

packages/components/src/renderers/form/form.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,13 @@ function renderFieldComponent(type: string, props: RenderFieldProps) {
405405

406406
switch (type) {
407407
case 'input':
408+
if (inputType === 'file') {
409+
// File inputs cannot be controlled with value prop
410+
const { value, ...fileProps } = fieldProps;
411+
return <Input type="file" placeholder={placeholder} {...fileProps} />;
412+
}
408413
return <Input type={inputType || 'text'} placeholder={placeholder} {...fieldProps} value={fieldProps.value ?? ''} />;
409-
414+
410415
case 'textarea':
411416
return <Textarea placeholder={placeholder} {...fieldProps} value={fieldProps.value ?? ''} />;
412417

0 commit comments

Comments
 (0)