@@ -21,7 +21,8 @@ const ReportTable = ({
21
21
const [ actLoader , setActLoader ] = useState ( { } ) ;
22
22
const [ isAlert , setIsAlert ] = useState ( false ) ;
23
23
const [ isErr , setIsErr ] = useState ( false ) ;
24
- const [ isPopup , setIsPopup ] = useState ( false ) ;
24
+ const [ isContactform , setIsContactform ] = useState ( false ) ;
25
+ const [ isDeleteModal , setIsDeleteModal ] = useState ( { } ) ;
25
26
// For loop is used to calculate page numbers visible below table
26
27
// Initialize pageNumbers using useMemo to avoid unnecessary re-creation
27
28
const pageNumbers = useMemo ( ( ) => {
@@ -166,31 +167,7 @@ const ReportTable = ({
166
167
} ;
167
168
const handlebtn = async ( item ) => {
168
169
if ( ReportName === "Contactbook" ) {
169
- setActLoader ( { [ item . objectId ] : true } ) ;
170
- try {
171
- const url =
172
- process . env . REACT_APP_SERVERURL + "/classes/contracts_Contactbook/" ;
173
- const body = { IsDeleted : true } ;
174
- const res = await axios . put ( url + item . objectId , body , {
175
- headers : {
176
- "Content-Type" : "application/json" ,
177
- "X-Parse-Application-Id" : localStorage . getItem ( "AppID12" ) ,
178
- "X-Parse-Session-Token" : localStorage . getItem ( "accesstoken" )
179
- }
180
- } ) ;
181
- // console.log("Res ", res.data);
182
- if ( res . data && res . data . updatedAt ) {
183
- setActLoader ( { } ) ;
184
- setIsAlert ( true ) ;
185
- const upldatedList = List . filter ( ( x ) => x . objectId !== item . objectId ) ;
186
- setList ( upldatedList ) ;
187
- }
188
- } catch ( err ) {
189
- console . log ( "err" , err ) ;
190
- setIsAlert ( true ) ;
191
- setIsErr ( true ) ;
192
- setActLoader ( { } ) ;
193
- }
170
+ setIsDeleteModal ( { [ item . objectId ] : true } ) ;
194
171
}
195
172
} ;
196
173
@@ -204,13 +181,44 @@ const ReportTable = ({
204
181
const paginateFront = ( ) => setCurrentPage ( currentPage + 1 ) ;
205
182
const paginateBack = ( ) => setCurrentPage ( currentPage - 1 ) ;
206
183
207
- const handlePopup = ( ) => {
208
- setIsPopup ( ! isPopup ) ;
184
+ const handleContactFormModal = ( ) => {
185
+ setIsContactform ( ! isContactform ) ;
209
186
} ;
210
187
211
188
const handleUserData = ( data ) => {
212
189
setList ( ( prevData ) => [ data , ...prevData ] ) ;
213
190
} ;
191
+
192
+ const handleDelete = async ( item ) => {
193
+ setIsDeleteModal ( { } )
194
+ setActLoader ( { [ item . objectId ] : true } ) ;
195
+ try {
196
+ const url =
197
+ process . env . REACT_APP_SERVERURL + "/classes/contracts_Contactbook/" ;
198
+ const body = { IsDeleted : true } ;
199
+ const res = await axios . put ( url + item . objectId , body , {
200
+ headers : {
201
+ "Content-Type" : "application/json" ,
202
+ "X-Parse-Application-Id" : localStorage . getItem ( "AppID12" ) ,
203
+ "X-Parse-Session-Token" : localStorage . getItem ( "accesstoken" )
204
+ }
205
+ } ) ;
206
+ // console.log("Res ", res.data);
207
+ if ( res . data && res . data . updatedAt ) {
208
+ setActLoader ( { } ) ;
209
+ setIsAlert ( true ) ;
210
+ const upldatedList = List . filter ( ( x ) => x . objectId !== item . objectId ) ;
211
+ setList ( upldatedList ) ;
212
+ }
213
+ } catch ( err ) {
214
+ console . log ( "err" , err ) ;
215
+ setIsAlert ( true ) ;
216
+ setIsErr ( true ) ;
217
+ setActLoader ( { } ) ;
218
+ }
219
+ } ;
220
+ const handleCloseDeleteModal = ( ) => setIsDeleteModal ( { } ) ;
221
+
214
222
return (
215
223
< div className = "p-2 overflow-x-scroll w-full bg-white rounded-md" >
216
224
{ isAlert && (
@@ -228,7 +236,10 @@ const ReportTable = ({
228
236
< div className = "flex flex-row items-center justify-between my-2 mx-3 text-[20px] md:text-[23px]" >
229
237
< div className = "font-light" > { ReportName } </ div >
230
238
{ form && (
231
- < div className = "cursor-pointer" onClick = { ( ) => handlePopup ( ) } >
239
+ < div
240
+ className = "cursor-pointer"
241
+ onClick = { ( ) => handleContactFormModal ( ) }
242
+ >
232
243
< i className = "fa-solid fa-square-plus text-sky-400 text-[25px]" > </ i >
233
244
</ div >
234
245
) }
@@ -294,6 +305,30 @@ const ReportTable = ({
294
305
) }
295
306
</ button >
296
307
) ) }
308
+ { isDeleteModal [ item . objectId ] && (
309
+ < ModalUi isOpen title = { "Delete Contact" } handleClose = { handleCloseDeleteModal } >
310
+ < div className = "m-[20px]" >
311
+ < div className = "text-lg font-normal text-black" >
312
+ Are you sure you want to delete this contact?
313
+ </ div >
314
+ < hr className = "bg-[#ccc] mt-4 " />
315
+ < div className = "flex items-center mt-3 gap-2 text-white" >
316
+ < button
317
+ onClick = { ( ) => handleDelete ( item ) }
318
+ className = "bg-[#1ab6ce] rounded-sm shadow-md text-[12px] font-semibold uppercase text-white py-1.5 px-3 focus:outline-none"
319
+ >
320
+ Yes
321
+ </ button >
322
+ < button
323
+ onClick = { handleCloseDeleteModal }
324
+ className = "bg-[#188ae2] rounded-sm shadow-md text-[12px] font-semibold uppercase text-white py-1.5 px-3 text-center ml-[2px] focus:outline-none"
325
+ >
326
+ No
327
+ </ button >
328
+ </ div >
329
+ </ div >
330
+ </ ModalUi >
331
+ ) }
297
332
</ td >
298
333
</ tr >
299
334
) : (
@@ -421,10 +456,14 @@ const ReportTable = ({
421
456
< div className = "text-sm font-semibold" > No Data Available</ div >
422
457
</ div >
423
458
) }
424
- < ModalUi title = { "Add Contact" } isOpen = { isPopup } handleClose = { handlePopup } >
459
+ < ModalUi
460
+ title = { "Add Contact" }
461
+ isOpen = { isContactform }
462
+ handleClose = { handleContactFormModal }
463
+ >
425
464
< AppendFormInForm
426
465
handleUserData = { handleUserData }
427
- closePopup = { handlePopup }
466
+ closePopup = { handleContactFormModal }
428
467
/>
429
468
</ ModalUi >
430
469
</ div >
0 commit comments