import { useState } from "react"; import { View, Text, TextInput, ScrollView, Pressable, KeyboardAvoidingView, Platform, Alert, } from "react-native"; import { router } from "expo-router"; import { createIncident } from "@/lib/db"; import { Colors } from "@/constants/theme"; import type { IncidentDraft } from "@/types/incident"; const FIELD_STYLE = { backgroundColor: Colors.surface, borderColor: Colors.border, borderWidth: 1, borderRadius: 8, color: Colors.text1, padding: 12, fontSize: 14, marginBottom: 16, } as const; const MONO_FIELD_STYLE = { ...FIELD_STYLE, fontFamily: "monospace", minHeight: 80, textAlignVertical: "top" as const, } as const; const LABEL_STYLE = { color: Colors.text2, fontSize: 12, fontWeight: "600" as const, textTransform: "uppercase" as const, letterSpacing: 0.5, marginBottom: 6, } as const; export default function NewIncidentScreen() { const [form, setForm] = useState({ title: "", service: "", symptom: "", rootCause: "", fix: "", status: "open", tags: [], }); const [tagInput, setTagInput] = useState(""); const [saving, setSaving] = useState(false); function set(key: keyof IncidentDraft) { return (value: string) => setForm((f) => ({ ...f, [key]: value })); } function handleTagInputEnd() { const trimmed = tagInput.trim(); if (trimmed && !form.tags.includes(trimmed)) { setForm((f) => ({ ...f, tags: [...f.tags, trimmed] })); } setTagInput(""); } function removeTag(tag: string) { setForm((f) => ({ ...f, tags: f.tags.filter((t) => t !== tag) })); } async function handleSave() { if (!form.title.trim()) { Alert.alert("Required", "Title is required."); return; } setSaving(true); try { await createIncident(form); router.back(); } catch (e) { Alert.alert("Error", "Failed to save incident."); } finally { setSaving(false); } } return ( Title * Service Symptom Root Cause Fix Applied Tags {form.tags.length > 0 && ( {form.tags.map((tag) => ( removeTag(tag)} style={{ backgroundColor: Colors.surface2, borderRadius: 4, paddingHorizontal: 10, paddingVertical: 4, flexDirection: "row", alignItems: "center", gap: 6, }} > {tag} ))} )} {saving ? "Saving…" : "Save Incident"} ); }