Path: blob/master/webhooks/webhook_preview/app/page.tsx
1091 views
"use client";12import { useState, useEffect } from "react";3import { useRouter } from "next/navigation";4import { Button } from "@/components/ui/button";5import {6Card,7CardContent,8CardDescription,9CardFooter,10CardHeader,11CardTitle,12} from "@/components/ui/card";13import { Input } from "@/components/ui/input";14import { generateUUID } from "@/lib/utils";15import { useToast } from "@/hooks/use-toast";1617export default function HomePage() {18const [uuid, setUuid] = useState<string>("");19const router = useRouter();20const { toast } = useToast();2122useEffect(() => {23// Generate a UUID if none exists24setUuid(generateUUID());25}, []);2627const handleCreateWebhook = async () => {28const uuidRegex =29/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;3031if (!uuidRegex.test(uuid)) {32toast({33title: "Invalid UUID",34description: "Please use the generated UUID or generate a new one",35variant: "destructive",36});37return;38}3940try {41const response = await fetch("/api/new-webhook/", {42method: "POST",43headers: {44"Content-Type": "application/json",45},46body: JSON.stringify({ uuid }),47});4849if (!response.ok) {50throw new Error("Failed to create webhook");51}5253const data = await response.json();5455if (data?.success) {56router.push(`/${uuid}`);57} else {58toast({59title: "Error",60description: "Webhook could not be created",61variant: "destructive",62});63}64} catch (error: unknown) {65if (error instanceof Error) {66toast({67title: "Error",68description: error.message,69variant: "destructive",70});71} else {72toast({73title: "Error",74description: "Something went wrong",75variant: "destructive",76});77}78}79};8081return (82<div className="min-h-screen flex items-center justify-center bg-gray-50 p-4">83<Card className="w-full max-w-md">84<CardHeader>85<CardTitle>License Plate Recognition Dashboard</CardTitle>86<CardDescription>87Create a new webhook URL to receive license plate recognition data88</CardDescription>89</CardHeader>90<CardContent>91<div className="space-y-4">92<div className="space-y-2">93<label htmlFor="uuid" className="text-sm font-medium">94Webhook UUID95</label>96<Input97id="uuid"98value={uuid}99readOnly100placeholder="Generated UUID"101className="font-mono"102/>103<p className="text-xs text-muted-foreground">104This UUID will be used to access your webhook data105</p>106</div>107</div>108</CardContent>109<CardFooter className="flex justify-between">110<Button variant="outline" onClick={() => setUuid(generateUUID())}>111Generate New UUID112</Button>113<Button onClick={handleCreateWebhook}>Create Webhook</Button>114</CardFooter>115</Card>116</div>117);118}119120121