import { View, Text, ScrollView, Alert } from "react-native"; import { Stack, useRouter } from "expo-router"; import { useState } from "react"; import { useMutation } from "convex/react"; import { api } from "../../convex/_generated/api"; import { useAuth } from "../_layout"; import { useTheme } from "../../components/theme"; import { Button } from "../../components/ui/button"; import { Input } from "../../components/ui/input"; import { Card } from "../../components/ui/card"; import { CATEGORIES } from "../../lib/constants"; export default function CreatePostScreen() { const router = useRouter(); const theme = useTheme(); const { token, isAuthenticated } = useAuth(); const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [category, setCategory] = useState(null); const [location, setLocation] = useState(""); const [budget, setBudget] = useState(""); const [submitting, setSubmitting] = useState(false); const createPost = useMutation(api.posts.create); if (!isAuthenticated) { return ( <> 🔒 Најавете се Треба да сте најавени за да креирате побарување. ); } async function handleSubmit() { if (!title.trim()) { Alert.alert("Грешка", "Внесете наслов"); return; } if (!description.trim()) { Alert.alert("Грешка", "Внесете опис"); return; } setSubmitting(true); try { const postId = await createPost({ token: token!, title: title.trim(), description: description.trim(), category: category ?? undefined, location: location.trim() || undefined, budget: budget.trim() || undefined, }); router.replace(`/post/${postId}` as any); } catch (e: any) { Alert.alert("Грешка", e.message || "Неуспешно креирање"); } finally { setSubmitting(false); } } return ( <> Наслов * Опис * Категорија {CATEGORIES.map((cat) => ( setCategory(category === cat.slug ? null : cat.slug)} > {cat.name} ))} Локација Буџет ); }