@@ -19,9 +19,10 @@ import { axios } from "../../data/axios";
19
19
import SheetDeleteDialog from "./SheetDeleteDialog" ;
20
20
import { useEffect } from "react" ;
21
21
22
- function SheetListItem ( { sheet, onDelete } ) {
22
+ function SheetListItem ( { sheet, onDelete, onEdit } ) {
23
23
const navigate = useNavigate ( ) ;
24
24
const [ deleteDialogOpen , setDeleteDialogOpen ] = useState ( false ) ;
25
+ const [ editDialogOpen , setEditDialogOpen ] = useState ( false ) ;
25
26
26
27
const handleDelete = ( ) => {
27
28
setDeleteDialogOpen ( true ) ;
@@ -32,48 +33,63 @@ function SheetListItem({ sheet, onDelete }) {
32
33
setDeleteDialogOpen ( false ) ;
33
34
} ;
34
35
36
+ const handleEdit = ( e ) => {
37
+ e . stopPropagation ( ) ;
38
+ setEditDialogOpen ( true ) ;
39
+ } ;
40
+
35
41
return (
36
- < TableRow
37
- key = { sheet . uuid }
38
- onClick = { ( ) => navigate ( `/sheets/${ sheet . uuid } ` ) }
39
- sx = { {
40
- cursor : "pointer" ,
41
- "&:hover" : {
42
- backgroundColor : "rgba(0, 0, 0, 0.04)" ,
43
- } ,
44
- } }
45
- >
46
- < TableCell >
47
- < Typography variant = "subtitle2" sx = { { fontWeight : "normal" } } >
48
- { sheet . name }
49
- </ Typography >
50
- </ TableCell >
51
- < TableCell >
52
- < Typography variant = "body2" sx = { { color : "text.secondary" } } >
53
- { sheet . data ?. description || "No description available" }
54
- </ Typography >
55
- </ TableCell >
56
- < TableCell >
57
- < IconButton aria-label = "edit" onClick = { ( e ) => e . stopPropagation ( ) } >
58
- < EditOutlined />
59
- </ IconButton >
60
- < IconButton
61
- aria-label = "delete"
62
- onClick = { ( e ) => {
63
- e . stopPropagation ( ) ;
64
- handleDelete ( ) ;
65
- } }
66
- >
67
- < DeleteOutlineOutlined />
68
- </ IconButton >
69
- </ TableCell >
42
+ < >
43
+ < TableRow
44
+ key = { sheet . uuid }
45
+ onClick = { ( ) => navigate ( `/sheets/${ sheet . uuid } ` ) }
46
+ sx = { {
47
+ cursor : "pointer" ,
48
+ "&:hover" : {
49
+ backgroundColor : "rgba(0, 0, 0, 0.04)" ,
50
+ } ,
51
+ } }
52
+ >
53
+ < TableCell >
54
+ < Typography variant = "subtitle2" sx = { { fontWeight : "normal" } } >
55
+ { sheet . name }
56
+ </ Typography >
57
+ </ TableCell >
58
+ < TableCell >
59
+ < Typography variant = "body2" sx = { { color : "text.secondary" } } >
60
+ { sheet . description || "No description available" }
61
+ </ Typography >
62
+ </ TableCell >
63
+ < TableCell >
64
+ < IconButton aria-label = "edit" onClick = { handleEdit } >
65
+ < EditOutlined />
66
+ </ IconButton >
67
+ < IconButton
68
+ aria-label = "delete"
69
+ onClick = { ( e ) => {
70
+ e . stopPropagation ( ) ;
71
+ handleDelete ( ) ;
72
+ } }
73
+ >
74
+ < DeleteOutlineOutlined />
75
+ </ IconButton >
76
+ </ TableCell >
77
+ </ TableRow >
70
78
< SheetDeleteDialog
71
79
open = { deleteDialogOpen }
72
80
onClose = { ( ) => setDeleteDialogOpen ( false ) }
73
81
onConfirm = { confirmDelete }
74
82
sheetName = { sheet . name }
75
83
/>
76
- </ TableRow >
84
+ < SheetFromTemplateDialog
85
+ open = { editDialogOpen }
86
+ setOpen = { setEditDialogOpen }
87
+ sheet = { sheet }
88
+ setSheet = { onEdit }
89
+ sheetId = { sheet . uuid }
90
+ setSheetId = { ( ) => { } }
91
+ />
92
+ </ >
77
93
) ;
78
94
}
79
95
@@ -102,6 +118,15 @@ function SheetsList() {
102
118
} ) ;
103
119
} ;
104
120
121
+ const handleEditSheet = ( updatedSheet ) => {
122
+ setSheets ( ( prevSheets ) =>
123
+ prevSheets . map ( ( sheet ) =>
124
+ sheet . uuid === updatedSheet . uuid ? updatedSheet : sheet ,
125
+ ) ,
126
+ ) ;
127
+ enqueueSnackbar ( "Sheet updated successfully" , { variant : "success" } ) ;
128
+ } ;
129
+
105
130
return (
106
131
< Stack >
107
132
< Typography variant = "h5" className = "section-header" >
@@ -139,6 +164,7 @@ function SheetsList() {
139
164
key = { sheet . uuid }
140
165
sheet = { sheet }
141
166
onDelete = { handleDeleteSheet }
167
+ onEdit = { handleEditSheet }
142
168
/>
143
169
) )
144
170
) : (
0 commit comments