11import { useState } from 'react' ;
22import { useNavigate } from 'react-router-dom' ;
3+ import { toast } from 'sonner' ;
34import { designStorage , Design } from '../services/designStorage' ;
45import {
56 Plus ,
@@ -25,50 +26,68 @@ export const MyDesigns = () => {
2526 const [ showImportModal , setShowImportModal ] = useState ( false ) ;
2627 const [ importJson , setImportJson ] = useState ( '' ) ;
2728 const [ importName , setImportName ] = useState ( '' ) ;
29+ const [ showDeleteConfirm , setShowDeleteConfirm ] = useState ( false ) ;
30+ const [ deleteTargetId , setDeleteTargetId ] = useState < string | null > ( null ) ;
31+ const [ deleteTargetName , setDeleteTargetName ] = useState < string > ( '' ) ;
2832
2933 const loadDesigns = ( ) => {
3034 setDesigns ( designStorage . getAllDesigns ( ) ) ;
3135 } ;
3236
33- const handleDelete = ( id : string ) => {
34- if ( confirm ( 'Are you sure you want to delete this design?' ) ) {
35- designStorage . deleteDesign ( id ) ;
37+ const handleDelete = ( id : string , name : string ) => {
38+ setDeleteTargetId ( id ) ;
39+ setDeleteTargetName ( name ) ;
40+ setShowDeleteConfirm ( true ) ;
41+ } ;
42+
43+ const confirmDelete = ( ) => {
44+ if ( deleteTargetId ) {
45+ designStorage . deleteDesign ( deleteTargetId ) ;
3646 loadDesigns ( ) ;
47+ toast . success ( 'Design deleted successfully' ) ;
48+ setShowDeleteConfirm ( false ) ;
49+ setDeleteTargetId ( null ) ;
50+ setDeleteTargetName ( '' ) ;
3751 }
3852 } ;
3953
4054 const handleClone = ( id : string ) => {
4155 try {
4256 const cloned = designStorage . cloneDesign ( id ) ;
4357 loadDesigns ( ) ;
58+ toast . success ( 'Design cloned successfully' ) ;
4459 navigate ( `/studio/${ cloned . id } ` ) ;
4560 } catch ( error ) {
46- alert ( 'Error cloning design: ' + ( error as Error ) . message ) ;
61+ const message = error instanceof Error ? error . message : 'Unknown error' ;
62+ toast . error ( `Failed to clone design: ${ message } ` ) ;
4763 }
4864 } ;
4965
5066 const handleShare = ( id : string ) => {
5167 try {
5268 const shareUrl = designStorage . shareDesign ( id ) ;
5369 navigator . clipboard . writeText ( shareUrl ) ;
54- alert ( 'Share link copied to clipboard!' ) ;
70+ toast . success ( 'Share link copied to clipboard!' ) ;
5571 } catch ( error ) {
56- alert ( 'Error sharing design: ' + ( error as Error ) . message ) ;
72+ const message = error instanceof Error ? error . message : 'Unknown error' ;
73+ toast . error ( `Failed to share design: ${ message } ` ) ;
5774 }
5875 } ;
5976
6077 const handleExport = ( id : string ) => {
6178 try {
62- const json = designStorage . exportDesign ( id ) ;
79+ const { json, filename } = designStorage . exportDesign ( id ) ;
6380 const blob = new Blob ( [ json ] , { type : 'application/json' } ) ;
6481 const url = URL . createObjectURL ( blob ) ;
6582 const a = document . createElement ( 'a' ) ;
6683 a . href = url ;
67- a . download = `design- ${ id } .json` ;
84+ a . download = filename ;
6885 a . click ( ) ;
6986 URL . revokeObjectURL ( url ) ;
87+ toast . success ( 'Design exported successfully' ) ;
7088 } catch ( error ) {
71- alert ( 'Error exporting design: ' + ( error as Error ) . message ) ;
89+ const message = error instanceof Error ? error . message : 'Unknown error' ;
90+ toast . error ( `Failed to export design: ${ message } ` ) ;
7291 }
7392 } ;
7493
@@ -79,9 +98,11 @@ export const MyDesigns = () => {
7998 setImportJson ( '' ) ;
8099 setImportName ( '' ) ;
81100 loadDesigns ( ) ;
101+ toast . success ( 'Design imported successfully' ) ;
82102 navigate ( `/studio/${ imported . id } ` ) ;
83103 } catch ( error ) {
84- alert ( 'Error importing design: ' + ( error as Error ) . message ) ;
104+ const message = error instanceof Error ? error . message : 'Unknown error' ;
105+ toast . error ( `Failed to import design: ${ message } ` ) ;
85106 }
86107 } ;
87108
@@ -258,7 +279,7 @@ export const MyDesigns = () => {
258279 < button
259280 onClick = { ( e ) => {
260281 e . stopPropagation ( ) ;
261- handleDelete ( design . id ) ;
282+ handleDelete ( design . id , design . name ) ;
262283 } }
263284 className = "p-2 text-gray-600 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors"
264285 title = "Delete"
@@ -331,7 +352,7 @@ export const MyDesigns = () => {
331352 < button
332353 onClick = { ( e ) => {
333354 e . stopPropagation ( ) ;
334- handleDelete ( design . id ) ;
355+ handleDelete ( design . id , design . name ) ;
335356 } }
336357 className = "p-2 text-gray-600 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors"
337358 title = "Delete"
@@ -400,6 +421,41 @@ export const MyDesigns = () => {
400421 </ div >
401422 </ div >
402423 ) }
424+
425+ { /* Delete Confirmation Modal */ }
426+ { showDeleteConfirm && (
427+ < div className = "fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4" >
428+ < div className = "bg-white rounded-2xl shadow-2xl max-w-md w-full" >
429+ < div className = "p-6 border-b border-gray-200" >
430+ < h2 className = "text-2xl font-bold text-gray-900" > Delete Design</ h2 >
431+ < p className = "text-sm text-gray-600 mt-1" > This action cannot be undone</ p >
432+ </ div >
433+ < div className = "p-6" >
434+ < p className = "text-gray-700" >
435+ Are you sure you want to delete < strong className = "text-gray-900" > "{ deleteTargetName } "</ strong > ? This will permanently remove the design and cannot be recovered.
436+ </ p >
437+ </ div >
438+ < div className = "p-6 border-t border-gray-200 flex items-center justify-end gap-3" >
439+ < button
440+ onClick = { ( ) => {
441+ setShowDeleteConfirm ( false ) ;
442+ setDeleteTargetId ( null ) ;
443+ setDeleteTargetName ( '' ) ;
444+ } }
445+ className = "px-4 py-2 text-sm font-semibold text-gray-700 bg-white hover:bg-gray-50 border-2 border-gray-200 rounded-xl transition-all"
446+ >
447+ Cancel
448+ </ button >
449+ < button
450+ onClick = { confirmDelete }
451+ className = "px-4 py-2 text-sm font-bold text-white bg-gradient-to-r from-red-600 to-pink-600 hover:from-red-700 hover:to-pink-700 rounded-xl shadow-lg shadow-red-300/50 transition-all"
452+ >
453+ Delete Design
454+ </ button >
455+ </ div >
456+ </ div >
457+ </ div >
458+ ) }
403459 </ div >
404460 ) ;
405461} ;
0 commit comments