@@ -17,13 +17,22 @@ export function TemplateEditor({ template, variables }: TemplateEditorProps) {
1717 const [ content , setContent ] = useState ( template . content ) ;
1818 const [ category , setCategory ] = useState ( template . category ) ;
1919 const [ tags , setTags ] = useState ( template . tags . join ( ', ' ) ) ;
20+ const [ error , setError ] = useState < string | null > ( null ) ;
21+ const [ success , setSuccess ] = useState < string | null > ( null ) ;
2022
2123 const handleSave = async ( ) => {
22- await TemplateService . updateTemplate ( template . id , {
23- content,
24- category,
25- tags : tags . split ( ',' ) . map ( t => t . trim ( ) ) ,
26- } ) ;
24+ try {
25+ setError ( null ) ;
26+ setSuccess ( null ) ;
27+ await TemplateService . updateTemplate ( template . id , {
28+ content,
29+ category,
30+ tags : tags . split ( ',' ) . map ( t => t . trim ( ) ) ,
31+ } ) ;
32+ setSuccess ( 'Template saved successfully!' ) ;
33+ } catch ( err ) {
34+ setError ( 'Failed to save template.' ) ;
35+ }
2736 } ;
2837
2938 const generateContent = ( ) => {
@@ -69,6 +78,8 @@ export function TemplateEditor({ template, variables }: TemplateEditorProps) {
6978 < Button onClick = { handleSave } > Save</ Button >
7079 < Button onClick = { copyToClipboard } > Copy to Clipboard</ Button >
7180 </ div >
81+ { error && < p className = "text-red-500" > { error } </ p > }
82+ { success && < p className = "text-green-500" > { success } </ p > }
7283 </ div >
7384 </ div >
7485 </ Card >
0 commit comments