@@ -3,7 +3,7 @@ import { useState, useEffect } from 'react';
33import { ONE_DAY_IN_MILLISECONDS } from '../utils/dates' ;
44import toast from 'react-hot-toast' ;
55import { Button } from './ui/button' ;
6- import { Trash2 } from 'lucide-react' ;
6+ import { Trash2 , Pencil } from 'lucide-react' ;
77import { getIndicatorColor } from '../utils/helpers' ;
88import {
99 AlertDialog ,
@@ -16,6 +16,16 @@ import {
1616 AlertDialogTitle ,
1717 AlertDialogTrigger ,
1818} from './ui/alert-dialog' ;
19+ import {
20+ Dialog ,
21+ DialogContent ,
22+ DialogDescription ,
23+ DialogFooter ,
24+ DialogHeader ,
25+ DialogTitle ,
26+ DialogTrigger ,
27+ } from '@/components/ui/dialog' ;
28+ import EditItemForm from './ManageListForms/EditItemForm' ;
1929
2030export function ListItem ( {
2131 listPath,
@@ -28,6 +38,9 @@ export function ListItem({
2838 dayInterval,
2939 dateCreated,
3040 indicator,
41+ isOpen,
42+ handleOpenModal,
43+ dateNextPurchased,
3144} ) {
3245 const [ isAlertOpen , setIsAlertOpen ] = useState ( false ) ;
3346
@@ -81,7 +94,7 @@ export function ListItem({
8194 >
8295 < label
8396 htmlFor = { `${ id } ` }
84- className = "capitalize text-sm hover:font-bold sm :text-lg "
97+ className = "capitalize text-sm sm:text-base md:text-lg hover:font-bold text-gray-800 dark :text-gray-300 "
8598 >
8699 { name }
87100 </ label >
@@ -92,51 +105,77 @@ export function ListItem({
92105 </ div >
93106 ) }
94107 </ div >
95- < div className = "flex items-center gap-1 sm:gap-2 " >
108+ < div className = "flex items-center gap-3 " >
96109 < div
97110 className = { `${ getIndicatorColor ( indicator ) } rounded-[3px] px-2 sm:rounded-[5px] sm:px-3` }
98111 >
99112 < p className = "capitalize text-xs sm:text-sm text-black dark:text-gray-800" >
100113 { indicator }
101114 </ p >
102115 </ div >
103- < AlertDialog open = { isAlertOpen } onOpenChange = { setIsAlertOpen } >
104- < AlertDialogTrigger asChild >
105- < Button
106- className = "bg-transparent hover:bg-transparent"
107- type = "button"
108- id = { id }
109- onClick = { ( ) => setIsAlertOpen ( true ) }
110- >
111- < Trash2 className = "w-5 h-5 text-ruby-pink hover:text-opacity-75 dark:text-emerald-500 dark:hover:text-opacity-80 sm:w-6 sm:h-6 md:w-7 md:h-7" />
112- </ Button >
113- </ AlertDialogTrigger >
114- < AlertDialogContent className = "p-6 sm:p-10" >
115- < AlertDialogHeader >
116- < AlertDialogTitle className = "text-sm text-slate-500 dark:text-slate-400 sm:text-lg" >
117- Are you absolutely sure?
118- </ AlertDialogTitle >
119- < AlertDialogDescription className = "text-black" >
120- This action cannot be undone. Do you really want to delete{ ' ' }
121- { name } ?
122- </ AlertDialogDescription >
123- </ AlertDialogHeader >
124- < AlertDialogFooter >
125- < AlertDialogCancel
126- className = "bg-white hover:bg-slate-100 px-6 border rounded-lg sm:px-8 sm:rounded-xl"
127- onClick = { ( ) => setIsAlertOpen ( false ) }
128- >
129- Cancel
130- </ AlertDialogCancel >
131- < AlertDialogAction
132- className = "bg-primary-pink hover:bg-opacity-75 rounded-lg sm:rounded-xl"
133- onClick = { handleDelete }
116+ < div className = "flex gap-3 px-1" >
117+ < Dialog open = { isOpen } onOpenChange = { ( ) => handleOpenModal ( id ) } >
118+ < DialogTrigger asChild >
119+ < Button className = "bg-transparent hover:bg-transparent p-0" >
120+ < Pencil className = "w-5 h-5 md:w-6 md:h-6 text-light-grey hover:text-opacity-75 dark:text-emerald-500 dark:hover:text-opacity-80 transform hover:scale-110 transition-transform duration-150 sm:hover:scale-125" />
121+ </ Button >
122+ </ DialogTrigger >
123+ < DialogContent >
124+ < DialogHeader >
125+ < DialogTitle > Edit { name } </ DialogTitle >
126+ < DialogDescription className = "text-md md:text-lg" >
127+ Modify the details of the item you'd like to edit.
128+ </ DialogDescription >
129+ </ DialogHeader >
130+ < EditItemForm
131+ listPath = { listPath }
132+ name = { name }
133+ id = { id }
134+ quantity = { quantity }
135+ dateNextPurchased = { dateNextPurchased }
136+ handleOpenModal = { handleOpenModal }
137+ />
138+ < DialogFooter className = "sm:justify-start" > </ DialogFooter >
139+ </ DialogContent >
140+ </ Dialog >
141+ < AlertDialog open = { isAlertOpen } onOpenChange = { setIsAlertOpen } >
142+ < AlertDialogTrigger asChild >
143+ < Button
144+ className = "bg-transparent hover:bg-transparent p-0"
145+ type = "button"
146+ id = { id }
147+ onClick = { ( ) => setIsAlertOpen ( true ) }
134148 >
135- Continue
136- </ AlertDialogAction >
137- </ AlertDialogFooter >
138- </ AlertDialogContent >
139- </ AlertDialog >
149+ < Trash2 className = "w-5 h-5 md:w-6 md:h-6 text-gray-600 hover:text-opacity-75 dark:text-emerald-500 dark:hover:text-opacity-80 transform hover:scale-110 transition-transform duration-150 sm:hover:scale-125" />
150+ </ Button >
151+ </ AlertDialogTrigger >
152+ < AlertDialogContent className = "p-6 sm:p-10" >
153+ < AlertDialogHeader >
154+ < AlertDialogTitle className = "text-sm text-slate-800 dark:text-slate-400 sm:text-lg" >
155+ Are you absolutely sure?
156+ </ AlertDialogTitle >
157+ < AlertDialogDescription className = "text-slate-700" >
158+ This action cannot be undone. Do you really want to delete{ ' ' }
159+ { name } ?
160+ </ AlertDialogDescription >
161+ </ AlertDialogHeader >
162+ < AlertDialogFooter >
163+ < AlertDialogCancel
164+ className = "bg-white text-slate-700 hover:bg-slate-100 px-6 border rounded-lg sm:px-8 sm:rounded-xl"
165+ onClick = { ( ) => setIsAlertOpen ( false ) }
166+ >
167+ Cancel
168+ </ AlertDialogCancel >
169+ < AlertDialogAction
170+ className = "bg-primary-pink text-white hover:bg-opacity-90 px-6 border rounded-lg sm:px-8 sm:rounded-xl"
171+ onClick = { handleDelete }
172+ >
173+ Delete
174+ </ AlertDialogAction >
175+ </ AlertDialogFooter >
176+ </ AlertDialogContent >
177+ </ AlertDialog >
178+ </ div >
140179 </ div >
141180 </ li >
142181 ) ;
0 commit comments