rankrunners-cms 0.0.35 → 0.0.36

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rankrunners-cms",
3
3
  "type": "module",
4
- "version": "0.0.35",
4
+ "version": "0.0.36",
5
5
  "peerDependencies": {
6
6
  "@puckeditor/core": "^0.21.1",
7
7
  "@tanstack/react-router": "^1.166.7",
@@ -6,7 +6,10 @@ import {
6
6
  } from "valibot";
7
7
  import { CMS_BASE_URL, SITE_ID } from "../constants";
8
8
  import type { FormFillSubmissionDTO } from "../types/form-fills";
9
- import { SendFormFillResult } from "../types/form-fills";
9
+ import {
10
+ type SendFormFillResult,
11
+ SendFormFillResultType,
12
+ } from "../types/form-fills";
10
13
 
11
14
  export type SendFormFillArgs<
12
15
  A,
@@ -33,14 +36,21 @@ export const sendFormFill = async <
33
36
  const formToSend = safeParse(args.schema, args.data);
34
37
 
35
38
  if (!formToSend.success) {
39
+ const errors: Record<string, string> = {};
40
+ formToSend.issues.forEach((issue) => {
41
+ if (issue.path && issue.path[0] && issue.path[0].key) {
42
+ errors[issue.path[0].key as string] = issue.message;
43
+ }
44
+ });
45
+
36
46
  console.error("Form fill validation failed:", formToSend.issues);
37
- return SendFormFillResult.ValidationError;
47
+ return { response: SendFormFillResultType.ValidationError, errors };
38
48
  }
39
49
 
40
50
  const data: FormFillSubmissionDTO = {
41
51
  siteId: SITE_ID,
42
52
  type: args.type,
43
- data: args.data as Record<string, string>,
53
+ data: formToSend.output as Record<string, string>,
44
54
  schema: {
45
55
  schema: JSON.stringify(args.schema),
46
56
  fields: args.fieldNames,
@@ -59,21 +69,22 @@ export const sendFormFill = async <
59
69
  });
60
70
 
61
71
  if (response.ok) {
62
- return SendFormFillResult.Success;
72
+ return { response: SendFormFillResultType.Success };
63
73
  }
64
74
 
65
75
  console.error("Form fill submission failed with status:", response.status);
66
- return SendFormFillResult.UnknownError;
76
+ console.error("Form fill submission:", data);
77
+ return { response: SendFormFillResultType.UnknownError };
67
78
  } catch (error) {
68
79
  console.error("Error sending form fill:", error);
69
80
  if (error instanceof Error) {
70
81
  if (error.message.includes("validation")) {
71
- return SendFormFillResult.ValidationError;
82
+ return { response: SendFormFillResultType.ValidationError };
72
83
  }
73
84
  if (error.message.includes("captcha")) {
74
- return SendFormFillResult.CaptchaError;
85
+ return { response: SendFormFillResultType.CaptchaError };
75
86
  }
76
87
  }
77
- return SendFormFillResult.UnknownError;
88
+ return { response: SendFormFillResultType.UnknownError };
78
89
  }
79
90
  };
@@ -46,7 +46,12 @@ export const FormFillSubmissionSchema = object({
46
46
 
47
47
  export type FormFillSubmissionDTO = InferInput<typeof FormFillSubmissionSchema>;
48
48
 
49
- export enum SendFormFillResult {
49
+ export type SendFormFillResult = {
50
+ response: SendFormFillResultType;
51
+ errors?: Record<string, string>;
52
+ };
53
+
54
+ export enum SendFormFillResultType {
50
55
  Success = "success",
51
56
  ValidationError = "validation_error",
52
57
  CaptchaError = "captcha_error",
@@ -54,17 +59,19 @@ export enum SendFormFillResult {
54
59
  UnknownError = "unknown_error",
55
60
  }
56
61
 
57
- export const formFillResultToMessage = (result: SendFormFillResult): string => {
62
+ export const formFillResultToMessage = (
63
+ result: SendFormFillResultType,
64
+ ): string => {
58
65
  switch (result) {
59
- case SendFormFillResult.Success:
66
+ case SendFormFillResultType.Success:
60
67
  return "Form submitted successfully!";
61
- case SendFormFillResult.ValidationError:
68
+ case SendFormFillResultType.ValidationError:
62
69
  return "There was a validation error with your submission. Please check your input and try again.";
63
- case SendFormFillResult.CaptchaError:
70
+ case SendFormFillResultType.CaptchaError:
64
71
  return "Captcha verification failed. Please complete the captcha and try again.";
65
- case SendFormFillResult.InvalidResponse:
72
+ case SendFormFillResultType.InvalidResponse:
66
73
  return "An internal error occurred while submitting the form. Please call us instead!";
67
- case SendFormFillResult.UnknownError:
74
+ case SendFormFillResultType.UnknownError:
68
75
  default:
69
76
  return "An unknown error occurred while submitting the form. Please try again later, or try calling us!";
70
77
  }