Update components/kleap-form.tsx
This commit is contained in:
parent
55445888ac
commit
86eb0e84b4
|
|
@ -13,6 +13,11 @@ import {
|
||||||
} from "@/components/ui/form";
|
} from "@/components/ui/form";
|
||||||
import { Button } from "./ui/button";
|
import { Button } from "./ui/button";
|
||||||
|
|
||||||
|
interface KleapFormFieldOption {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
interface KleapFormField {
|
interface KleapFormField {
|
||||||
name: string;
|
name: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
|
@ -28,7 +33,7 @@ interface KleapFormField {
|
||||||
| "number";
|
| "number";
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
required?: boolean;
|
required?: boolean;
|
||||||
options?: string[]; // For select, radio
|
options?: KleapFormFieldOption[]; // For select, radio
|
||||||
rows?: number; // For textarea
|
rows?: number; // For textarea
|
||||||
validation?: {
|
validation?: {
|
||||||
min?: number;
|
min?: number;
|
||||||
|
|
@ -171,7 +176,7 @@ export function KleapForm({
|
||||||
try {
|
try {
|
||||||
// Get app_id from environment or URL
|
// Get app_id from environment or URL
|
||||||
const envAppId = process.env.NEXT_PUBLIC_APP_ID;
|
const envAppId = process.env.NEXT_PUBLIC_APP_ID;
|
||||||
const urlAppId = new URLSearchParams(window.location.search).get(
|
const urlAppId = new URLSearchParams(typeof window !== 'undefined' ? window.location.search : '').get(
|
||||||
"app_id",
|
"app_id",
|
||||||
);
|
);
|
||||||
const appId = envAppId || urlAppId || "";
|
const appId = envAppId || urlAppId || "";
|
||||||
|
|
@ -197,13 +202,6 @@ export function KleapForm({
|
||||||
formData.append(key, String(value));
|
formData.append(key, String(value));
|
||||||
});
|
});
|
||||||
|
|
||||||
// 📤 DEBUG HELPER - Log request details
|
|
||||||
console.group("📤 KLEAP FORM REQUEST");
|
|
||||||
for (const [_key, _value] of formData.entries()) {
|
|
||||||
// Debug logging entries
|
|
||||||
}
|
|
||||||
console.groupEnd();
|
|
||||||
|
|
||||||
// Submit to Kleap's form API
|
// Submit to Kleap's form API
|
||||||
const response = await fetch("https://form.kleap.co", {
|
const response = await fetch("https://form.kleap.co", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -325,8 +323,8 @@ export function KleapForm({
|
||||||
>
|
>
|
||||||
<option value="">Select an option</option>
|
<option value="">Select an option</option>
|
||||||
{field.options?.map((option) => (
|
{field.options?.map((option) => (
|
||||||
<option key={option} value={option}>
|
<option key={option.value} value={option.value}>
|
||||||
{option}
|
{option.label}
|
||||||
</option>
|
</option>
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
|
|
@ -349,16 +347,16 @@ export function KleapForm({
|
||||||
) : field.type === "radio" && field.options ? (
|
) : field.type === "radio" && field.options ? (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
{field.options.map((option) => (
|
{field.options.map((option) => (
|
||||||
<label key={option} className="flex items-center">
|
<label key={option.value} className="flex items-center">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
value={option}
|
value={option.value}
|
||||||
checked={formField.value === option}
|
checked={formField.value === option.value}
|
||||||
onChange={() => formField.onChange(option)}
|
onChange={() => formField.onChange(option.value)}
|
||||||
className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300"
|
className="h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300"
|
||||||
/>
|
/>
|
||||||
<span className="ml-2 text-sm text-gray-700 dark:text-gray-300">
|
<span className="ml-2 text-sm text-gray-700 dark:text-gray-300">
|
||||||
{option}
|
{option.label}
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
))}
|
))}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue