diff --git a/src/pages/create/description.tsx b/src/pages/create/description.tsx index 206634f..d13a8a0 100644 --- a/src/pages/create/description.tsx +++ b/src/pages/create/description.tsx @@ -1,4 +1,4 @@ -import React, { useState, FormEvent } from 'react'; +import React, { useState, useEffect } from 'react'; import { useRouter } from 'next/router'; import { useSession } from 'next-auth/react'; import Layout from '~/components/Layout'; @@ -6,51 +6,56 @@ import Layout from '~/components/Layout'; interface Props {} const Description: React.FC = () => { - const { status } = useSession(); const router = useRouter(); + const { data: session } = useSession(); const [description, setDescription] = useState(''); + const [error, setError] = useState(''); - if (status === 'unauthenticated') { - router.push('/login'); - } + useEffect(() => { + if (!session) { + router.push('/login'); + } + }, [session]); - const handleSubmit = async (e: FormEvent) => { - e.preventDefault(); + const handleSubmit = async (event: React.FormEvent) => { + event.preventDefault(); try { - // Call the API endpoint to save the project description to the database - // If the API call is successful, navigate to the next step in the project creation flow + const response = await fetch('/api/projects', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ description }), + }); + + if (!response.ok) { + throw new Error('Failed to save project description'); + } + router.push('/create/setup'); } catch (error) { - // Handle any errors that may occur during the API call and display an appropriate error message to the user - console.error('Error saving project description:', error); + setError((error as any).message); } }; return ( -
-

Project Description

-
- -