Fixes type errors, cleans up code

This commit is contained in:
2025-05-28 16:22:14 -07:00
parent 3c989cf285
commit 8bee0973cd
3 changed files with 25 additions and 35 deletions

View File

@@ -1,12 +1,16 @@
import { useState } from "react";
import { pb } from "@/lib/pocketbase";
import { useAuth } from "@/context/auth/AuthContext";
import { pb } from "@/lib/pocketbase";
import type { Campaign } from "@/lib/types";
import { useState } from "react";
/**
* Button and form for creating a new campaign. Handles UI state and creation logic.
*/
export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Campaign) => void }) {
export function CreateCampaignButton({
onCreated,
}: {
onCreated?: (campaign: Campaign) => void;
}) {
const [creating, setCreating] = useState(false);
const [name, setName] = useState("");
const [loading, setLoading] = useState(false);
@@ -29,7 +33,7 @@ export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Cam
});
setName("");
setCreating(false);
if (onCreated) onCreated({ id: record.id, name: record.name });
if (onCreated) onCreated(record as Campaign);
} catch (e: any) {
setError(e?.message || "Failed to create campaign.");
} finally {
@@ -55,7 +59,7 @@ export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Cam
className="px-3 py-2 rounded bg-slate-800 text-slate-100 border border-slate-700 focus:outline-none focus:ring-2 focus:ring-violet-500"
placeholder="Campaign name"
value={name}
onChange={e => setName(e.target.value)}
onChange={(e) => setName(e.target.value)}
disabled={loading}
autoFocus
/>
@@ -68,7 +72,11 @@ export function CreateCampaignButton({ onCreated }: { onCreated?: (campaign: Cam
</button>
<button
className="px-2 py-2 rounded text-slate-400 hover:text-red-400"
onClick={() => { setCreating(false); setName(""); setError(null); }}
onClick={() => {
setCreating(false);
setName("");
setError(null);
}}
disabled={loading}
aria-label="Cancel"
>