11"use client" ;
22
3+ import { ConfirmModal } from "@/components/ConfirmModal" ;
34import { ImportTable } from "@/components/tables/ImportTable" ;
4- import { ImportList } from "@/lib/crud/importCsv" ;
5+ import { ImportList , rollbackImport } from "@/lib/crud/importCsv" ;
56import { Accordion , Badge , Button , Group , Paper , Stack , Text , Title } from "@mantine/core" ;
7+ import { useDisclosure } from "@mantine/hooks" ;
68import React from "react" ;
79import { FaUndo } from "react-icons/fa" ;
810
911interface ImportsListProps {
1012 imports : ImportList ;
1113}
1214
15+ const ImportItem : React . FC < { importItem : ImportList [ 0 ] } > = ( { importItem } ) => {
16+ const [ opened , { open, close } ] = useDisclosure ( false ) ;
17+
18+ return (
19+ < Stack gap = "xl" >
20+ < Paper p = "md" withBorder >
21+ < ConfirmModal
22+ onConfirm = { async ( ) => {
23+ await rollbackImport ( importItem . id ) ;
24+ } }
25+ confirmButtonText = { `Rollback Import` }
26+ opened = { opened }
27+ close = { close }
28+ >
29+ < Text >
30+ This will delete all < strong > { importItem . _count . OrderItem } </ strong > items
31+ imported in the import < strong > { importItem . name } </ strong > !
32+ </ Text >
33+ < Text > This action cannot be undone. Are you sure you want to proceed?</ Text >
34+ </ ConfirmModal >
35+ < Group justify = "space-between" >
36+ < Title order = { 5 } > Actions</ Title >
37+ < Group >
38+ < Button
39+ color = "red"
40+ variant = "outline"
41+ leftSection = { < FaUndo /> }
42+ onClick = { open }
43+ >
44+ Rollback Import
45+ </ Button >
46+ </ Group >
47+ </ Group >
48+ </ Paper >
49+ < ImportTable importId = { importItem . id } />
50+ </ Stack >
51+ ) ;
52+ } ;
53+
1354export const ImportsList : React . FC < ImportsListProps > = ( { imports } ) => {
1455 return (
1556 < Paper p = "lg" withBorder mt = "xl" >
1657 < Stack >
1758 < Title order = { 3 } > Previous Imports</ Title >
59+
1860 < Accordion >
1961 { imports . map ( ( importItem , index ) => (
2062 < Accordion . Item key = { index } value = { importItem . id } >
@@ -25,23 +67,7 @@ export const ImportsList: React.FC<ImportsListProps> = ({ imports }) => {
2567 </ Group >
2668 </ Accordion . Control >
2769 < Accordion . Panel pl = "md" pr = "md" >
28- < Stack gap = "xl" >
29- < Paper p = "md" withBorder >
30- < Group justify = "space-between" >
31- < Title order = { 5 } > Actions</ Title >
32- < Group >
33- < Button
34- color = "red"
35- variant = "outline"
36- leftSection = { < FaUndo /> }
37- >
38- Rollback Import
39- </ Button >
40- </ Group >
41- </ Group >
42- </ Paper >
43- < ImportTable importId = { importItem . id } />
44- </ Stack >
70+ < ImportItem importItem = { importItem } />
4571 </ Accordion . Panel >
4672 </ Accordion . Item >
4773 ) ) }
0 commit comments