@payloadcms/plugin-form-builder 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collections/FormSubmissions/hooks/createCharge.d.ts.map +1 -1
- package/dist/collections/FormSubmissions/hooks/createCharge.js.map +1 -1
- package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts +4 -1
- package/dist/collections/FormSubmissions/hooks/sendEmail.d.ts.map +1 -1
- package/dist/collections/FormSubmissions/hooks/sendEmail.js +8 -8
- package/dist/collections/FormSubmissions/hooks/sendEmail.js.map +1 -1
- package/dist/collections/FormSubmissions/index.d.ts +1 -1
- package/dist/collections/FormSubmissions/index.d.ts.map +1 -1
- package/dist/collections/FormSubmissions/index.js +64 -60
- package/dist/collections/FormSubmissions/index.js.map +1 -1
- package/dist/collections/Forms/DynamicFieldSelector.d.ts +4 -2
- package/dist/collections/Forms/DynamicFieldSelector.d.ts.map +1 -1
- package/dist/collections/Forms/DynamicFieldSelector.js +8 -6
- package/dist/collections/Forms/DynamicFieldSelector.js.map +1 -1
- package/dist/collections/Forms/DynamicPriceSelector.d.ts +2 -3
- package/dist/collections/Forms/DynamicPriceSelector.d.ts.map +1 -1
- package/dist/collections/Forms/DynamicPriceSelector.js +23 -14
- package/dist/collections/Forms/DynamicPriceSelector.js.map +1 -1
- package/dist/collections/Forms/fields.d.ts +2 -2
- package/dist/collections/Forms/fields.d.ts.map +1 -1
- package/dist/collections/Forms/fields.js +2 -5
- package/dist/collections/Forms/fields.js.map +1 -1
- package/dist/collections/Forms/index.d.ts +1 -1
- package/dist/collections/Forms/index.d.ts.map +1 -1
- package/dist/collections/Forms/index.js +155 -146
- package/dist/collections/Forms/index.js.map +1 -1
- package/dist/exports/client.d.ts +3 -0
- package/dist/exports/client.d.ts.map +1 -0
- package/dist/exports/client.js +4 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -15
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +32 -18
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/getPaymentTotal.d.ts +2 -2
- package/dist/utilities/getPaymentTotal.d.ts.map +1 -1
- package/dist/utilities/getPaymentTotal.js +4 -4
- package/dist/utilities/getPaymentTotal.js.map +1 -1
- package/dist/utilities/keyValuePairToHtmlTable.d.ts +4 -0
- package/dist/utilities/keyValuePairToHtmlTable.d.ts.map +1 -0
- package/dist/utilities/keyValuePairToHtmlTable.js +10 -0
- package/dist/utilities/keyValuePairToHtmlTable.js.map +1 -0
- package/dist/utilities/lexical/converters/heading.js.map +1 -1
- package/dist/utilities/lexical/converters/linebreak.js.map +1 -1
- package/dist/utilities/lexical/converters/link.js.map +1 -1
- package/dist/utilities/lexical/converters/list.js.map +1 -1
- package/dist/utilities/lexical/converters/paragraph.js.map +1 -1
- package/dist/utilities/lexical/converters/quote.js.map +1 -1
- package/dist/utilities/lexical/converters/text.js.map +1 -1
- package/dist/utilities/lexical/defaultConverters.js.map +1 -1
- package/dist/utilities/lexical/nodeFormat.js.map +1 -1
- package/dist/utilities/lexical/serializeLexical.js.map +1 -1
- package/dist/utilities/lexical/types.d.ts +2 -2
- package/dist/utilities/lexical/types.d.ts.map +1 -1
- package/dist/utilities/lexical/types.js.map +1 -1
- package/dist/utilities/replaceDoubleCurlys.d.ts.map +1 -1
- package/dist/utilities/replaceDoubleCurlys.js +18 -2
- package/dist/utilities/replaceDoubleCurlys.js.map +1 -1
- package/dist/utilities/slate/serializeSlate.d.ts.map +1 -1
- package/dist/utilities/slate/serializeSlate.js +19 -19
- package/dist/utilities/slate/serializeSlate.js.map +1 -1
- package/license.md +22 -0
- package/package.json +35 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createCharge.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAEhE,eAAO,MAAM,YAAY,qBACL,GAAG,cACT,uBAAuB,KAClC,
|
|
1
|
+
{"version":3,"file":"createCharge.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAEhE,eAAO,MAAM,YAAY,qBACL,GAAG,cACT,uBAAuB,KAClC,OAAO,CAAC,GAAG,CAeb,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"sourcesContent":["import type { FormBuilderPluginConfig } from '../../../types.js'\n\nexport const createCharge = async (\n beforeChangeData: any,\n formConfig: FormBuilderPluginConfig,\n): Promise<any> => {\n const { data, operation } = beforeChangeData\n\n let dataWithPaymentDetails = data\n\n if (operation === 'create') {\n const { handlePayment } = formConfig || {}\n\n if (typeof handlePayment === 'function') {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n dataWithPaymentDetails = await handlePayment(beforeChangeData)\n }\n }\n\n return dataWithPaymentDetails\n}\n"],"names":["createCharge","beforeChangeData","formConfig","data","operation","dataWithPaymentDetails","handlePayment"],"
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/createCharge.ts"],"sourcesContent":["import type { FormBuilderPluginConfig } from '../../../types.js'\n\nexport const createCharge = async (\n beforeChangeData: any,\n formConfig: FormBuilderPluginConfig,\n): Promise<any> => {\n const { data, operation } = beforeChangeData\n\n let dataWithPaymentDetails = data\n\n if (operation === 'create') {\n const { handlePayment } = formConfig || {}\n\n if (typeof handlePayment === 'function') {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n dataWithPaymentDetails = await handlePayment(beforeChangeData)\n }\n }\n\n return dataWithPaymentDetails\n}\n"],"names":["createCharge","beforeChangeData","formConfig","data","operation","dataWithPaymentDetails","handlePayment"],"mappings":"AAEA,OAAO,MAAMA,eAAe,OAC1BC,kBACAC;IAEA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAE,GAAGH;IAE5B,IAAII,yBAAyBF;IAE7B,IAAIC,cAAc,UAAU;QAC1B,MAAM,EAAEE,aAAa,EAAE,GAAGJ,cAAc,CAAC;QAEzC,IAAI,OAAOI,kBAAkB,YAAY;YACvC,6DAA6D;YAC7DD,yBAAyB,MAAMC,cAAcL;QAC/C;IACF;IAEA,OAAOI;AACT,EAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import type { CollectionBeforeChangeHook } from 'payload';
|
|
1
2
|
import type { FormBuilderPluginConfig } from '../../../types.js';
|
|
2
|
-
|
|
3
|
+
type BeforeChangeParams = Parameters<CollectionBeforeChangeHook>[0];
|
|
4
|
+
export declare const sendEmail: (beforeChangeParameters: BeforeChangeParams, formConfig: FormBuilderPluginConfig) => Promise<BeforeChangeParams["data"]>;
|
|
5
|
+
export {};
|
|
3
6
|
//# sourceMappingURL=sendEmail.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sendEmail.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"sendEmail.d.ts","sourceRoot":"","sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAEzD,OAAO,KAAK,EAAyB,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAMvF,KAAK,kBAAkB,GAAG,UAAU,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnE,eAAO,MAAM,SAAS,2BACI,kBAAkB,cAC9B,uBAAuB,KAClC,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,CA6FpC,CAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { serializeLexical } from '../../../utilities/lexical/serializeLexical.js';
|
|
2
2
|
import { replaceDoubleCurlys } from '../../../utilities/replaceDoubleCurlys.js';
|
|
3
3
|
import { serializeSlate } from '../../../utilities/slate/serializeSlate.js';
|
|
4
|
-
export const sendEmail = async (
|
|
5
|
-
const { data, operation, req } =
|
|
4
|
+
export const sendEmail = async (beforeChangeParameters, formConfig)=>{
|
|
5
|
+
const { data, operation, req } = beforeChangeParameters;
|
|
6
6
|
if (operation === 'create') {
|
|
7
|
-
const { data: { id: formSubmissionID }, req: { locale, payload } } =
|
|
7
|
+
const { data: { id: formSubmissionID }, req: { locale, payload } } = beforeChangeParameters;
|
|
8
8
|
const { form: formID, submissionData } = data || {};
|
|
9
|
-
const { beforeEmail, formOverrides } = formConfig || {};
|
|
9
|
+
const { beforeEmail, defaultToEmail, formOverrides } = formConfig || {};
|
|
10
10
|
try {
|
|
11
11
|
const form = await payload.findByID({
|
|
12
12
|
id: formID,
|
|
@@ -14,10 +14,11 @@ export const sendEmail = async (beforeChangeData, formConfig)=>{
|
|
|
14
14
|
locale,
|
|
15
15
|
req
|
|
16
16
|
});
|
|
17
|
-
const
|
|
17
|
+
const emails = form.emails;
|
|
18
18
|
if (emails && emails.length) {
|
|
19
19
|
const formattedEmails = await Promise.all(emails.map(async (email)=>{
|
|
20
|
-
const { bcc: emailBCC, cc: emailCC, emailFrom, emailTo, message, replyTo: emailReplyTo, subject } = email;
|
|
20
|
+
const { bcc: emailBCC, cc: emailCC, emailFrom, emailTo: emailToFromConfig, message, replyTo: emailReplyTo, subject } = email;
|
|
21
|
+
const emailTo = emailToFromConfig || defaultToEmail || payload.email.defaultFromAddress;
|
|
21
22
|
const to = replaceDoubleCurlys(emailTo, submissionData);
|
|
22
23
|
const cc = emailCC ? replaceDoubleCurlys(emailCC, submissionData) : '';
|
|
23
24
|
const bcc = emailBCC ? replaceDoubleCurlys(emailBCC, submissionData) : '';
|
|
@@ -37,9 +38,8 @@ export const sendEmail = async (beforeChangeData, formConfig)=>{
|
|
|
37
38
|
}));
|
|
38
39
|
let emailsToSend = formattedEmails;
|
|
39
40
|
if (typeof beforeEmail === 'function') {
|
|
40
|
-
emailsToSend = await beforeEmail(formattedEmails);
|
|
41
|
+
emailsToSend = await beforeEmail(formattedEmails, beforeChangeParameters);
|
|
41
42
|
}
|
|
42
|
-
// const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest }))
|
|
43
43
|
await Promise.all(emailsToSend.map(async (email)=>{
|
|
44
44
|
const { to } = email;
|
|
45
45
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"sourcesContent":["import type { Email,
|
|
1
|
+
{"version":3,"sources":["../../../../src/collections/FormSubmissions/hooks/sendEmail.ts"],"sourcesContent":["import type { CollectionBeforeChangeHook } from 'payload'\n\nimport type { Email, FormattedEmail, FormBuilderPluginConfig } from '../../../types.js'\n\nimport { serializeLexical } from '../../../utilities/lexical/serializeLexical.js'\nimport { replaceDoubleCurlys } from '../../../utilities/replaceDoubleCurlys.js'\nimport { serializeSlate } from '../../../utilities/slate/serializeSlate.js'\n\ntype BeforeChangeParams = Parameters<CollectionBeforeChangeHook>[0]\n\nexport const sendEmail = async (\n beforeChangeParameters: BeforeChangeParams,\n formConfig: FormBuilderPluginConfig,\n): Promise<BeforeChangeParams['data']> => {\n const { data, operation, req } = beforeChangeParameters\n\n if (operation === 'create') {\n const {\n data: { id: formSubmissionID },\n req: { locale, payload },\n } = beforeChangeParameters\n\n const { form: formID, submissionData } = data || {}\n\n const { beforeEmail, defaultToEmail, formOverrides } = formConfig || {}\n\n try {\n const form = await payload.findByID({\n id: formID,\n collection: formOverrides?.slug || 'forms',\n locale,\n req,\n })\n\n const emails = form.emails as Email[]\n\n if (emails && emails.length) {\n const formattedEmails: FormattedEmail[] = await Promise.all(\n emails.map(async (email: Email): Promise<FormattedEmail | null> => {\n const {\n bcc: emailBCC,\n cc: emailCC,\n emailFrom,\n emailTo: emailToFromConfig,\n message,\n replyTo: emailReplyTo,\n subject,\n } = email\n\n const emailTo = emailToFromConfig || defaultToEmail || payload.email.defaultFromAddress\n\n const to = replaceDoubleCurlys(emailTo, submissionData)\n const cc = emailCC ? replaceDoubleCurlys(emailCC, submissionData) : ''\n const bcc = emailBCC ? replaceDoubleCurlys(emailBCC, submissionData) : ''\n const from = replaceDoubleCurlys(emailFrom, submissionData)\n const replyTo = replaceDoubleCurlys(emailReplyTo || emailFrom, submissionData)\n\n const isLexical = message && !Array.isArray(message) && 'root' in message\n\n const serializedMessage = isLexical\n ? await serializeLexical(message, submissionData)\n : serializeSlate(message, submissionData)\n\n return {\n bcc,\n cc,\n from,\n html: `<div>${serializedMessage}</div>`,\n replyTo,\n subject: replaceDoubleCurlys(subject, submissionData),\n to,\n }\n }),\n )\n\n let emailsToSend = formattedEmails\n\n if (typeof beforeEmail === 'function') {\n emailsToSend = await beforeEmail(formattedEmails, beforeChangeParameters)\n }\n\n await Promise.all(\n emailsToSend.map(async (email) => {\n const { to } = email\n try {\n const emailPromise = await payload.sendEmail(email)\n return emailPromise\n } catch (err: unknown) {\n payload.logger.error({\n err: `Error while sending email to address: ${to}. Email not sent: ${JSON.stringify(\n err,\n )}`,\n })\n }\n }),\n )\n } else {\n payload.logger.info({ msg: 'No emails to send.' })\n }\n } catch (err: unknown) {\n const msg = `Error while sending one or more emails in form submission id: ${formSubmissionID}.`\n payload.logger.error({ err: msg })\n }\n }\n\n return data\n}\n"],"names":["serializeLexical","replaceDoubleCurlys","serializeSlate","sendEmail","beforeChangeParameters","formConfig","data","operation","req","id","formSubmissionID","locale","payload","form","formID","submissionData","beforeEmail","defaultToEmail","formOverrides","findByID","collection","slug","emails","length","formattedEmails","Promise","all","map","email","bcc","emailBCC","cc","emailCC","emailFrom","emailTo","emailToFromConfig","message","replyTo","emailReplyTo","subject","defaultFromAddress","to","from","isLexical","Array","isArray","serializedMessage","html","emailsToSend","emailPromise","err","logger","error","JSON","stringify","info","msg"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,iDAAgD;AACjF,SAASC,mBAAmB,QAAQ,4CAA2C;AAC/E,SAASC,cAAc,QAAQ,6CAA4C;AAI3E,OAAO,MAAMC,YAAY,OACvBC,wBACAC;IAEA,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,GAAG,EAAE,GAAGJ;IAEjC,IAAIG,cAAc,UAAU;QAC1B,MAAM,EACJD,MAAM,EAAEG,IAAIC,gBAAgB,EAAE,EAC9BF,KAAK,EAAEG,MAAM,EAAEC,OAAO,EAAE,EACzB,GAAGR;QAEJ,MAAM,EAAES,MAAMC,MAAM,EAAEC,cAAc,EAAE,GAAGT,QAAQ,CAAC;QAElD,MAAM,EAAEU,WAAW,EAAEC,cAAc,EAAEC,aAAa,EAAE,GAAGb,cAAc,CAAC;QAEtE,IAAI;YACF,MAAMQ,OAAO,MAAMD,QAAQO,QAAQ,CAAC;gBAClCV,IAAIK;gBACJM,YAAYF,eAAeG,QAAQ;gBACnCV;gBACAH;YACF;YAEA,MAAMc,SAAST,KAAKS,MAAM;YAE1B,IAAIA,UAAUA,OAAOC,MAAM,EAAE;gBAC3B,MAAMC,kBAAoC,MAAMC,QAAQC,GAAG,CACzDJ,OAAOK,GAAG,CAAC,OAAOC;oBAChB,MAAM,EACJC,KAAKC,QAAQ,EACbC,IAAIC,OAAO,EACXC,SAAS,EACTC,SAASC,iBAAiB,EAC1BC,OAAO,EACPC,SAASC,YAAY,EACrBC,OAAO,EACR,GAAGX;oBAEJ,MAAMM,UAAUC,qBAAqBlB,kBAAkBL,QAAQgB,KAAK,CAACY,kBAAkB;oBAEvF,MAAMC,KAAKxC,oBAAoBiC,SAASnB;oBACxC,MAAMgB,KAAKC,UAAU/B,oBAAoB+B,SAASjB,kBAAkB;oBACpE,MAAMc,MAAMC,WAAW7B,oBAAoB6B,UAAUf,kBAAkB;oBACvE,MAAM2B,OAAOzC,oBAAoBgC,WAAWlB;oBAC5C,MAAMsB,UAAUpC,oBAAoBqC,gBAAgBL,WAAWlB;oBAE/D,MAAM4B,YAAYP,WAAW,CAACQ,MAAMC,OAAO,CAACT,YAAY,UAAUA;oBAElE,MAAMU,oBAAoBH,YACtB,MAAM3C,iBAAiBoC,SAASrB,kBAChCb,eAAekC,SAASrB;oBAE5B,OAAO;wBACLc;wBACAE;wBACAW;wBACAK,MAAM,CAAC,KAAK,EAAED,kBAAkB,MAAM,CAAC;wBACvCT;wBACAE,SAAStC,oBAAoBsC,SAASxB;wBACtC0B;oBACF;gBACF;gBAGF,IAAIO,eAAexB;gBAEnB,IAAI,OAAOR,gBAAgB,YAAY;oBACrCgC,eAAe,MAAMhC,YAAYQ,iBAAiBpB;gBACpD;gBAEA,MAAMqB,QAAQC,GAAG,CACfsB,aAAarB,GAAG,CAAC,OAAOC;oBACtB,MAAM,EAAEa,EAAE,EAAE,GAAGb;oBACf,IAAI;wBACF,MAAMqB,eAAe,MAAMrC,QAAQT,SAAS,CAACyB;wBAC7C,OAAOqB;oBACT,EAAE,OAAOC,KAAc;wBACrBtC,QAAQuC,MAAM,CAACC,KAAK,CAAC;4BACnBF,KAAK,CAAC,sCAAsC,EAAET,GAAG,kBAAkB,EAAEY,KAAKC,SAAS,CACjFJ,KACA,CAAC;wBACL;oBACF;gBACF;YAEJ,OAAO;gBACLtC,QAAQuC,MAAM,CAACI,IAAI,CAAC;oBAAEC,KAAK;gBAAqB;YAClD;QACF,EAAE,OAAON,KAAc;YACrB,MAAMM,MAAM,CAAC,8DAA8D,EAAE9C,iBAAiB,CAAC,CAAC;YAChGE,QAAQuC,MAAM,CAACC,KAAK,CAAC;gBAAEF,KAAKM;YAAI;QAClC;IACF;IAEA,OAAOlD;AACT,EAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig } from 'payload
|
|
1
|
+
import type { CollectionConfig } from 'payload';
|
|
2
2
|
import type { FormBuilderPluginConfig } from '../../types.js';
|
|
3
3
|
export declare const generateSubmissionCollection: (formConfig: FormBuilderPluginConfig) => CollectionConfig;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/FormSubmissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/collections/FormSubmissions/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;AAM7D,eAAO,MAAM,4BAA4B,eAC3B,uBAAuB,KAClC,gBA+JF,CAAA"}
|
|
@@ -3,6 +3,67 @@ import { sendEmail } from './hooks/sendEmail.js';
|
|
|
3
3
|
// all settings can be overridden by the config
|
|
4
4
|
export const generateSubmissionCollection = (formConfig)=>{
|
|
5
5
|
const formSlug = formConfig?.formOverrides?.slug || 'forms';
|
|
6
|
+
const defaultFields = [
|
|
7
|
+
{
|
|
8
|
+
name: 'form',
|
|
9
|
+
type: 'relationship',
|
|
10
|
+
admin: {
|
|
11
|
+
readOnly: true
|
|
12
|
+
},
|
|
13
|
+
relationTo: formSlug,
|
|
14
|
+
required: true,
|
|
15
|
+
validate: async (value, { req: { payload }, req })=>{
|
|
16
|
+
/* Don't run in the client side */ if (!payload) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
if (payload) {
|
|
20
|
+
let _existingForm;
|
|
21
|
+
try {
|
|
22
|
+
_existingForm = await payload.findByID({
|
|
23
|
+
id: value,
|
|
24
|
+
collection: formSlug,
|
|
25
|
+
req
|
|
26
|
+
});
|
|
27
|
+
return true;
|
|
28
|
+
} catch (error) {
|
|
29
|
+
return 'Cannot create this submission because this form does not exist.';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'submissionData',
|
|
36
|
+
type: 'array',
|
|
37
|
+
admin: {
|
|
38
|
+
readOnly: true
|
|
39
|
+
},
|
|
40
|
+
fields: [
|
|
41
|
+
{
|
|
42
|
+
name: 'field',
|
|
43
|
+
type: 'text',
|
|
44
|
+
required: true
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'value',
|
|
48
|
+
type: 'text',
|
|
49
|
+
required: true,
|
|
50
|
+
validate: (value)=>{
|
|
51
|
+
// TODO:
|
|
52
|
+
// create a validation function that dynamically
|
|
53
|
+
// relies on the field type and its options as configured.
|
|
54
|
+
// How to access sibling data from this field?
|
|
55
|
+
// Need the `name` of the field in order to validate it.
|
|
56
|
+
// Might not be possible to use this validation function.
|
|
57
|
+
// Instead, might need to do all validation in a `beforeValidate` collection hook.
|
|
58
|
+
if (typeof value !== 'undefined') {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return 'This field is required.';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
];
|
|
6
67
|
const newConfig = {
|
|
7
68
|
...formConfig?.formSubmissionOverrides || {},
|
|
8
69
|
slug: formConfig?.formSubmissionOverrides?.slug || 'form-submissions',
|
|
@@ -16,66 +77,9 @@ export const generateSubmissionCollection = (formConfig)=>{
|
|
|
16
77
|
...formConfig?.formSubmissionOverrides?.admin || {},
|
|
17
78
|
enableRichTextRelationship: false
|
|
18
79
|
},
|
|
19
|
-
fields:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
type: 'relationship',
|
|
23
|
-
admin: {
|
|
24
|
-
readOnly: true
|
|
25
|
-
},
|
|
26
|
-
relationTo: formSlug,
|
|
27
|
-
required: true,
|
|
28
|
-
validate: async (value, { req: { payload }, req })=>{
|
|
29
|
-
/* Don't run in the client side */ if (!payload) return true;
|
|
30
|
-
if (payload) {
|
|
31
|
-
let _existingForm;
|
|
32
|
-
try {
|
|
33
|
-
_existingForm = await payload.findByID({
|
|
34
|
-
id: value,
|
|
35
|
-
collection: formSlug,
|
|
36
|
-
req
|
|
37
|
-
});
|
|
38
|
-
return true;
|
|
39
|
-
} catch (error) {
|
|
40
|
-
return 'Cannot create this submission because this form does not exist.';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
name: 'submissionData',
|
|
47
|
-
type: 'array',
|
|
48
|
-
admin: {
|
|
49
|
-
readOnly: true
|
|
50
|
-
},
|
|
51
|
-
fields: [
|
|
52
|
-
{
|
|
53
|
-
name: 'field',
|
|
54
|
-
type: 'text',
|
|
55
|
-
required: true
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
name: 'value',
|
|
59
|
-
type: 'text',
|
|
60
|
-
required: true,
|
|
61
|
-
validate: (value)=>{
|
|
62
|
-
// TODO:
|
|
63
|
-
// create a validation function that dynamically
|
|
64
|
-
// relies on the field type and its options as configured.
|
|
65
|
-
// How to access sibling data from this field?
|
|
66
|
-
// Need the `name` of the field in order to validate it.
|
|
67
|
-
// Might not be possible to use this validation function.
|
|
68
|
-
// Instead, might need to do all validation in a `beforeValidate` collection hook.
|
|
69
|
-
if (typeof value !== 'undefined') {
|
|
70
|
-
return true;
|
|
71
|
-
}
|
|
72
|
-
return 'This field is required.';
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
},
|
|
77
|
-
...formConfig?.formSubmissionOverrides?.fields || []
|
|
78
|
-
],
|
|
80
|
+
fields: formConfig?.formSubmissionOverrides?.fields && typeof formConfig?.formSubmissionOverrides?.fields === 'function' ? formConfig.formSubmissionOverrides.fields({
|
|
81
|
+
defaultFields
|
|
82
|
+
}) : defaultFields,
|
|
79
83
|
hooks: {
|
|
80
84
|
...formConfig?.formSubmissionOverrides?.hooks || {},
|
|
81
85
|
beforeChange: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/FormSubmissions/index.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/FormSubmissions/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { FormBuilderPluginConfig } from '../../types.js'\n\nimport { createCharge } from './hooks/createCharge.js'\nimport { sendEmail } from './hooks/sendEmail.js'\n\n// all settings can be overridden by the config\nexport const generateSubmissionCollection = (\n formConfig: FormBuilderPluginConfig,\n): CollectionConfig => {\n const formSlug = formConfig?.formOverrides?.slug || 'forms'\n\n const defaultFields: Field[] = [\n {\n name: 'form',\n type: 'relationship',\n admin: {\n readOnly: true,\n },\n relationTo: formSlug,\n required: true,\n validate: async (value, { req: { payload }, req }) => {\n /* Don't run in the client side */\n if (!payload) {\n return true\n }\n\n if (payload) {\n let _existingForm\n\n try {\n _existingForm = await payload.findByID({\n id: value,\n collection: formSlug,\n req,\n })\n\n return true\n } catch (error) {\n return 'Cannot create this submission because this form does not exist.'\n }\n }\n },\n },\n {\n name: 'submissionData',\n type: 'array',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n required: true,\n },\n {\n name: 'value',\n type: 'text',\n required: true,\n validate: (value: unknown) => {\n // TODO:\n // create a validation function that dynamically\n // relies on the field type and its options as configured.\n\n // How to access sibling data from this field?\n // Need the `name` of the field in order to validate it.\n\n // Might not be possible to use this validation function.\n // Instead, might need to do all validation in a `beforeValidate` collection hook.\n\n if (typeof value !== 'undefined') {\n return true\n }\n\n return 'This field is required.'\n },\n },\n ],\n },\n ]\n\n const newConfig: CollectionConfig = {\n ...(formConfig?.formSubmissionOverrides || {}),\n slug: formConfig?.formSubmissionOverrides?.slug || 'form-submissions',\n access: {\n create: () => true,\n read: ({ req: { user } }) => !!user, // logged-in users,\n update: () => false,\n ...(formConfig?.formSubmissionOverrides?.access || {}),\n },\n admin: {\n ...(formConfig?.formSubmissionOverrides?.admin || {}),\n enableRichTextRelationship: false,\n },\n fields:\n formConfig?.formSubmissionOverrides?.fields &&\n typeof formConfig?.formSubmissionOverrides?.fields === 'function'\n ? formConfig.formSubmissionOverrides.fields({ defaultFields })\n : defaultFields,\n hooks: {\n ...(formConfig?.formSubmissionOverrides?.hooks || {}),\n beforeChange: [\n (data) => createCharge(data, formConfig),\n (data) => sendEmail(data, formConfig),\n ...(formConfig?.formSubmissionOverrides?.hooks?.beforeChange || []),\n ],\n },\n }\n\n const paymentFieldConfig = formConfig?.fields?.payment\n\n if (paymentFieldConfig) {\n newConfig.fields.push({\n name: 'payment',\n type: 'group',\n admin: {\n readOnly: true,\n },\n fields: [\n {\n name: 'field',\n type: 'text',\n label: 'Field',\n },\n {\n name: 'status',\n type: 'text',\n label: 'Status',\n },\n {\n name: 'amount',\n type: 'number',\n admin: {\n description: 'Amount in cents',\n },\n },\n {\n name: 'paymentProcessor',\n type: 'text',\n },\n {\n name: 'creditCard',\n type: 'group',\n fields: [\n {\n name: 'token',\n type: 'text',\n label: 'token',\n },\n {\n name: 'brand',\n type: 'text',\n label: 'Brand',\n },\n {\n name: 'number',\n type: 'text',\n label: 'Number',\n },\n ],\n label: 'Credit Card',\n },\n ],\n })\n }\n\n return newConfig\n}\n"],"names":["createCharge","sendEmail","generateSubmissionCollection","formConfig","formSlug","formOverrides","slug","defaultFields","name","type","admin","readOnly","relationTo","required","validate","value","req","payload","_existingForm","findByID","id","collection","error","fields","newConfig","formSubmissionOverrides","access","create","read","user","update","enableRichTextRelationship","hooks","beforeChange","data","paymentFieldConfig","payment","push","label","description"],"mappings":"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"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SelectFieldClientProps, SelectFieldValidation } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export declare const DynamicFieldSelector: React.FC<
|
|
3
|
+
export declare const DynamicFieldSelector: React.FC<{
|
|
4
|
+
validate: SelectFieldValidation;
|
|
5
|
+
} & SelectFieldClientProps>;
|
|
4
6
|
//# sourceMappingURL=DynamicFieldSelector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicFieldSelector.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"DynamicFieldSelector.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAG5E,OAAO,KAA8B,MAAM,OAAO,CAAA;AAIlD,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC;IAAE,QAAQ,EAAE,qBAAqB,CAAA;CAAE,GAAG,sBAAsB,CAsC7D,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import { useForm } from '@payloadcms/ui
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { SelectField, useForm } from '@payloadcms/ui';
|
|
4
4
|
import React, { useEffect, useState } from 'react';
|
|
5
5
|
export const DynamicFieldSelector = (props)=>{
|
|
6
6
|
const { fields, getDataByPath } = useForm();
|
|
@@ -24,11 +24,13 @@ export const DynamicFieldSelector = (props)=>{
|
|
|
24
24
|
fields,
|
|
25
25
|
getDataByPath
|
|
26
26
|
]);
|
|
27
|
-
|
|
28
|
-
// but the FormFieldBase type has only label?: string, changing FormFieldBase breaks other ui components
|
|
29
|
-
return /*#__PURE__*/ React.createElement(Select, {
|
|
27
|
+
return /*#__PURE__*/ _jsx(SelectField, {
|
|
30
28
|
...props,
|
|
31
|
-
|
|
29
|
+
field: {
|
|
30
|
+
name: props?.field?.name,
|
|
31
|
+
options,
|
|
32
|
+
...props.field || {}
|
|
33
|
+
}
|
|
32
34
|
});
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"sourcesContent":["'use client'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/Forms/DynamicFieldSelector.tsx"],"sourcesContent":["'use client'\n\nimport type { SelectFieldClientProps, SelectFieldValidation } from 'payload'\n\nimport { SelectField, useForm } from '@payloadcms/ui'\nimport React, { useEffect, useState } from 'react'\n\nimport type { SelectFieldOption } from '../../types.js'\n\nexport const DynamicFieldSelector: React.FC<\n { validate: SelectFieldValidation } & SelectFieldClientProps\n> = (props) => {\n const { fields, getDataByPath } = useForm()\n\n const [options, setOptions] = useState<SelectFieldOption[]>([])\n\n useEffect(() => {\n const fields: any[] = getDataByPath('fields')\n\n if (fields) {\n const allNonPaymentFields = fields\n .map((block): null | SelectFieldOption => {\n const { name, blockType, label } = block\n\n if (blockType !== 'payment') {\n return {\n label,\n value: name,\n }\n }\n\n return null\n })\n .filter(Boolean)\n setOptions(allNonPaymentFields)\n }\n }, [fields, getDataByPath])\n\n return (\n <SelectField\n {...props}\n field={{\n name: props?.field?.name,\n options,\n ...(props.field || {}),\n }}\n />\n )\n}\n"],"names":["SelectField","useForm","React","useEffect","useState","DynamicFieldSelector","props","fields","getDataByPath","options","setOptions","allNonPaymentFields","map","block","name","blockType","label","value","filter","Boolean","field"],"mappings":"AAAA;;AAIA,SAASA,WAAW,EAAEC,OAAO,QAAQ,iBAAgB;AACrD,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAIlD,OAAO,MAAMC,uBAET,CAACC;IACH,MAAM,EAAEC,MAAM,EAAEC,aAAa,EAAE,GAAGP;IAElC,MAAM,CAACQ,SAASC,WAAW,GAAGN,SAA8B,EAAE;IAE9DD,UAAU;QACR,MAAMI,SAAgBC,cAAc;QAEpC,IAAID,QAAQ;YACV,MAAMI,sBAAsBJ,OACzBK,GAAG,CAAC,CAACC;gBACJ,MAAM,EAAEC,IAAI,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGH;gBAEnC,IAAIE,cAAc,WAAW;oBAC3B,OAAO;wBACLC;wBACAC,OAAOH;oBACT;gBACF;gBAEA,OAAO;YACT,GACCI,MAAM,CAACC;YACVT,WAAWC;QACb;IACF,GAAG;QAACJ;QAAQC;KAAc;IAE1B,qBACE,KAACR;QACE,GAAGM,KAAK;QACTc,OAAO;YACLN,MAAMR,OAAOc,OAAON;YACpBL;YACA,GAAIH,MAAMc,KAAK,IAAI,CAAC,CAAC;QACvB;;AAGN,EAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const DynamicPriceSelector: React.FC<TextFieldProps>;
|
|
1
|
+
import type { TextFieldClientComponent } from 'payload';
|
|
2
|
+
export declare const DynamicPriceSelector: TextFieldClientComponent;
|
|
4
3
|
//# sourceMappingURL=DynamicPriceSelector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DynamicPriceSelector.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"DynamicPriceSelector.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAQ,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAU7D,eAAO,MAAM,oBAAoB,EAAE,wBA2DlC,CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import { useWatchForm } from '@payloadcms/ui
|
|
4
|
-
import { useLocale } from '@payloadcms/ui/providers/Locale';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { TextField, useLocale, useWatchForm } from '@payloadcms/ui';
|
|
5
4
|
import React, { useEffect, useState } from 'react';
|
|
6
5
|
export const DynamicPriceSelector = (props)=>{
|
|
7
|
-
const {
|
|
6
|
+
const { field, path } = props;
|
|
8
7
|
const { fields, getData, getDataByPath } = useWatchForm();
|
|
9
8
|
const locale = useLocale();
|
|
10
9
|
const [isNumberField, setIsNumberField] = useState();
|
|
@@ -27,25 +26,35 @@ export const DynamicPriceSelector = (props)=>{
|
|
|
27
26
|
}
|
|
28
27
|
}, [
|
|
29
28
|
fields,
|
|
30
|
-
path,
|
|
31
29
|
getDataByPath,
|
|
32
|
-
getData
|
|
30
|
+
getData,
|
|
31
|
+
path
|
|
33
32
|
]);
|
|
34
33
|
// TODO: make this a number field, block by Payload
|
|
35
34
|
if (valueType === 'static') {
|
|
36
|
-
return /*#__PURE__*/
|
|
35
|
+
return /*#__PURE__*/ _jsx(TextField, {
|
|
36
|
+
...props
|
|
37
|
+
});
|
|
37
38
|
}
|
|
38
39
|
const localeCode = typeof locale === 'object' && 'code' in locale ? locale.code : locale;
|
|
39
|
-
const localLabels = typeof label === 'object' ? label : {
|
|
40
|
-
[localeCode]: label
|
|
40
|
+
const localLabels = typeof field.label === 'object' ? field.label : {
|
|
41
|
+
[localeCode]: field.label
|
|
41
42
|
};
|
|
42
43
|
const labelValue = localLabels[localeCode] || localLabels['en'] || '';
|
|
43
44
|
if (valueType === 'valueOfField' && !isNumberField) {
|
|
44
|
-
return /*#__PURE__*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
46
|
+
children: [
|
|
47
|
+
/*#__PURE__*/ _jsx("div", {
|
|
48
|
+
children: String(labelValue)
|
|
49
|
+
}),
|
|
50
|
+
/*#__PURE__*/ _jsx("div", {
|
|
51
|
+
style: {
|
|
52
|
+
color: '#9A9A9A'
|
|
53
|
+
},
|
|
54
|
+
children: "The selected field must be a number field."
|
|
55
|
+
})
|
|
56
|
+
]
|
|
57
|
+
});
|
|
49
58
|
}
|
|
50
59
|
return null;
|
|
51
60
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"sourcesContent":["'use client'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../src/collections/Forms/DynamicPriceSelector.tsx"],"sourcesContent":["'use client'\n\nimport type { Data, TextFieldClientComponent } from 'payload'\n\nimport { TextField, useLocale, useWatchForm } from '@payloadcms/ui'\nimport React, { useEffect, useState } from 'react'\n\ntype FieldWithID = {\n id: string\n name: string\n}\n\nexport const DynamicPriceSelector: TextFieldClientComponent = (props) => {\n const { field, path } = props\n\n const { fields, getData, getDataByPath } = useWatchForm()\n\n const locale = useLocale()\n\n const [isNumberField, setIsNumberField] = useState<boolean>()\n const [valueType, setValueType] = useState<'static' | 'valueOfField'>()\n\n // only number fields can use 'valueOfField`\n useEffect(() => {\n if (path) {\n const parentPath = path.split('.').slice(0, -1).join('.')\n const paymentFieldData: any = getDataByPath(parentPath)\n\n if (paymentFieldData) {\n const { fieldToUse, valueType } = paymentFieldData\n\n setValueType(valueType)\n\n const { fields: allFields }: Data = getData()\n const field = allFields.find((field: FieldWithID) => field.name === fieldToUse)\n\n if (field) {\n const { blockType } = field\n setIsNumberField(blockType === 'number')\n }\n }\n }\n }, [fields, getDataByPath, getData, path])\n\n // TODO: make this a number field, block by Payload\n if (valueType === 'static') {\n return <TextField {...props} />\n }\n\n const localeCode = typeof locale === 'object' && 'code' in locale ? locale.code : locale\n\n const localLabels = typeof field.label === 'object' ? field.label : { [localeCode]: field.label }\n\n const labelValue = localLabels[localeCode] || localLabels['en'] || ''\n\n if (valueType === 'valueOfField' && !isNumberField) {\n return (\n <div>\n <div>{String(labelValue)}</div>\n <div\n style={{\n color: '#9A9A9A',\n }}\n >\n The selected field must be a number field.\n </div>\n </div>\n )\n }\n\n return null\n}\n"],"names":["TextField","useLocale","useWatchForm","React","useEffect","useState","DynamicPriceSelector","props","field","path","fields","getData","getDataByPath","locale","isNumberField","setIsNumberField","valueType","setValueType","parentPath","split","slice","join","paymentFieldData","fieldToUse","allFields","find","name","blockType","localeCode","code","localLabels","label","labelValue","div","String","style","color"],"mappings":"AAAA;;AAIA,SAASA,SAAS,EAAEC,SAAS,EAAEC,YAAY,QAAQ,iBAAgB;AACnE,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAOlD,OAAO,MAAMC,uBAAiD,CAACC;IAC7D,MAAM,EAAEC,KAAK,EAAEC,IAAI,EAAE,GAAGF;IAExB,MAAM,EAAEG,MAAM,EAAEC,OAAO,EAAEC,aAAa,EAAE,GAAGV;IAE3C,MAAMW,SAASZ;IAEf,MAAM,CAACa,eAAeC,iBAAiB,GAAGV;IAC1C,MAAM,CAACW,WAAWC,aAAa,GAAGZ;IAElC,4CAA4C;IAC5CD,UAAU;QACR,IAAIK,MAAM;YACR,MAAMS,aAAaT,KAAKU,KAAK,CAAC,KAAKC,KAAK,CAAC,GAAG,CAAC,GAAGC,IAAI,CAAC;YACrD,MAAMC,mBAAwBV,cAAcM;YAE5C,IAAII,kBAAkB;gBACpB,MAAM,EAAEC,UAAU,EAAEP,SAAS,EAAE,GAAGM;gBAElCL,aAAaD;gBAEb,MAAM,EAAEN,QAAQc,SAAS,EAAE,GAASb;gBACpC,MAAMH,QAAQgB,UAAUC,IAAI,CAAC,CAACjB,QAAuBA,MAAMkB,IAAI,KAAKH;gBAEpE,IAAIf,OAAO;oBACT,MAAM,EAAEmB,SAAS,EAAE,GAAGnB;oBACtBO,iBAAiBY,cAAc;gBACjC;YACF;QACF;IACF,GAAG;QAACjB;QAAQE;QAAeD;QAASF;KAAK;IAEzC,mDAAmD;IACnD,IAAIO,cAAc,UAAU;QAC1B,qBAAO,KAAChB;YAAW,GAAGO,KAAK;;IAC7B;IAEA,MAAMqB,aAAa,OAAOf,WAAW,YAAY,UAAUA,SAASA,OAAOgB,IAAI,GAAGhB;IAElF,MAAMiB,cAAc,OAAOtB,MAAMuB,KAAK,KAAK,WAAWvB,MAAMuB,KAAK,GAAG;QAAE,CAACH,WAAW,EAAEpB,MAAMuB,KAAK;IAAC;IAEhG,MAAMC,aAAaF,WAAW,CAACF,WAAW,IAAIE,WAAW,CAAC,KAAK,IAAI;IAEnE,IAAId,cAAc,kBAAkB,CAACF,eAAe;QAClD,qBACE,MAACmB;;8BACC,KAACA;8BAAKC,OAAOF;;8BACb,KAACC;oBACCE,OAAO;wBACLC,OAAO;oBACT;8BACD;;;;IAKP;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Block } from 'payload
|
|
1
|
+
import type { Block } from 'payload';
|
|
2
2
|
import type { FieldConfig } from '../../types.js';
|
|
3
3
|
export declare const fields: {
|
|
4
|
-
[key: string]:
|
|
4
|
+
[key: string]: ((fieldConfig?: boolean | FieldConfig) => Block) | Block;
|
|
5
5
|
};
|
|
6
6
|
//# sourceMappingURL=fields.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../../src/collections/Forms/fields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAS,MAAM,SAAS,CAAA;AAE3C,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,gBAAgB,CAAA;AAyjBrE,eAAO,MAAM,MAAM,EAWd;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAA;CACxE,CAAA"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { DynamicFieldSelector } from './DynamicFieldSelector.js';
|
|
2
|
-
import { DynamicPriceSelector } from './DynamicPriceSelector.js';
|
|
3
1
|
const name = {
|
|
4
2
|
name: 'name',
|
|
5
3
|
type: 'text',
|
|
@@ -436,7 +434,7 @@ const Payment = (fieldConfig)=>{
|
|
|
436
434
|
type: 'text',
|
|
437
435
|
admin: {
|
|
438
436
|
components: {
|
|
439
|
-
Field: DynamicFieldSelector
|
|
437
|
+
Field: '@payloadcms/plugin-form-builder/client#DynamicFieldSelector'
|
|
440
438
|
}
|
|
441
439
|
}
|
|
442
440
|
},
|
|
@@ -515,7 +513,7 @@ const Payment = (fieldConfig)=>{
|
|
|
515
513
|
type: 'text',
|
|
516
514
|
admin: {
|
|
517
515
|
components: {
|
|
518
|
-
Field: DynamicPriceSelector
|
|
516
|
+
Field: '@payloadcms/plugin-form-builder/client#DynamicPriceSelector'
|
|
519
517
|
}
|
|
520
518
|
},
|
|
521
519
|
label: 'Value'
|
|
@@ -550,7 +548,6 @@ const Message = {
|
|
|
550
548
|
singular: 'Message'
|
|
551
549
|
}
|
|
552
550
|
};
|
|
553
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
554
551
|
export const fields = {
|
|
555
552
|
checkbox: Checkbox,
|
|
556
553
|
country: Country,
|