"use client"; import { useState, useEffect, ChangeEvent } from "react"; import { useRouter } from "next/navigation"; import Layout from "@/components/layout/layout"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Save, Send, Key, MessageSquare, Shield, Globe } from "lucide-react"; import { apiRequest } from "@/lib/storeHelper"; import { toast, Toaster } from "sonner"; import BroadcastDialog from "@/components/modals/broadcast-dialog"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; const SHIPPING_REGIONS = [ { value: "UK", label: "United Kingdom", emoji: "πŸ‡¬πŸ‡§" }, { value: "EU", label: "European Union", emoji: "πŸ‡ͺπŸ‡Ί" }, { value: "USA", label: "United States", emoji: "πŸ‡ΊπŸ‡Έ" }, { value: "WW", label: "Worldwide", emoji: "🌍" }, ] as const; interface Storefront { pgpKey: string; welcomeMessage: string; telegramToken: string; shipsFrom: typeof SHIPPING_REGIONS[number]["value"]; shipsTo: typeof SHIPPING_REGIONS[number]["value"]; } export default function StorefrontPage() { const router = useRouter(); const [storefront, setStorefront] = useState({ pgpKey: "", welcomeMessage: "", telegramToken: "", shipsFrom: "UK", shipsTo: "WW", }); const [broadcastOpen, setBroadcastOpen] = useState(false); const [loading, setLoading] = useState(true); const [saving, setSaving] = useState(false); useEffect(() => { const authToken = document.cookie .split("; ") .find((row) => row.startsWith("Authorization=")) ?.split("=")[1]; if (!authToken) { router.push("/login"); return; } const fetchStorefront = async () => { try { setLoading(true); const data: Storefront = await apiRequest("/storefront"); setStorefront(data); } catch (error) { toast.error("Failed to load storefront data."); } finally { setLoading(false); } }; fetchStorefront(); }, []); // βœ… Handle Form Input Changes const handleInputChange = ( e: ChangeEvent ) => { setStorefront({ ...storefront, [e.target.name]: e.target.value }); }; // βœ… Save Storefront Changes const saveStorefront = async () => { try { setSaving(true); await apiRequest("/storefront", "PUT", storefront); toast.success("Storefront updated successfully!"); } catch (error) { toast.error("Failed to update storefront."); } finally { setSaving(false); } }; return (

PGP Encryption Key