import { useState, type FormEvent } from 'react' import { useNavigate } from 'react-router-dom' import { inventory } from '@/api/client' import { PageHeader } from '@/components/PageHeader' import { ErrorBox } from '@/components/ErrorBox' const LOCATION_TYPES = ['WAREHOUSE', 'BIN', 'VIRTUAL'] as const export function CreateLocationPage() { const navigate = useNavigate() const [code, setCode] = useState('') const [name, setName] = useState('') const [type, setType] = useState('WAREHOUSE') const [submitting, setSubmitting] = useState(false) const [error, setError] = useState(null) const onSubmit = async (e: FormEvent) => { e.preventDefault() setError(null) setSubmitting(true) try { await inventory.createLocation({ code, name, type }) navigate('/locations') } catch (err: unknown) { setError(err instanceof Error ? err : new Error(String(err))) } finally { setSubmitting(false) } } return (
navigate('/locations')}>Cancel} />
setCode(e.target.value)} placeholder="WH-NEW" className="mt-1 w-full rounded-md border border-slate-300 px-3 py-2 text-sm" />
setName(e.target.value)} placeholder="New Warehouse" className="mt-1 w-full rounded-md border border-slate-300 px-3 py-2 text-sm" />
{error && }
) }