umwd-components 0.1.830 → 0.1.831
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.
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* @copyright Jelle Paulus
|
|
5
5
|
* @license MIT
|
|
6
6
|
*/
|
|
7
|
-
"use strict";var e=require("../../../../lib/utils.js"),
|
|
7
|
+
"use strict";var e=require("zod"),r=require("../../../../lib/utils.js"),s=require("../../../../lib/parseFormData.js");const t=e.z.object({email:e.z.string().email(),name:e.z.string().min(2).max(100),subject:e.z.string().min(2).max(100),message:e.z.string().min(2).max(1e3)});exports.contactFormAction=async function(e,a){Object.fromEntries(a);const o=s.parseFormData(a);console.log("parsedFormData",o);const i=t.safeParse(o);if(!i.success)return{...e,severity:"error",strapiErrors:i.error.format(),message:"Validation Error. Please check your input."};console.log("validatedFields",i);const{data:n}=i,c=await fetch(`${process.env.NEXT_PUBLIC_STRAPI_URL}/api/leads/createFromContactform`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)}).then(e=>e.json());if(console.log("responseData",c),!c)return{...e,severity:"error",strapiErrors:null,message:"Ops! Something went wrong. Please try again."};if(c.error)return{...e,severity:"error",strapiErrors:c.error,message:"Failed to Create Lead."};const l=r.flattenAttributes(c);return{...e,severity:"success",message:"Lead Created Successfully",data:l,strapiErrors:null}};
|