import { For, Show, createSignal, onMount } from 'solid-js'; import { BTN_GHOST, BTN_ORANGE, CARD, INPUT, LABEL } from '~/components/DashboardShell'; const API = '/api/gateway'; type RequirementItem = { id: string; title: string; description?: string | null; status?: string; budget_min?: number | null; budget_max?: number | null; area?: string | null; city?: string | null; created_at?: string; }; async function apiFetch(path: string, opts?: RequestInit) { return fetch(`${API}${path}`, { ...opts, credentials: 'include', headers: { 'Content-Type': 'application/json', ...(opts?.headers ?? {}) }, }); } export default function CustomerRequirementsPage() { const [requirements, setRequirements] = createSignal([]); const [loading, setLoading] = createSignal(true); const [busyId, setBusyId] = createSignal(null); const [saving, setSaving] = createSignal(false); const [msg, setMsg] = createSignal(''); const [err, setErr] = createSignal(''); const [form, setForm] = createSignal({ title: '', description: '', budget_min: '', budget_max: '', area: '', city: '', }); const loadRequirements = async () => { setLoading(true); setErr(''); try { const res = await apiFetch('/api/customers/requirements?page=1&limit=100'); const payload = await res.json().catch(() => ({})); if (!res.ok) { setErr(payload.error || payload.message || 'Failed to load requirements.'); setRequirements([]); return; } setRequirements(Array.isArray(payload?.data) ? payload.data : []); } catch { setErr('Network error while loading requirements.'); } finally { setLoading(false); } }; onMount(loadRequirements); const setField = (key: keyof ReturnType, value: string) => setForm((prev) => ({ ...prev, [key]: value })); const createRequirement = async () => { setSaving(true); setMsg(''); setErr(''); try { const payload = { title: form().title.trim(), description: form().description.trim() || undefined, budget_min: form().budget_min ? Number(form().budget_min) : undefined, budget_max: form().budget_max ? Number(form().budget_max) : undefined, area: form().area.trim() || undefined, city: form().city.trim() || undefined, }; const res = await apiFetch('/api/customers/requirements', { method: 'POST', body: JSON.stringify(payload), }); const data = await res.json().catch(() => ({})); if (!res.ok) { setErr(data.error || data.message || 'Failed to create requirement.'); return; } setMsg('Requirement created.'); setForm({ title: '', description: '', budget_min: '', budget_max: '', area: '', city: '' }); await loadRequirements(); } catch { setErr('Network error while creating requirement.'); } finally { setSaving(false); } }; const submitRequirement = async (id: string) => { setBusyId(id); setMsg(''); setErr(''); try { const res = await apiFetch(`/api/customers/requirements/${id}/submit`, { method: 'POST' }); const data = await res.json().catch(() => ({})); if (!res.ok) { setErr(data.error || data.message || 'Failed to submit requirement.'); return; } setMsg('Requirement submitted to verification.'); await loadRequirements(); } catch { setErr('Network error while submitting requirement.'); } finally { setBusyId(null); } }; return (

My Requirements

Create requirements. They move to verification first, then final approval.

Post New Requirement

setField('title', e.currentTarget.value)} style={INPUT} placeholder="Wedding photographer in Chennai" />