1- import { useState } from "react"
1+ import { useEffect , useState } from "react"
22import { Button } from "~/components/ui/button"
33import {
44 Dialog ,
@@ -138,6 +138,13 @@ function TinyCheckbox({
138138function ProductTableBulkDelete ( ) {
139139 const [ products , setProducts ] = useState ( initialProducts )
140140 const [ selected , setSelected ] = useState < Set < number > > ( new Set ( ) )
141+ const [ toast , setToast ] = useState < string | null > ( null )
142+
143+ useEffect ( ( ) => {
144+ if ( ! toast ) return
145+ const t = setTimeout ( ( ) => setToast ( null ) , 3000 )
146+ return ( ) => clearTimeout ( t )
147+ } , [ toast ] )
141148
142149 function toggleRow ( id : number ) {
143150 setSelected ( ( prev ) => {
@@ -160,8 +167,12 @@ function ProductTableBulkDelete() {
160167 }
161168
162169 function handleDelete ( ) {
170+ const count = selected . size
163171 setProducts ( ( prev ) => prev . filter ( ( p ) => ! selected . has ( p . id ) ) )
164172 setSelected ( new Set ( ) )
173+ setToast (
174+ `${ count } ${ count === 1 ? "product" : "products" } deleted successfully.` ,
175+ )
165176 }
166177
167178 const allSelected = products . length > 0 && selected . size === products . length
@@ -277,6 +288,12 @@ function ProductTableBulkDelete() {
277288 Reset products
278289 </ Button >
279290 ) }
291+
292+ { toast && (
293+ < div className = "fixed bottom-4 left-1/2 -translate-x-1/2 rounded-md bg-emerald-600 px-4 py-2 text-sm text-white shadow-lg" >
294+ { toast }
295+ </ div >
296+ ) }
280297 </ div >
281298 )
282299}
@@ -285,7 +302,7 @@ export const productTableBulkDelete: MiniAppDefinition = {
285302 id : "product-table-bulk-delete" ,
286303 name : "Product Bulk Actions" ,
287304 introduction :
288- "A product inventory table with checkboxes for selecting rows and performing bulk actions." ,
305+ "A product inventory table with the ability to perform bulk actions." ,
289306 category : "lists" ,
290307 difficulty : "medium" ,
291308 component : ProductTableBulkDelete ,
0 commit comments