-
- {isLoading ? (
-
- {[...Array(3)].map((_, index) => (
-
- ))}
-
- ) : forms.length === 0 ? (
-
-
- Click "Create Form" to get started.
-
-
- ) : (
-
- {forms.map((form) => (
-
- ))}
-
- )}
-
+ {isLoading ? (
+
+ {[...Array(3)].map((_, index) => (
+
+ ))}
+
+ ) : forms.length === 0 ? (
+
+
+ Click "Create Form" to get started.
+
+
+ ) : (
+
+ {forms.map((form) => (
+
+ ))}
+
+ )}
+
+
+
+ >
);
}
diff --git a/frontend/components/form/formwise.tsx b/frontend/components/form/formwise.tsx
index ed48799..00211c0 100644
--- a/frontend/components/form/formwise.tsx
+++ b/frontend/components/form/formwise.tsx
@@ -91,7 +91,7 @@ export default function FormWise({ form, preview = false }: FormWiseProps) {
{field.help_text && (
@@ -116,7 +116,7 @@ export default function FormWise({ form, preview = false }: FormWiseProps) {
)}
-
+
{field.help_text && (
{field.help_text}
@@ -335,7 +335,7 @@ export default function FormWise({ form, preview = false }: FormWiseProps) {
type="number"
min={field.min_value ?? undefined}
max={field.max_value ?? undefined}
- placeholder={field.label}
+ placeholder="Your Answer"
onChange={(e) => {
const value =
e.target.value === ""
diff --git a/frontend/config/api-urls.ts b/frontend/config/api-urls.ts
index 6e92391..770c399 100644
--- a/frontend/config/api-urls.ts
+++ b/frontend/config/api-urls.ts
@@ -22,4 +22,5 @@ export const USER_URLS = {
export const FORM_URLS = {
BASE: `${BASE_API_URL}/forms`,
BY_ID: (id: string) => `${BASE_API_URL}/forms/${id}`,
+ CREATE: `${BASE_API_URL}/forms/generate`,
};
diff --git a/frontend/lib/api.ts b/frontend/lib/api.ts
index ca2c3d5..f5b5e9f 100644
--- a/frontend/lib/api.ts
+++ b/frontend/lib/api.ts
@@ -37,5 +37,9 @@ export async function apiRequest
({
throw new Error(errorMessage);
}
+ if (response.status === 204) {
+ return {} as T;
+ }
+
return response.json();
}
diff --git a/frontend/lib/schemas.ts b/frontend/lib/schemas.ts
index 722c92e..f4b59eb 100644
--- a/frontend/lib/schemas.ts
+++ b/frontend/lib/schemas.ts
@@ -62,10 +62,25 @@ export const editProfileSchema = z
path: ["confirmPassword"],
});
+export const createFormSchema = z.object({
+ title: z
+ .string()
+ .max(100, "Title cannot exceed 100 characters")
+ .optional()
+ .refine((title) => !title || title.trim().length > 0, {
+ message: "Title cannot be empty",
+ }),
+ prompt: z
+ .string()
+ .min(50, "Prompt must be at least 50 characters")
+ .max(500, "Prompt cannot exceed 500 characters"),
+});
+
// Types
export type LoginFormValues = z.infer;
export type RegisterFormValues = z.infer;
export type EditProfileFormValues = z.infer;
+export type CreateFormFormValues = z.infer;
// Generate dynamic form schemas
export function generateFormwiseSchema(form: Form) {
diff --git a/frontend/lib/services/form.ts b/frontend/lib/services/form.ts
index e81f4ff..0b8158c 100644
--- a/frontend/lib/services/form.ts
+++ b/frontend/lib/services/form.ts
@@ -1,4 +1,4 @@
-import type { Form, FormOverview } from "@/types/form";
+import type { Form, FormCreateValues, FormOverview } from "@/types/form";
import { apiRequest } from "@/lib/api";
import { FORM_URLS } from "@/config/api-urls";
@@ -15,4 +15,24 @@ export const formService = {
endpoint: FORM_URLS.BY_ID(id),
});
},
+
+ async deleteForm(id: string): Promise {
+ return await apiRequest({
+ endpoint: FORM_URLS.BY_ID(id),
+ method: "DELETE",
+ requireAuth: true,
+ });
+ },
+
+ async createForm(data: FormCreateValues): Promise