From 6408ae537d1eb60f12e87fffca6aa80fb426dfac Mon Sep 17 00:00:00 2001 From: Jacob Fletcher Date: Mon, 15 May 2023 12:19:41 -0400 Subject: [PATCH] fix: correctly types width fields #37 --- demo/src/payload-types.ts | 205 ++++++++++++++++++++++++++++++++++++++ src/types.ts | 16 +-- 2 files changed, 213 insertions(+), 8 deletions(-) create mode 100644 demo/src/payload-types.ts diff --git a/demo/src/payload-types.ts b/demo/src/payload-types.ts new file mode 100644 index 0000000..43c698f --- /dev/null +++ b/demo/src/payload-types.ts @@ -0,0 +1,205 @@ +/* tslint:disable */ +/** + * This file was automatically generated by Payload CMS. + * DO NOT MODIFY IT BY HAND. Instead, modify your source Payload config, + * and re-run `payload generate:types` to regenerate this file. + */ + +export interface Config { + collections: { + users: User; + pages: Page; + forms: Form; + 'form-submissions': FormSubmission; + }; + globals: {}; +} +export interface User { + id: string; + updatedAt: string; + createdAt: string; + email?: string; + resetPasswordToken?: string; + resetPasswordExpiration?: string; + loginAttempts?: number; + lockUntil?: string; + password?: string; +} +export interface Page { + id: string; + title: string; + form?: string | Form; + updatedAt: string; + createdAt: string; +} +export interface Form { + id: string; + title: string; + fields?: ( + | { + name: string; + label?: string; + width?: number; + defaultValue?: string; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'text'; + } + | { + name: string; + label?: string; + width?: number; + defaultValue?: string; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'textarea'; + } + | { + name: string; + label?: string; + width?: number; + defaultValue?: string; + options: { + label: string; + value: string; + id?: string; + }[]; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'select'; + } + | { + name: string; + label?: string; + width?: number; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'email'; + } + | { + name: string; + label?: string; + width?: number; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'state'; + } + | { + name: string; + label?: string; + width?: number; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'country'; + } + | { + name: string; + label?: string; + width?: number; + defaultValue?: number; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'number'; + } + | { + name: string; + label?: string; + width?: number; + required?: boolean; + defaultValue?: boolean; + id?: string; + blockName?: string; + blockType: 'checkbox'; + } + | { + message?: { + [k: string]: unknown; + }[]; + id?: string; + blockName?: string; + blockType: 'message'; + } + | { + name: string; + label?: string; + width?: number; + basePrice?: number; + priceConditions?: { + fieldToUse?: string; + condition?: 'hasValue' | 'equals' | 'notEquals'; + valueForCondition?: string; + operator?: 'add' | 'subtract' | 'multiply' | 'divide'; + valueType?: 'static' | 'valueOfField'; + valueForOperator?: string; + id?: string; + }[]; + required?: boolean; + id?: string; + blockName?: string; + blockType: 'payment'; + } + | { + value?: string; + id?: string; + blockName?: string; + blockType: 'color'; + } + )[]; + submitButtonLabel?: string; + confirmationType?: 'message' | 'redirect'; + confirmationMessage: { + [k: string]: unknown; + }[]; + redirect?: { + type?: 'reference' | 'custom'; + reference: { + value: string | Page; + relationTo: 'pages'; + }; + url: string; + }; + emails: { + emailTo?: string; + cc?: string; + bcc?: string; + replyTo?: string; + emailFrom?: string; + subject: string; + message?: { + [k: string]: unknown; + }[]; + id?: string; + }[]; + name?: string; + updatedAt: string; + createdAt: string; +} +export interface FormSubmission { + id: string; + form: string | Form; + submissionData: { + field: string; + value: string; + id?: string; + }[]; + payment?: { + field?: string; + status?: string; + amount?: number; + paymentProcessor?: string; + creditCard?: { + token?: string; + brand?: string; + number?: string; + }; + }; + updatedAt: string; + createdAt: string; +} diff --git a/src/types.ts b/src/types.ts index b3db867..46d1d8b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -52,7 +52,7 @@ export interface PluginConfig { export interface TextField { blockType: 'text' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -62,7 +62,7 @@ export interface TextField { export interface TextAreaField { blockType: 'textarea' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -77,7 +77,7 @@ export interface SelectFieldOption { export interface SelectField { blockType: 'select' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -97,7 +97,7 @@ export interface PriceCondition { export interface PaymentField { blockType: 'payment' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -110,7 +110,7 @@ export interface PaymentField { export interface EmailField { blockType: 'email' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -120,7 +120,7 @@ export interface EmailField { export interface StateField { blockType: 'state' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -130,7 +130,7 @@ export interface StateField { export interface CountryField { blockType: 'country' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: string @@ -140,7 +140,7 @@ export interface CountryField { export interface CheckboxField { blockType: 'checkbox' blockName?: string - width?: string + width?: number name: string label?: string defaultValue?: boolean