Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Enhance FunnelForm and GoalFormModal validation to prevent full URL entries, ensuring users input only paths. Update input styles for error states and improve accessibility in form components.

Bill Yangf25337dbf089
diff --git a/client/src/app/[site]/funnels/components/FunnelForm.tsx b/client/src/app/[site]/funnels/components/FunnelForm.tsx
index 788224bcc..ac606a520 100644
--- a/client/src/app/[site]/funnels/components/FunnelForm.tsx
+++ b/client/src/app/[site]/funnels/components/FunnelForm.tsx
@@ -5,7 +5,7 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
import { cn } from "@/lib/utils";
import { Reorder } from "framer-motion";
import { ChevronDown, ChevronUp, GripVertical, Plus, Save, Trash2, X } from "lucide-react";
-import { useState } from "react";
+import { useMemo, useState } from "react";
import { FunnelResponse, FunnelStep } from "../../../../api/analytics/endpoints";
import { useMetric } from "../../../../api/analytics/hooks/useGetMetric";
import { ThreeDotLoader } from "../../../../components/Loaders";
@@ -13,6 +13,8 @@ import { Label } from "../../../../components/ui/label";
import { Switch } from "../../../../components/ui/switch";
import { Funnel } from "./Funnel";
+const URL_PATTERN = /^(https?:\/\/|www\.|[a-zA-Z0-9-]+\.[a-zA-Z]{2,}\/)/i;
+
interface FunnelFormProps {
name: string;
setName: (name: string) => void;
@@ -80,6 +82,13 @@ export function FunnelForm({
// Unique IDs for each step (needed for drag-and-drop reordering)
const [stepIds, setStepIds] = useState<string[]>(() => steps.map((_, i) => `step-${Date.now()}-${i}`));
+ // Derive which page-type steps have URL values
+ const stepUrlErrors = useMemo(
+ () => steps.map(step => step.type === "page" && URL_PATTERN.test(step.value)),
+ [steps]
+ );
+ const hasUrlErrors = stepUrlErrors.some(Boolean);
+
// Fetch suggestions for paths, events, and hostnames
const { data: pathsData } = useMetric({
parameter: "pathname",
@@ -270,13 +279,23 @@ export function FunnelForm({
<SelectItem value="event">Event</SelectItem>
</SelectContent>
</Select>
- <InputWithSuggestions
- suggestions={step.type === "page" ? pathSuggestions : eventSuggestions}
- placeholder={step.type === "page" ? "Path (e.g. /pricing)" : "Event name"}
- value={step.value}
- className="border-neutral-300 dark:border-neutral-700 w-[260px]"
- onChange={e => updateStep(index, "value", e.target.value)}
- />
+ <div className="flex flex-col">
+ <InputWithSuggestions
+ suggestions={step.type === "page" ? pathSuggestions : eventSuggestions}
+ placeholder={step.type === "page" ? "Path (e.g. /pricing)" : "Event name"}
+ value={step.value}
+ className={cn(
+ "border-neutral-300 dark:border-neutral-700 w-[260px]",
+ stepUrlErrors[index] && "border-red-500 dark:border-red-500"
+ )}
+ onChange={e => updateStep(index, "value", e.target.value)}
+ />
+ {stepUrlErrors[index] && (
+ <p className="text-xs text-red-500 mt-1">
+ Enter a path (e.g., /checkout), not a full URL.
+ </p>
+ )}
+ </div>
<div className="flex items-center">
<Button
variant="ghost"
@@ -456,7 +475,7 @@ export function FunnelForm({
<Button variant="outline" onClick={onCancel}>
Cancel
</Button>
- <Button onClick={onSave} disabled={isSaving} variant="success">
+ <Button onClick={onSave} disabled={isSaving || hasUrlErrors} variant="success">
<Save className="h-4 w-4" />
{isSaving ? "Saving..." : saveButtonText}
</Button>
diff --git a/client/src/app/[site]/goals/components/GoalFormModal.tsx b/client/src/app/[site]/goals/components/GoalFormModal.tsx
index 9d7031d5b..abeef2e6b 100644
--- a/client/src/app/[site]/goals/components/GoalFormModal.tsx
+++ b/client/src/app/[site]/goals/components/GoalFormModal.tsx
@@ -59,6 +59,19 @@ const formSchema = z
message: "Configuration is required based on goal type",
path: ["config"],
}
+ )
+ .refine(
+ data => {
+ if (data.goalType === "path" && data.config.pathPattern) {
+ return !/^(https?:\/\/|www\.|[a-zA-Z0-9-]+\.[a-zA-Z]{2,}\/)/i.test(data.config.pathPattern);
+ }
+ return true;
+ },
+ {
+ message:
+ "Enter a path (e.g., /checkout), not a full URL. The domain is already determined by your site.",
+ path: ["config", "pathPattern"],
+ }
);
type FormValues = z.infer<typeof formSchema>;
diff --git a/client/src/components/ui/form.tsx b/client/src/components/ui/form.tsx
index 50d05465a..b85f7ddf3 100644
--- a/client/src/components/ui/form.tsx
+++ b/client/src/components/ui/form.tsx
@@ -90,7 +90,7 @@ const FormLabel = React.forwardRef<
return (
<Label
ref={ref}
- className={cn(error && "text-red-500 dark:text-red-900", className)}
+ className={cn(className)}
htmlFor={formItemId}
{...props}
/>
@@ -144,7 +144,7 @@ const FormMessage = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<
<p
ref={ref}
id={formMessageId}
- className={cn("text-[0.8rem] font-medium text-red-500 dark:text-red-900", className)}
+ className={cn("text-[0.8rem] font-medium text-red-500 dark:text-red-400", className)}
{...props}
>
{body}
diff --git a/client/src/components/ui/input.tsx b/client/src/components/ui/input.tsx
index 7238e71ac..effd892c1 100644
--- a/client/src/components/ui/input.tsx
+++ b/client/src/components/ui/input.tsx
@@ -5,7 +5,7 @@ import { Search } from "lucide-react";
import { cn } from "@/lib/utils";
const inputVariants = cva(
- "flex w-full rounded-lg border border-neutral-150 bg-transparent transition-colors file:border-0 file:bg-transparent file:font-medium file:text-neutral-950 placeholder:text-neutral-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-neutral-800 dark:file:text-neutral-50 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300",
+ "flex w-full rounded-lg border border-neutral-150 bg-transparent transition-colors file:border-0 file:bg-transparent file:font-medium file:text-neutral-950 placeholder:text-neutral-500 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-red-500 dark:aria-[invalid=true]:border-red-400 dark:border-neutral-800 dark:file:text-neutral-50 dark:placeholder:text-neutral-400 dark:focus-visible:ring-neutral-300",
{
variants: {
inputSize: {
@@ -21,7 +21,7 @@ const inputVariants = cva(
export interface InputProps
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
- VariantProps<typeof inputVariants> {
+ VariantProps<typeof inputVariants> {
isSearch?: boolean;
}