11'use client' ;
22
3- import { useState , useEffect } from 'react' ;
3+ import { useState } from 'react' ;
44import { useRouter } from 'next/navigation' ;
5- import type { LinkWork , WorkType } from '@/types' ;
5+ import type { LinkWork } from '@/types' ;
6+ import { formatWorkType } from '@/lib/utils' ;
67
78interface ResearchFormProps {
89 mode : 'create' | 'edit' ;
910 initialData ?: LinkWork & { rkey ?: string } ;
1011}
1112
12- const WORK_TYPES : { value : WorkType ; label : string } [ ] = [
13- { value : 'abstract' , label : 'Abstract' } ,
14- { value : 'poster' , label : 'Poster' } ,
15- { value : 'paper' , label : 'Paper' } ,
16- { value : 'conference-proceeding' , label : 'Conference Proceeding' } ,
17- { value : 'journal-article' , label : 'Journal Article' } ,
18- { value : 'book-chapter' , label : 'Book Chapter' } ,
19- { value : 'book' , label : 'Book' } ,
20- { value : 'preprint' , label : 'Preprint' } ,
21- { value : 'dataset' , label : 'Dataset' } ,
22- { value : 'other' , label : 'Other' } ,
23- ] ;
24-
2513export default function ResearchForm ( { mode, initialData } : ResearchFormProps ) {
2614 const router = useRouter ( ) ;
2715 const [ loading , setLoading ] = useState ( false ) ;
2816 const [ resolvingDOI , setResolvingDOI ] = useState ( false ) ;
2917 const [ error , setError ] = useState ( '' ) ;
30- const [ resolvedMetadata , setResolvedMetadata ] = useState < any > ( null ) ;
18+ const [ resolvedMetadata , setResolvedMetadata ] = useState < {
19+ title ?: string ;
20+ authors ?: string [ ] ;
21+ journal ?: string ;
22+ publicationDate ?: string ;
23+ type ?: string ;
24+ abstract ?: string ;
25+ url ?: string ;
26+ } | null > ( null ) ;
3127 const [ showDuplicateWarning , setShowDuplicateWarning ] = useState ( false ) ;
3228
33- const [ formData , setFormData ] = useState < {
34- doi : string ;
35- type : WorkType | '' ;
36- rkey ?: string ;
37- } > ( {
29+ const [ formData , setFormData ] = useState ( {
3830 doi : initialData ?. doi || '' ,
39- type : initialData ?. type || '' ,
4031 rkey : initialData ?. rkey ,
4132 } ) ;
4233
@@ -72,12 +63,10 @@ export default function ResearchForm({ mode, initialData }: ResearchFormProps) {
7263 setShowDuplicateWarning ( false ) ;
7364
7465 try {
75- const payload = mode === 'create'
76- ? { doi : formData . doi , type : formData . type , bypassDuplicateCheck }
77- : { rkey : formData . rkey , type : formData . type } ;
66+ const payload = { doi : formData . doi , bypassDuplicateCheck } ;
7867
7968 const response = await fetch ( '/api/profile/works' , {
80- method : mode === 'create' ? ' POST' : 'PUT ',
69+ method : ' POST',
8170 headers : {
8271 'Content-Type' : 'application/json' ,
8372 } ,
@@ -201,7 +190,7 @@ export default function ResearchForm({ mode, initialData }: ResearchFormProps) {
201190 ) }
202191 { resolvedMetadata . type && (
203192 < p className = "text-sm text-blue-800 mb-1" >
204- < strong > Type:</ strong > { resolvedMetadata . type }
193+ < strong > Type:</ strong > { formatWorkType ( resolvedMetadata . type ) }
205194 </ p >
206195 ) }
207196 { resolvedMetadata . abstract && (
@@ -250,6 +239,11 @@ export default function ResearchForm({ mode, initialData }: ResearchFormProps) {
250239 < strong > Published:</ strong > { new Date ( initialData . publicationDate ) . getFullYear ( ) }
251240 </ p >
252241 ) }
242+ { initialData . type && (
243+ < p className = "text-sm text-gray-800 mb-1" >
244+ < strong > Type:</ strong > { formatWorkType ( initialData . type ) }
245+ </ p >
246+ ) }
253247 { ( 'abstract' in initialData && initialData . abstract && typeof initialData . abstract === 'string' ) ? (
254248 < p className = "text-sm text-gray-800 mb-1" >
255249 < strong > Abstract:</ strong > { initialData . abstract . substring ( 0 , 200 ) } { initialData . abstract . length > 200 ? '...' : '' }
@@ -270,27 +264,6 @@ export default function ResearchForm({ mode, initialData }: ResearchFormProps) {
270264 ) : null }
271265 </ div >
272266 ) }
273-
274- < div >
275- < label className = "block text-sm font-medium text-gray-700 mb-2" >
276- Type *
277- </ label >
278- < select
279- value = { formData . type }
280- onChange = { ( e ) =>
281- setFormData ( { ...formData , type : e . target . value as WorkType } )
282- }
283- required
284- className = "w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"
285- >
286- < option value = "" > Select type...</ option >
287- { WORK_TYPES . map ( ( type ) => (
288- < option key = { type . value } value = { type . value } >
289- { type . label }
290- </ option >
291- ) ) }
292- </ select >
293- </ div >
294267 </ div >
295268
296269 { error && (
@@ -310,27 +283,23 @@ export default function ResearchForm({ mode, initialData }: ResearchFormProps) {
310283 ) }
311284
312285 < div className = "flex flex-col gap-3 mt-6" >
313- < button
314- type = "submit"
315- disabled = { loading }
316- className = "w-full bg-blue-600 text-white py-3 px-6 rounded-lg font-medium hover:bg-blue-700 disabled:bg-gray-300 disabled:cursor-not-allowed transition-colors"
317- >
318- { loading
319- ? mode === 'create'
320- ? 'Adding...'
321- : 'Saving...'
322- : mode === 'create'
323- ? 'Add Research'
324- : 'Save Changes' }
325- </ button >
286+ { mode === 'create' && (
287+ < button
288+ type = "submit"
289+ disabled = { loading }
290+ className = "w-full bg-blue-600 text-white py-3 px-6 rounded-lg font-medium hover:bg-blue-700 disabled:bg-gray-300 disabled:cursor-not-allowed transition-colors"
291+ >
292+ { loading ? 'Adding...' : 'Add Research' }
293+ </ button >
294+ ) }
326295
327296 < button
328297 type = "button"
329298 onClick = { ( ) => router . push ( '/dashboard/research' ) }
330299 disabled = { loading }
331300 className = "w-full py-3 px-6 border border-gray-300 rounded-lg hover:bg-gray-50 transition-colors disabled:opacity-50"
332301 >
333- Cancel
302+ { mode === 'edit' ? 'Back' : ' Cancel' }
334303 </ button >
335304
336305 { mode === 'edit' && (
0 commit comments