Enhance forms with validation and terminology

Implements enhanced inline validation with contextual messages and examples, adds a comprehensive theme park terminology tool (tooltip and glossary), and integrates these features into ParkForm and RideForm (including header actions and descriptive hints). Also introduces new helper modules and components to support validated inputs and glossary tooltips.
This commit is contained in:
gpt-engineer-app[bot]
2025-11-11 23:25:15 +00:00
parent 67ce8b5a88
commit 985454f0d9
8 changed files with 875 additions and 37 deletions

View File

@@ -31,6 +31,9 @@ import { OperatorForm } from './OperatorForm';
import { PropertyOwnerForm } from './PropertyOwnerForm';
import { Checkbox } from '@/components/ui/checkbox';
import { SubmissionHelpDialog } from '@/components/help/SubmissionHelpDialog';
import { TerminologyDialog } from '@/components/help/TerminologyDialog';
import { TooltipProvider } from '@/components/ui/tooltip';
import { fieldHints } from '@/lib/enhancedValidation';
const parkSchema = z.object({
name: z.string().min(1, 'Park name is required'),
@@ -320,10 +323,14 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
<MapPin className="w-5 h-5" />
{isEditing ? 'Edit Park' : 'Create New Park'}
</CardTitle>
<SubmissionHelpDialog type="park" variant="icon" />
<div className="flex gap-2">
<TerminologyDialog />
<SubmissionHelpDialog type="park" variant="icon" />
</div>
</div>
</CardHeader>
<CardContent>
<TooltipProvider>
<form onSubmit={handleSubmit(handleFormSubmit)} className="space-y-6">
{/* Basic Information */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
@@ -724,6 +731,7 @@ export function ParkForm({ onSubmit, onCancel, initialData, isEditing = false }:
)}
</div>
</form>
</TooltipProvider>
{/* Operator Modal */}
<Dialog open={isOperatorModalOpen} onOpenChange={setIsOperatorModalOpen}>

View File

@@ -36,6 +36,9 @@ import { TechnicalSpecsEditor, validateTechnicalSpecs } from './editors/Technica
import { CoasterStatsEditor, validateCoasterStats } from './editors/CoasterStatsEditor';
import { FormerNamesEditor } from './editors/FormerNamesEditor';
import { SubmissionHelpDialog } from '@/components/help/SubmissionHelpDialog';
import { TerminologyDialog } from '@/components/help/TerminologyDialog';
import { TermTooltip } from '@/components/ui/term-tooltip';
import { fieldHints } from '@/lib/enhancedValidation';
import {
convertValueToMetric,
convertValueFromMetric,
@@ -391,7 +394,10 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
<Zap className="w-5 h-5" />
{isEditing ? 'Edit Ride' : 'Create New Ride'}
</CardTitle>
<SubmissionHelpDialog type="ride" variant="icon" />
<div className="flex gap-2">
<TerminologyDialog />
<SubmissionHelpDialog type="ride" variant="icon" />
</div>
</div>
</CardHeader>
<CardContent>
@@ -851,17 +857,15 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
<div className="space-y-3">
<div className="flex items-center gap-2">
<Label>Track Material(s)</Label>
<Tooltip>
<TooltipTrigger asChild>
<HelpCircle className="h-4 w-4 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p>Material used for the track. Select multiple if hybrid (e.g., wood track with steel supports).</p>
</TooltipContent>
</Tooltip>
<Label>
<TermTooltip term="ibox-track" showIcon={false}>
Track Material(s)
</TermTooltip>
</Label>
</div>
<p className="text-sm text-muted-foreground">Select all materials used in the track</p>
<p className="text-sm text-muted-foreground">
Common: <TermTooltip term="ibox-track" inline>Steel</TermTooltip>, Wood, <TermTooltip term="hybrid-coaster" inline>Hybrid (RMC IBox)</TermTooltip>
</p>
<div className="grid grid-cols-2 gap-3">
{TRACK_MATERIALS.map((material) => (
<div key={material.value} className="flex items-center space-x-2">
@@ -888,16 +892,10 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
<div className="space-y-3">
<div className="flex items-center gap-2">
<Label>Support Material(s)</Label>
<Tooltip>
<TooltipTrigger asChild>
<HelpCircle className="h-4 w-4 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p>Material used for the support structure. Can be different from track material (e.g., wood track on steel supports).</p>
</TooltipContent>
</Tooltip>
</div>
<p className="text-sm text-muted-foreground">Select all materials used in the supports</p>
<p className="text-sm text-muted-foreground">
Materials used for support structure (can differ from track)
</p>
<div className="grid grid-cols-2 gap-3">
{SUPPORT_MATERIALS.map((material) => (
<div key={material.value} className="flex items-center space-x-2">
@@ -923,23 +921,15 @@ export function RideForm({ onSubmit, onCancel, initialData, isEditing = false }:
<div className="space-y-3">
<div className="flex items-center gap-2">
<Label>Propulsion Method(s)</Label>
<Tooltip>
<TooltipTrigger asChild>
<HelpCircle className="h-4 w-4 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p className="font-semibold mb-1">Common methods:</p>
<ul className="text-xs space-y-1">
<li> <strong>LSM Launch:</strong> Linear Synchronous Motor (smooth, modern)</li>
<li> <strong>Chain Lift:</strong> Traditional lift hill</li>
<li> <strong>Hydraulic Launch:</strong> Fast, powerful (e.g., Kingda Ka)</li>
<li> <strong>Gravity:</strong> Free-fall or terrain-based</li>
</ul>
</TooltipContent>
</Tooltip>
<Label>
<TermTooltip term="lsm" showIcon={false}>
Propulsion Method(s)
</TermTooltip>
</Label>
</div>
<p className="text-sm text-muted-foreground">Select all propulsion methods used</p>
<p className="text-sm text-muted-foreground">
Common: <TermTooltip term="lsm" inline>LSM Launch</TermTooltip>, <TermTooltip term="chain-lift" inline>Chain Lift</TermTooltip>, <TermTooltip term="hydraulic-launch" inline>Hydraulic Launch</TermTooltip>
</p>
<div className="grid grid-cols-2 gap-3">
{PROPULSION_METHODS.map((method) => (
<div key={method.value} className="flex items-center space-x-2">

View File

@@ -8,6 +8,7 @@ import { Card } from "@/components/ui/card";
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
import { useUnitPreferences } from "@/hooks/useUnitPreferences";
import { toast } from "sonner";
import { fieldHints } from "@/lib/enhancedValidation";
import {
convertValueToMetric,
convertValueFromMetric,

View File

@@ -0,0 +1,135 @@
import { useState } from "react";
import { BookOpen, Search } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { ScrollArea } from "@/components/ui/scroll-area";
import { Badge } from "@/components/ui/badge";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { getAllCategories, getTermsByCategory, searchGlossary, type GlossaryTerm } from "@/lib/glossary";
export function TerminologyDialog() {
const [open, setOpen] = useState(false);
const [searchQuery, setSearchQuery] = useState("");
const categories = getAllCategories();
const searchResults = searchQuery ? searchGlossary(searchQuery) : [];
const renderTermCard = (term: GlossaryTerm) => (
<div key={term.term} className="p-4 border rounded-lg space-y-2 hover:bg-muted/50 transition-colors">
<div className="flex items-start justify-between gap-2">
<h4 className="font-semibold">{term.term}</h4>
<Badge variant="secondary" className="text-xs shrink-0">
{term.category.replace('-', ' ')}
</Badge>
</div>
<p className="text-sm text-muted-foreground">{term.definition}</p>
{term.example && (
<p className="text-xs text-muted-foreground italic">
<span className="font-medium">Example:</span> {term.example}
</p>
)}
{term.relatedTerms && term.relatedTerms.length > 0 && (
<div className="flex flex-wrap gap-1 pt-1">
<span className="text-xs text-muted-foreground">Related:</span>
{term.relatedTerms.map(rt => (
<Badge key={rt} variant="outline" className="text-xs">
{rt.replace(/-/g, ' ')}
</Badge>
))}
</div>
)}
</div>
);
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button variant="outline" size="sm">
<BookOpen className="w-4 h-4 mr-2" />
Terminology
</Button>
</DialogTrigger>
<DialogContent className="max-w-4xl max-h-[80vh]">
<DialogHeader>
<DialogTitle>Theme Park Terminology Reference</DialogTitle>
<DialogDescription>
Quick reference for technical terms, manufacturers, and ride types
</DialogDescription>
</DialogHeader>
<div className="space-y-4">
{/* Search */}
<div className="relative">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground" />
<Input
placeholder="Search terminology..."
value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)}
className="pl-9"
/>
</div>
{/* Results */}
{searchQuery ? (
<ScrollArea className="h-[400px]">
<div className="space-y-3">
{searchResults.length > 0 ? (
searchResults.map(renderTermCard)
) : (
<div className="text-center py-12 text-muted-foreground">
No terms found matching "{searchQuery}"
</div>
)}
</div>
</ScrollArea>
) : (
<Tabs defaultValue="manufacturer" className="w-full">
<TabsList className="grid w-full grid-cols-4 lg:grid-cols-7">
{categories.map(cat => (
<TabsTrigger key={cat} value={cat} className="text-xs">
{cat === 'manufacturer' ? 'Mfg.' :
cat === 'technology' ? 'Tech' :
cat === 'measurement' ? 'Units' :
cat.charAt(0).toUpperCase() + cat.slice(1).substring(0, 4)}
</TabsTrigger>
))}
</TabsList>
{categories.map(cat => {
const terms = getTermsByCategory(cat);
return (
<TabsContent key={cat} value={cat}>
<ScrollArea className="h-[400px]">
<div className="space-y-3 pr-4">
<div className="flex items-center gap-2 pb-2 border-b">
<h3 className="font-semibold capitalize">
{cat.replace('-', ' ')}
</h3>
<Badge variant="secondary">{terms.length} terms</Badge>
</div>
{terms.map(renderTermCard)}
</div>
</ScrollArea>
</TabsContent>
);
})}
</Tabs>
)}
</div>
<div className="flex items-center gap-2 pt-4 border-t text-xs text-muted-foreground">
<Badge variant="outline" className="text-xs">Tip</Badge>
<span>Hover over underlined terms in forms to see quick definitions</span>
</div>
</DialogContent>
</Dialog>
);
}

View File

@@ -0,0 +1,56 @@
import { HelpCircle } from "lucide-react";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { getGlossaryTerm } from "@/lib/glossary";
import { cn } from "@/lib/utils";
interface TermTooltipProps {
term: string;
children: React.ReactNode;
inline?: boolean;
showIcon?: boolean;
}
export function TermTooltip({ term, children, inline = false, showIcon = true }: TermTooltipProps) {
const glossaryEntry = getGlossaryTerm(term);
if (!glossaryEntry) {
return <>{children}</>;
}
return (
<Tooltip>
<TooltipTrigger asChild>
<span className={cn(
"inline-flex items-center gap-1",
inline && "underline decoration-dotted cursor-help"
)}>
{children}
{showIcon && (
<HelpCircle className="inline-block w-3 h-3 text-muted-foreground" />
)}
</span>
</TooltipTrigger>
<TooltipContent className="max-w-xs" side="top">
<div className="space-y-1">
<div className="font-semibold text-sm">{glossaryEntry.term}</div>
<p className="text-xs text-muted-foreground capitalize">
{glossaryEntry.category.replace('-', ' ')}
</p>
<p className="text-sm">{glossaryEntry.definition}</p>
{glossaryEntry.example && (
<p className="text-xs text-muted-foreground italic pt-1">
Example: {glossaryEntry.example}
</p>
)}
{glossaryEntry.relatedTerms && glossaryEntry.relatedTerms.length > 0 && (
<p className="text-xs text-muted-foreground pt-1">
See also: {glossaryEntry.relatedTerms.map(t =>
getGlossaryTerm(t)?.term || t
).join(', ')}
</p>
)}
</div>
</TooltipContent>
</Tooltip>
);
}

View File

@@ -0,0 +1,87 @@
import * as React from "react";
import { Check, AlertCircle } from "lucide-react";
import { cn } from "@/lib/utils";
import { Input } from "@/components/ui/input";
import { useDebouncedCallback } from "use-debounce";
export interface ValidatedInputProps extends React.ComponentProps<typeof Input> {
validation?: {
isValid?: boolean;
error?: string;
hint?: string;
};
showValidation?: boolean;
onValidate?: (value: string) => { isValid: boolean; error?: string };
}
const ValidatedInput = React.forwardRef<HTMLInputElement, ValidatedInputProps>(
({ className, validation, showValidation = true, onValidate, onChange, ...props }, ref) => {
const [localValidation, setLocalValidation] = React.useState<{
isValid?: boolean;
error?: string;
}>({});
const debouncedValidate = useDebouncedCallback((value: string) => {
if (onValidate) {
const result = onValidate(value);
setLocalValidation(result);
}
}, 300);
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange?.(e);
if (onValidate && showValidation) {
debouncedValidate(e.target.value);
}
};
const validationState = validation || localValidation;
const showSuccess = showValidation && validationState.isValid && props.value;
const showError = showValidation && validationState.error;
return (
<div className="space-y-1">
<div className="relative">
<Input
ref={ref}
className={cn(
showError && "border-destructive focus-visible:ring-destructive",
showSuccess && "border-green-500 focus-visible:ring-green-500",
"pr-8",
className
)}
onChange={handleChange}
{...props}
/>
{showValidation && props.value && (
<div className="absolute right-3 top-1/2 transform -translate-y-1/2">
{validationState.isValid && (
<Check className="w-4 h-4 text-green-500" />
)}
{validationState.error && (
<AlertCircle className="w-4 h-4 text-destructive" />
)}
</div>
)}
</div>
{showValidation && validation?.hint && !validationState.error && (
<p className="text-xs text-muted-foreground">
{validation.hint}
</p>
)}
{showError && (
<p className="text-xs text-destructive flex items-center gap-1">
<AlertCircle className="w-3 h-3" />
{validationState.error}
</p>
)}
</div>
);
}
);
ValidatedInput.displayName = "ValidatedInput";
export { ValidatedInput };