fix: nocodeForm not accessible from the outside

This commit is contained in:
Matthias Nannt
2022-06-25 16:27:01 +09:00
parent 29cb62da53
commit 178a7b51e6
15 changed files with 230 additions and 104 deletions
+14
View File
@@ -15,6 +15,20 @@ export const useNoCodeForm = (formId) => {
};
};
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`, {
+15 -1
View File
@@ -1,7 +1,21 @@
import intlFormat from "date-fns/intlFormat";
import { formatDistance } from "date-fns";
export const fetcher = (url) => fetch(url).then((res) => res.json());
export const fetcher = async (url) => {
const res = await fetch(url);
// If the status code is not in the range 200-299,
// we still try to parse and throw it.
if (!res.ok) {
const error: any = new Error("An error occurred while fetching the data.");
// Attach extra info to the error object.
error.info = await res.json();
error.status = res.status;
throw error;
}
return res.json();
};
export const shuffle = (array) => {
array = [...array];