umwd-components 0.1.828 → 0.1.829

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.
@@ -0,0 +1,42 @@
1
+ "use server";
2
+ /*
3
+ * UMWD-Components
4
+ * @copyright Jelle Paulus
5
+ * @license MIT
6
+ */
7
+
8
+ import { mutateData } from '../../../services/mutate-data.js';
9
+ import { flattenAttributes } from '../../../../lib/utils.js';
10
+ import { parseFormData } from '../../../../lib/parseFormData.js';
11
+
12
+ async function contactFormAction(prevState, formData) {
13
+ Object.fromEntries(formData);
14
+ const parsedFormData = parseFormData(formData);
15
+ const responseData = await mutateData("POST", `/api/leads/createFromContactform`, parsedFormData);
16
+ if (!responseData) {
17
+ return {
18
+ ...prevState,
19
+ severity: "error",
20
+ strapiErrors: null,
21
+ message: "Ops! Something went wrong. Please try again.",
22
+ };
23
+ }
24
+ if (responseData.error) {
25
+ return {
26
+ ...prevState,
27
+ severity: "error",
28
+ strapiErrors: responseData.error,
29
+ message: "Failed to Create Lead.",
30
+ };
31
+ }
32
+ const flattenedData = flattenAttributes(responseData);
33
+ return {
34
+ ...prevState,
35
+ severity: "success",
36
+ message: "Lead Created Successfully",
37
+ data: flattenedData,
38
+ strapiErrors: null,
39
+ };
40
+ }
41
+
42
+ export { contactFormAction };
@@ -222,3 +222,4 @@ export { getAllMinioMedia } from './data/loaders/common/media/minio/getAllMinioM
222
222
  export { getAllMinioReferences } from './data/loaders/common/media/minio/getAllMinioReferences.js';
223
223
  export { MinioItemList } from './components/common/media/minio/MinioItemList.js';
224
224
  export { MinioDisplay } from './components/common/media/minio/MinioDisplay.js';
225
+ export { contactFormAction } from './data/actions/e-commerce/lead/contactFormAction.js';