Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

2.3 KB
Raw Blame
/** @jsxImportSource @webstudio-is/template */
import {
  ActionValue,
  css,
  expression,
  PlaceholderValue,
  setInstanceMeta,
  Variable,
  type TemplateMeta,
} from "@webstudio-is/template";
import type { ReactNode } from "react";
import { WebhookForm } from "./components";

const formState = new Variable("formState", "initial");

/** @deprecated Use the Form component for new forms. */
export const meta: TemplateMeta = {
  category: "data",
  order: 1,
  label: "Webhook Form (Deprecated)",
  description:
    "Deprecated. Existing Webhook Forms remain supported through the next release. Use the new Form component in the Forms section instead.",
  template: (
    <WebhookForm
      state={expression`${formState}`}
      onStateChange={
        new ActionValue(["state"], expression`${formState} = state`)
      }
    >
      {setInstanceMeta(
        { label: "Form content" },
        <div
          ws:show={expression`${formState} === 'initial' || ${formState} === 'error'`}
        >
          <label
            ws:style={css`
              display: block;
            `}
          >
            {new PlaceholderValue("Name") as unknown as ReactNode}
          </label>
          <input
            ws:style={css`
              display: block;
            `}
            name="name"
          />
          <label
            ws:style={css`
              display: block;
            `}
          >
            {new PlaceholderValue("Email") as unknown as ReactNode}
          </label>
          <input
            ws:style={css`
              display: block;
            `}
            name="email"
          />
          <button>
            {new PlaceholderValue("Submit") as unknown as ReactNode}
          </button>
        </div>
      )}
      {setInstanceMeta(
        { label: "Success message" },
        <div ws:show={expression`${formState} === 'success'`}>
          {
            new PlaceholderValue(
              "Thank you for getting in touch!"
            ) as unknown as ReactNode
          }
        </div>
      )}
      {setInstanceMeta(
        { label: "Error message" },
        <div ws:show={expression`${formState} === 'error'`}>
          {
            new PlaceholderValue(
              "Sorry, something went wrong."
            ) as unknown as ReactNode
          }
        </div>
      )}
    </WebhookForm>
  ),
};