@stackshift-ui/webriq-form 1.0.0 → 6.0.3

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,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/webriq-form",
3
3
  "description": "",
4
- "version": "1.0.0",
4
+ "version": "6.0.3",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
10
10
  "files": [
11
- "dist/**"
11
+ "dist/**",
12
+ "src"
12
13
  ],
13
14
  "author": "WebriQ <info@webriq.com>",
14
15
  "devDependencies": {
@@ -28,12 +29,12 @@
28
29
  "typescript": "^5.6.2",
29
30
  "vite-tsconfig-paths": "^5.0.1",
30
31
  "vitest": "^2.1.1",
31
- "@stackshift-ui/typescript-config": "2.0.0",
32
- "@stackshift-ui/eslint-config": "1.0.0"
32
+ "@stackshift-ui/eslint-config": "6.0.2",
33
+ "@stackshift-ui/typescript-config": "6.0.2"
33
34
  },
34
35
  "dependencies": {
35
- "@stackshift-ui/scripts": "1.0.0",
36
- "@stackshift-ui/system": "2.0.0"
36
+ "@stackshift-ui/scripts": "6.0.2",
37
+ "@stackshift-ui/system": "6.0.3"
37
38
  },
38
39
  "peerDependencies": {
39
40
  "@types/react": "16.8 - 19",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./webriq-form";
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { WebriQForm } from "./webriq-form";
4
+
5
+ describe.concurrent("webriq-form", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: WebriQ Form - test if renders without errors", ({ expect }) => {
9
+ const clx = "webriqform-class";
10
+ render(<WebriQForm className={clx} />);
11
+ expect(screen.getByTestId("webriq-form").classList).toContain(clx);
12
+ });
13
+ });
@@ -0,0 +1,95 @@
1
+ import React from "react";
2
+
3
+ declare global {
4
+ interface Window {
5
+ isWebriQFormLoaded?: boolean;
6
+ webriqFormRefresh?: () => void;
7
+ }
8
+ }
9
+
10
+ interface WebriQFormProps {
11
+ id?: string;
12
+ name?: string;
13
+ className?: string;
14
+ formId?: string;
15
+ redirectUrl?: string;
16
+ scriptSrc?: string;
17
+ unmountScript?: boolean;
18
+ children?: React.ReactNode;
19
+ [key: string]: any;
20
+ webriq?: string;
21
+ }
22
+
23
+ class WebriQForm extends React.Component<WebriQFormProps> {
24
+ constructor(props: WebriQFormProps) {
25
+ super(props);
26
+ this.loadWebriQFormScript = this.loadWebriQFormScript.bind(this);
27
+ }
28
+
29
+ componentDidMount() {
30
+ if (window && !window.isWebriQFormLoaded) {
31
+ this.loadWebriQFormScript();
32
+ }
33
+
34
+ if (window && window.isWebriQFormLoaded) {
35
+ window.webriqFormRefresh?.();
36
+ }
37
+ }
38
+
39
+ loadWebriQFormScript() {
40
+ const webriqFormScript = document.getElementById("webriqform");
41
+
42
+ if (!webriqFormScript) {
43
+ const script = document.createElement("script");
44
+ script.type = "text/javascript";
45
+ script.id = "webriqform";
46
+ script.defer = true;
47
+ script.src = this.props.scriptSrc || "https://pagebuilderforms.webriq.com/js/initReactForms";
48
+ document.body.appendChild(script);
49
+ const headScript = document.getElementsByTagName("script")[0];
50
+ headScript.parentNode?.insertBefore(script, headScript);
51
+ }
52
+ }
53
+
54
+ componentWillUnmount() {
55
+ const { unmountScript } = this.props;
56
+
57
+ const webriqFormScript = document.getElementById("webriqform");
58
+ if (webriqFormScript && unmountScript) {
59
+ webriqFormScript.parentNode?.removeChild(webriqFormScript);
60
+ }
61
+
62
+ if (window && unmountScript) {
63
+ window.isWebriQFormLoaded = false;
64
+ }
65
+
66
+ const webriqFormRecaptcha = document.getElementById("webriqFormRecaptcha");
67
+ if (webriqFormRecaptcha && unmountScript) {
68
+ webriqFormRecaptcha.parentNode?.removeChild(webriqFormRecaptcha);
69
+ }
70
+ }
71
+
72
+ render() {
73
+ const { id, name, className, ...rest } = this.props;
74
+ const formId = this.props.formId || this.props["data-form-id"];
75
+ let redirectURL = this.props.redirectUrl || this.props["data-thankyou-url"] || "/thank-you";
76
+
77
+ return (
78
+ <form
79
+ name={name}
80
+ id={id}
81
+ className={className}
82
+ method="POST"
83
+ data-form-id={formId}
84
+ data-testid="webriq-form"
85
+ data-thankyou-url={redirectURL}
86
+ // eslint-disable-next-line react/no-unknown-property
87
+ webriq="true"
88
+ {...rest}>
89
+ {this.props.children}
90
+ </form>
91
+ );
92
+ }
93
+ }
94
+
95
+ export { WebriQForm };