diff --git a/src/modules/clients/pages/NewClientPage.tsx b/src/modules/clients/pages/NewClientPage.tsx new file mode 100644 index 0000000..186cc0b --- /dev/null +++ b/src/modules/clients/pages/NewClientPage.tsx @@ -0,0 +1,202 @@ +import { SidebarMenu } from "@/shared/components/Sidebar"; +import { useToast } from "@/shared/hooks"; +import { getPageTitle } from "@/shared/utils"; +import { Ban, Save } from "lucide-react"; +import { useState, type SyntheticEvent, type ChangeEvent } from "react"; +import { Helmet } from "react-helmet-async"; +import { createDocument } from "@/services/firebase/firestore"; +import { InputField } from "@/shared/components/InputField"; +import { Button } from "@/shared/components/Button"; +import { useNavigate } from "react-router-dom"; + +export function NewClientPage() { + const [form, setForm] = useState({ + name: "", + email: "", + phone: "", + company: "", + status: "active", + notes: "", + }); + + const [loading, setLoading] = useState(false); + + const { addToast } = useToast(); + const navigate = useNavigate(); + + const handleChange = (e: ChangeEvent) => { + setForm({ ...form, [e.target.name]: e.target.value }); + }; + + const handleClientCreation = async (e: SyntheticEvent) => { + e.preventDefault(); + setLoading(true); + + try { + const now = new Date().toISOString(); + + const client = { + ...form, + createdAt: now, + updatedAt: now, + }; + + await createDocument("clients", client as never); + + addToast({ + message: "Client created successfully", + variant: "success", + duration: 3000, + }); + + navigate("/clients"); + } catch (err: unknown) { + console.error("Failed to create client", err); + + addToast({ + message: "Failed to create client. Please try again.", + variant: "error", + duration: 3000, + }); + } finally { + setLoading(false); + } + }; + + return ( + <> + + {getPageTitle("New Client")} + + + +
+
+
+
+

New Client

+ +

+ Add a new client to your database. Provide contact details and additional information to manage your + relationships. +

+
+
+ +
+
+
+ +
+ +
+
+ + + +
+
+
+ +
+
+ +
+ +
+ +
+
+ + + +
+ + +