mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-10 03:08:50 -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.
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
import useSWR from "swr";
|
|
import { fetcher } from "./utils";
|
|
|
|
export const useNoCodeForm = (formId) => {
|
|
const { data, error, mutate } = useSWR(`/api/forms/${formId}/nocodeform`, fetcher);
|
|
|
|
return {
|
|
noCodeForm: data,
|
|
isLoadingNoCodeForm: !error && !data,
|
|
isErrorNoCodeForm: error,
|
|
mutateNoCodeForm: mutate,
|
|
};
|
|
};
|
|
|
|
export const useNoCodeFormPublic = (formId) => {
|
|
const { data, error, mutate } = useSWR(`/api/public/forms/${formId}/nocodeform`, fetcher);
|
|
|
|
return {
|
|
noCodeForm: data,
|
|
isLoadingNoCodeForm: !error && !data,
|
|
isErrorNoCodeForm: error,
|
|
mutateNoCodeForm: mutate,
|
|
};
|
|
};
|
|
|
|
export const createNoCodeForm = async (formId) => {
|
|
try {
|
|
const res = await fetch(`/api/forms/${formId}/nocodeform`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({}),
|
|
});
|
|
return await res.json();
|
|
} catch (error) {
|
|
console.error(error);
|
|
throw Error(`createNoCodeForm: unable to create noCodeForm: ${error.message}`);
|
|
}
|
|
};
|
|
|
|
export const persistNoCodeForm = async (noCodeForm) => {
|
|
try {
|
|
await fetch(`/api/forms/${noCodeForm.formId}/nocodeform`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(noCodeForm),
|
|
});
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
};
|