diff --git a/package.json b/package.json index f82d549..6c22891 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "siteforge", "private": true, - "version": "1.1.31", + "version": "1.1.32", "type": "module", "scripts": { "dev": "vite", diff --git a/src/App.tsx b/src/App.tsx index 9e791bc..e1c6b2f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2528,14 +2528,132 @@ export default function App() { function NotFoundPage() { const location = useLocation() + const [showForm, setShowForm] = useState(false) + const [form, setForm] = useState({ + firstName: '', + email: '', + message: `Hi Nate, I tried visiting "${location.pathname}" and got a 404. You may want to check if this link is broken.`, + }) + const [submitStatus, setSubmitStatus] = useState<'idle' | 'busy' | 'sent' | 'error'>('idle') + const [errMsg, setErrMsg] = useState('') + useEffect(() => { sendEvent('not_found', { path: location.pathname }) }, [location.pathname]) + + async function handleReport(e: React.FormEvent) { + e.preventDefault() + setSubmitStatus('busy') + try { + const res = await fetch('/api/contact', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + firstName: form.firstName, + email: form.email, + message: form.message, + messageType: 'question', + _honey: '', + }), + }) + const data = await res.json() + if (!res.ok) throw new Error(data.message ?? 'Something went wrong.') + setSubmitStatus('sent') + } catch (err) { + setErrMsg(err instanceof Error ? err.message : 'Something went wrong.') + setSubmitStatus('error') + } + } + return ( -
-

Page not found

-

The page {location.pathname} doesn't exist.

- ← Back to home +
+
+ +

404

+

Page Not Found

+

+ The path {location.pathname}{' '} + doesn't exist — it may have moved or been removed. +

+
+ ← Back to Home + Browse Episodes +
+
+ {submitStatus !== 'sent' ? ( + <> +

+ Think this is a broken link?{' '} + {!showForm && ( + + )} +

+ {showForm && ( +
+
+ + +
+