mirror of
https://github.com/formbricks/formbricks.git
synced 2026-01-06 05:40:02 -06:00
Move repository into a monorepo with turborepo and pnpm. This is a big change in the way the code is organized, used and deployed.
116 lines
5.4 KiB
TypeScript
116 lines
5.4 KiB
TypeScript
/* This example requires Tailwind CSS v2.0+ */
|
|
import { Dialog, Switch, Transition } from "@headlessui/react";
|
|
import { Fragment, useState } from "react";
|
|
import { TailSpin } from "react-loader-spinner";
|
|
import { persistNoCodeForm, useNoCodeForm } from "../../lib/noCodeForm";
|
|
import Loading from "../Loading";
|
|
import { XMarkIcon } from "@heroicons/react/24/outline";
|
|
import { toast } from "react-toastify";
|
|
import { classNames } from "../../lib/utils";
|
|
|
|
export default function SettingsModal({ open, setOpen, formId }) {
|
|
const { noCodeForm, isLoadingNoCodeForm, mutateNoCodeForm } = useNoCodeForm(formId);
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const toggleClose = async () => {
|
|
setLoading(true);
|
|
setTimeout(async () => {
|
|
const newNoCodeForm = JSON.parse(JSON.stringify(noCodeForm));
|
|
newNoCodeForm.closed = !noCodeForm.closed;
|
|
await persistNoCodeForm(newNoCodeForm);
|
|
mutateNoCodeForm(newNoCodeForm);
|
|
setLoading(false);
|
|
toast(
|
|
newNoCodeForm.closed
|
|
? "Your form is now closed for submissions "
|
|
: "Your form is now open for submissions 🎉"
|
|
);
|
|
}, 500);
|
|
};
|
|
|
|
if (isLoadingNoCodeForm) {
|
|
return <Loading />;
|
|
}
|
|
|
|
return (
|
|
<Transition.Root show={open} as={Fragment}>
|
|
<Dialog as="div" className="relative z-10" onClose={setOpen}>
|
|
<Transition.Child
|
|
as={Fragment}
|
|
enter="ease-out duration-300"
|
|
enterFrom="opacity-0"
|
|
enterTo="opacity-100"
|
|
leave="ease-in duration-200"
|
|
leaveFrom="opacity-100"
|
|
leaveTo="opacity-0">
|
|
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
|
|
</Transition.Child>
|
|
|
|
<div className="fixed inset-0 z-10 overflow-y-auto">
|
|
<div className="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
|
|
<Transition.Child
|
|
as={Fragment}
|
|
enter="ease-out duration-300"
|
|
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
|
leave="ease-in duration-200"
|
|
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
|
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95">
|
|
<Dialog.Panel className="relative transform overflow-hidden rounded-lg bg-white px-4 pt-5 pb-4 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-4xl sm:p-6">
|
|
<div className="absolute top-0 right-0 hidden pt-4 pr-4 sm:block">
|
|
<button
|
|
type="button"
|
|
className="rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2"
|
|
onClick={() => setOpen(false)}>
|
|
<span className="sr-only">Close</span>
|
|
<XMarkIcon className="h-6 w-6" aria-hidden="true" />
|
|
</button>
|
|
</div>
|
|
<div className="px-4 py-5 sm:p-6">
|
|
<div className="mb-4">
|
|
<h1 className="text-2xl font-medium leading-6 text-gray-900">Settings</h1>
|
|
</div>
|
|
<h3 className="text-lg font-medium leading-6 text-gray-900">Access</h3>
|
|
<div className="mt-2 w-full text-sm text-gray-500">
|
|
<Switch.Group as="div" className="flex w-full items-center justify-between">
|
|
<span className="flex flex-grow flex-col">
|
|
<Switch.Label as="span" className="text-sm font-medium text-gray-900" passive={true}>
|
|
Close form for new submissions?
|
|
</Switch.Label>
|
|
<Switch.Description as="span" className="text-sm text-gray-500">
|
|
Your form is currently{" "}
|
|
<span className="font-bold">{noCodeForm.closed ? "closed" : "open"}</span> for
|
|
submissions.
|
|
</Switch.Description>
|
|
</span>
|
|
{loading ? (
|
|
<TailSpin color="#1f2937" height={30} width={30} />
|
|
) : (
|
|
<Switch
|
|
checked={noCodeForm.closed}
|
|
onChange={() => toggleClose()}
|
|
className={classNames(
|
|
noCodeForm.closed ? "bg-red-600" : "bg-gray-200",
|
|
"relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2"
|
|
)}>
|
|
<span
|
|
aria-hidden="true"
|
|
className={classNames(
|
|
noCodeForm.closed ? "translate-x-5" : "translate-x-0",
|
|
"pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"
|
|
)}
|
|
/>
|
|
</Switch>
|
|
)}
|
|
</Switch.Group>
|
|
</div>
|
|
</div>
|
|
</Dialog.Panel>
|
|
</Transition.Child>
|
|
</div>
|
|
</div>
|
|
</Dialog>
|
|
</Transition.Root>
|
|
);
|
|
}
|