File tree Expand file tree Collapse file tree 4 files changed +81
-62
lines changed
packages/plugin-form-builder/src/collections/FormSubmissions Expand file tree Collapse file tree 4 files changed +81
-62
lines changed Original file line number Diff line number Diff line change
1
+ import type { Field } from 'payload'
2
+
3
+ export const defaultPaymentFields : Field = {
4
+ name : 'payment' ,
5
+ type : 'group' ,
6
+ admin : {
7
+ readOnly : true ,
8
+ } ,
9
+ fields : [
10
+ {
11
+ name : 'field' ,
12
+ type : 'text' ,
13
+ label : 'Field' ,
14
+ } ,
15
+ {
16
+ name : 'status' ,
17
+ type : 'text' ,
18
+ label : 'Status' ,
19
+ } ,
20
+ {
21
+ name : 'amount' ,
22
+ type : 'number' ,
23
+ admin : {
24
+ description : 'Amount in cents' ,
25
+ } ,
26
+ } ,
27
+ {
28
+ name : 'paymentProcessor' ,
29
+ type : 'text' ,
30
+ } ,
31
+ {
32
+ name : 'creditCard' ,
33
+ type : 'group' ,
34
+ fields : [
35
+ {
36
+ name : 'token' ,
37
+ type : 'text' ,
38
+ label : 'token' ,
39
+ } ,
40
+ {
41
+ name : 'brand' ,
42
+ type : 'text' ,
43
+ label : 'Brand' ,
44
+ } ,
45
+ {
46
+ name : 'number' ,
47
+ type : 'text' ,
48
+ label : 'Number' ,
49
+ } ,
50
+ ] ,
51
+ label : 'Credit Card' ,
52
+ } ,
53
+ ] ,
54
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import type { CollectionConfig, Field } from 'payload'
2
2
3
3
import type { FormBuilderPluginConfig } from '../../types.js'
4
4
5
+ import { defaultPaymentFields } from './fields/defaultPaymentFields.js'
5
6
import { createCharge } from './hooks/createCharge.js'
6
7
import { sendEmail } from './hooks/sendEmail.js'
7
8
@@ -11,6 +12,8 @@ export const generateSubmissionCollection = (
11
12
) : CollectionConfig => {
12
13
const formSlug = formConfig ?. formOverrides ?. slug || 'forms'
13
14
15
+ const enablePaymentFields = Boolean ( formConfig ?. fields ?. payment )
16
+
14
17
const defaultFields : Field [ ] = [
15
18
{
16
19
name : 'form' ,
@@ -79,6 +82,7 @@ export const generateSubmissionCollection = (
79
82
} ,
80
83
] ,
81
84
} ,
85
+ ...( enablePaymentFields ? [ defaultPaymentFields ] : [ ] ) ,
82
86
]
83
87
84
88
const newConfig : CollectionConfig = {
@@ -108,63 +112,5 @@ export const generateSubmissionCollection = (
108
112
] ,
109
113
} ,
110
114
}
111
-
112
- const paymentFieldConfig = formConfig ?. fields ?. payment
113
-
114
- if ( paymentFieldConfig ) {
115
- newConfig . fields . push ( {
116
- name : 'payment' ,
117
- type : 'group' ,
118
- admin : {
119
- readOnly : true ,
120
- } ,
121
- fields : [
122
- {
123
- name : 'field' ,
124
- type : 'text' ,
125
- label : 'Field' ,
126
- } ,
127
- {
128
- name : 'status' ,
129
- type : 'text' ,
130
- label : 'Status' ,
131
- } ,
132
- {
133
- name : 'amount' ,
134
- type : 'number' ,
135
- admin : {
136
- description : 'Amount in cents' ,
137
- } ,
138
- } ,
139
- {
140
- name : 'paymentProcessor' ,
141
- type : 'text' ,
142
- } ,
143
- {
144
- name : 'creditCard' ,
145
- type : 'group' ,
146
- fields : [
147
- {
148
- name : 'token' ,
149
- type : 'text' ,
150
- label : 'token' ,
151
- } ,
152
- {
153
- name : 'brand' ,
154
- type : 'text' ,
155
- label : 'Brand' ,
156
- } ,
157
- {
158
- name : 'number' ,
159
- type : 'text' ,
160
- label : 'Number' ,
161
- } ,
162
- ] ,
163
- label : 'Credit Card' ,
164
- } ,
165
- ] ,
166
- } )
167
- }
168
-
169
115
return newConfig
170
116
}
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import path from 'path'
3
3
const filename = fileURLToPath ( import . meta. url )
4
4
const dirname = path . dirname ( filename )
5
5
import type { BeforeEmail } from '@payloadcms/plugin-form-builder/types'
6
- import type { Block } from 'payload'
6
+ import type { Block , Field } from 'payload'
7
7
8
8
//import { nodemailerAdapter } from '@payloadcms/email-nodemailer'
9
9
import { formBuilderPlugin , fields as formFields } from '@payloadcms/plugin-form-builder'
@@ -104,8 +104,25 @@ export default buildConfigWithDefaults({
104
104
} ,
105
105
formSubmissionOverrides : {
106
106
fields : ( { defaultFields } ) => {
107
+ const modifiedFields : Field [ ] = defaultFields . map ( ( field ) => {
108
+ if ( 'name' in field && field . type === 'group' && field . name === 'payment' ) {
109
+ return {
110
+ ...field ,
111
+ fields : [
112
+ ...field . fields , // comment this out to override payments group entirely
113
+ {
114
+ name : 'stripeCheckoutSession' ,
115
+ type : 'text' ,
116
+ } ,
117
+ ] ,
118
+ }
119
+ }
120
+
121
+ return field
122
+ } )
123
+
107
124
return [
108
- ...defaultFields ,
125
+ ...modifiedFields ,
109
126
{
110
127
name : 'custom' ,
111
128
type : 'text' ,
Original file line number Diff line number Diff line change @@ -301,7 +301,6 @@ export interface FormSubmission {
301
301
id ?: string | null ;
302
302
} [ ]
303
303
| null ;
304
- custom ?: string | null ;
305
304
payment ?: {
306
305
field ?: string | null ;
307
306
status ?: string | null ;
@@ -312,7 +311,9 @@ export interface FormSubmission {
312
311
brand ?: string | null ;
313
312
number ?: string | null ;
314
313
} ;
314
+ stripeCheckoutSession ?: string | null ;
315
315
} ;
316
+ custom ?: string | null ;
316
317
updatedAt : string ;
317
318
createdAt : string ;
318
319
}
@@ -584,7 +585,6 @@ export interface FormSubmissionsSelect<T extends boolean = true> {
584
585
value ?: T ;
585
586
id ?: T ;
586
587
} ;
587
- custom ?: T ;
588
588
payment ?:
589
589
| T
590
590
| {
@@ -599,7 +599,9 @@ export interface FormSubmissionsSelect<T extends boolean = true> {
599
599
brand ?: T ;
600
600
number ?: T ;
601
601
} ;
602
+ stripeCheckoutSession ?: T ;
602
603
} ;
604
+ custom ?: T ;
603
605
updatedAt ?: T ;
604
606
createdAt ?: T ;
605
607
}
You can’t perform that action at this time.
0 commit comments