@@ -33,10 +33,12 @@ import { Library } from '@/lib/types/library'
3333import { useState , useEffect , useCallback } from 'react'
3434import { Input } from '@/components/ui/input'
3535import { Book } from '@/lib/types/book'
36+ import Image from 'next/image'
37+ import { ImageUploader } from '../common/ImageUploader'
3638
3739export type BookFormValues = Pick <
3840 Book ,
39- 'title' | 'author' | 'year' | 'code' | 'library_id'
41+ 'title' | 'author' | 'year' | 'code' | 'library_id' | 'cover'
4042>
4143
4244type BookFormProps = {
@@ -70,6 +72,7 @@ const FormSchema = z.object({
7072 required_error : 'Please select the library.' ,
7173 } )
7274 . uuid ( ) ,
75+ cover : z . string ( ) . optional ( ) ,
7376} )
7477
7578export const BookForm : React . FC < BookFormProps > = ( {
@@ -104,6 +107,8 @@ export const BookForm: React.FC<BookFormProps> = ({
104107 form . reset ( )
105108 } , [ form ] )
106109
110+ const title = form . watch ( 'title' )
111+
107112 return (
108113 < div className = "grid place-items-center" >
109114 < Form { ...form } >
@@ -246,6 +251,37 @@ export const BookForm: React.FC<BookFormProps> = ({
246251 ) }
247252 />
248253
254+ { initialData . cover && (
255+ < Image
256+ className = "w-12 h-auto rounded col-span-2"
257+ src = { initialData . cover }
258+ alt = { initialData . title }
259+ width = { 50 }
260+ height = { 50 }
261+ />
262+ ) }
263+
264+ { title && (
265+ < FormField
266+ control = { form . control }
267+ name = "cover"
268+ render = { ( { field } ) => (
269+ < FormItem className = "flex flex-col" >
270+ < FormLabel > Cover Image URL</ FormLabel >
271+ < FormControl >
272+ < ImageUploader
273+ { ...field }
274+ imageName = { title }
275+ value = { field . value }
276+ onChange = { field . onChange }
277+ />
278+ </ FormControl >
279+ < FormMessage />
280+ </ FormItem >
281+ ) }
282+ />
283+ ) }
284+
249285 < Button type = "reset" variant = "ghost" onClick = { onReset } >
250286 Reset
251287 </ Button >
0 commit comments