lms/bootstrap/ssr/assets/section-form-DIYHBO-_.js
2025-12-15 12:26:23 +01:00

74 lines
3.1 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 { usePage, useForm } from "@inertiajs/react";
import { useState } from "react";
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 SectionForm = ({ title, section, handler }) => {
const [open, setOpen] = useState(false);
const { props } = usePage();
const { translate } = props;
const { dashboard, input, button } = translate;
const { data, setData, post, put, errors, processing } = useForm({
title: section ? section.title : "",
sort: section ? section.sort : props.lastSectionSort + 1,
course_id: props.course.id
});
const handleSubmit = (e) => {
e.preventDefault();
if (section) {
put(route("section.update", { id: section.id }), {
onSuccess: () => setOpen(false)
});
} else {
post(route("section.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: dashboard.section_title }),
/* @__PURE__ */ jsx(
Input,
{
required: true,
type: "text",
name: "title",
value: data.title,
placeholder: input.section_title_placeholder,
onChange: (e) => onHandleChange(e, setData)
}
),
/* @__PURE__ */ jsx(InputError, { message: errors.title })
] }),
/* @__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 {
SectionForm as default
};