@@ -10,36 +10,36 @@ export const action = async ({ request }: ActionFunctionArgs) => {
1010 const userId = await requireUserId ( request ) ;
1111
1212 const formData = await request . formData ( ) ;
13- const title = formData . get ( "title " ) ;
13+ const essayPrompt = formData . get ( "essayPrompt " ) ;
1414 const body = formData . get ( "body" ) ;
1515
16- if ( typeof title !== "string" || title . length === 0 ) {
16+ if ( typeof essayPrompt !== "string" || essayPrompt . length === 0 ) {
1717 return json (
18- { errors : { body : null , title : "Title is required" } } ,
18+ { errors : { body : null , essayPrompt : "Essay prompt is required" } } ,
1919 { status : 400 } ,
2020 ) ;
2121 }
2222
2323 if ( typeof body !== "string" || body . length === 0 ) {
2424 return json (
25- { errors : { body : "Body is required" , title : null } } ,
25+ { errors : { body : "Body is required" , essayPrompt : null } } ,
2626 { status : 400 } ,
2727 ) ;
2828 }
2929
30- const essay = await createEssay ( { body, title , userId } ) ;
30+ const essay = await createEssay ( { body, essayPrompt , userId } ) ;
3131
3232 return redirect ( `/essays/${ essay . id } ` ) ;
3333} ;
3434
3535export default function NewNotePage ( ) {
3636 const actionData = useActionData < typeof action > ( ) ;
37- const titleRef = useRef < HTMLInputElement > ( null ) ;
37+ const essayPromptRef = useRef < HTMLInputElement > ( null ) ;
3838 const bodyRef = useRef < HTMLTextAreaElement > ( null ) ;
3939
4040 useEffect ( ( ) => {
41- if ( actionData ?. errors ?. title ) {
42- titleRef . current ?. focus ( ) ;
41+ if ( actionData ?. errors ?. essayPrompt ) {
42+ essayPromptRef . current ?. focus ( ) ;
4343 } else if ( actionData ?. errors ?. body ) {
4444 bodyRef . current ?. focus ( ) ;
4545 }
@@ -57,20 +57,20 @@ export default function NewNotePage() {
5757 >
5858 < div >
5959 < label className = "flex w-full flex-col gap-1" >
60- < span > Title : </ span >
60+ < span > Essay prompt : </ span >
6161 < input
62- ref = { titleRef }
63- name = "title "
62+ ref = { essayPromptRef }
63+ name = "essayPrompt "
6464 className = "flex-1 rounded-md border-2 border-blue-500 px-3 text-lg leading-loose"
65- aria-invalid = { actionData ?. errors ?. title ? true : undefined }
65+ aria-invalid = { actionData ?. errors ?. essayPrompt ? true : undefined }
6666 aria-errormessage = {
67- actionData ?. errors ?. title ? "title -error" : undefined
67+ actionData ?. errors ?. essayPrompt ? "essayPrompt -error" : undefined
6868 }
6969 />
7070 </ label >
71- { actionData ?. errors ?. title ? (
72- < div className = "pt-1 text-red-700" id = "title -error" >
73- { actionData . errors . title }
71+ { actionData ?. errors ?. essayPrompt ? (
72+ < div className = "pt-1 text-red-700" id = "essayPrompt -error" >
73+ { actionData . errors . essayPrompt }
7474 </ div >
7575 ) : null }
7676 </ div >
0 commit comments