lms/bootstrap/ssr/assets/newsletter-form-RAycnHkp.js
2025-12-15 12:26:23 +01:00

100 lines
3.9 KiB
JavaScript

import { jsxs, jsx } from "react/jsx-runtime";
import { I as InputError } from "./input-error-D1JIzedA.js";
import { L as LoadingButton } from "./loading-button-CCIxhJrY.js";
import { B as Button } from "./button-CdJZJLGw.js";
import { D as Dialog, a as DialogTrigger, b as DialogContent, c as DialogHeader, d as DialogTitle, e as DialogFooter, f as DialogClose } from "./dialog-DGP_3dPQ.js";
import { I as Input } from "./input-BsvJqbcd.js";
import { L as Label } from "./label-0rIIfpX0.js";
import { S as ScrollArea } from "./scroll-area-CDdrLubh.js";
import { o as onHandleChange } from "./inertia-BtwbgBI3.js";
import { useForm } from "@inertiajs/react";
import { useState } from "react";
import { Editor } from "richtor";
/* empty css */
import "./utils-DLCPGU0v.js";
import "clsx";
import "tailwind-merge";
import "lucide-react";
import "@radix-ui/react-slot";
import "class-variance-authority";
import "@radix-ui/react-dialog";
import "@radix-ui/react-label";
import "@radix-ui/react-scroll-area";
const NewsletterForm = ({ title, newsletter, handler, translate }) => {
const [open, setOpen] = useState(false);
const { input, button } = translate || {
input: {
subject: "Subject"
},
button: { close: "Close", submit: "Submit" }
};
const { data, setData, post, put, errors, processing } = useForm({
subject: newsletter ? newsletter.subject : "",
description: newsletter ? newsletter.description : ""
});
const handleSubmit = (e) => {
e.preventDefault();
if (newsletter) {
put(route("newsletters.update", { id: newsletter.id }), {
onSuccess: () => setOpen(false)
});
} else {
post(route("newsletters.store"), {
onSuccess: () => setOpen(false)
});
}
};
return /* @__PURE__ */ jsxs(Dialog, { open, onOpenChange: setOpen, children: [
/* @__PURE__ */ jsx(DialogTrigger, { children: handler }),
/* @__PURE__ */ jsx(DialogContent, { className: "p-0", children: /* @__PURE__ */ jsxs(ScrollArea, { className: "max-h-[90vh] p-6", children: [
/* @__PURE__ */ jsx(DialogHeader, { className: "mb-6", children: /* @__PURE__ */ jsx(DialogTitle, { children: title }) }),
/* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "space-y-4 p-0.5", children: [
/* @__PURE__ */ jsxs("div", { children: [
/* @__PURE__ */ jsx(Label, { children: input.subject }),
/* @__PURE__ */ jsx(
Input,
{
required: true,
type: "text",
name: "subject",
value: data.subject,
placeholder: input.subject,
onChange: (e) => onHandleChange(e, setData)
}
),
/* @__PURE__ */ jsx(InputError, { message: errors.subject })
] }),
/* @__PURE__ */ jsxs("div", { children: [
/* @__PURE__ */ jsx(Label, { children: input.description }),
/* @__PURE__ */ jsx(
Editor,
{
ssr: true,
output: "html",
placeholder: {
paragraph: input.description_placeholder,
imageCaption: input.image_url_placeholder
},
contentMinHeight: 256,
contentMaxHeight: 640,
initialContent: data.description,
onContentChange: (value) => setData((prev) => ({
...prev,
description: value
}))
}
),
/* @__PURE__ */ jsx(InputError, { message: errors.description })
] }),
/* @__PURE__ */ jsxs(DialogFooter, { className: "flex justify-end space-x-2 pt-4", children: [
/* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { type: "button", variant: "outline", children: button.close }) }),
/* @__PURE__ */ jsx(LoadingButton, { loading: processing, children: button.submit })
] })
] })
] }) })
] });
};
export {
NewsletterForm as default
};