Преглед на файлове

auto sort to latest on selected product

master
azri преди 1 седмица
родител
ревизия
ef1dc073e7
променени са 1 файла, в които са добавени 9 реда и са изтрити 3 реда
  1. 9
    3
      src/components/ProductSelected/ProductSelected.jsx

+ 9
- 3
src/components/ProductSelected/ProductSelected.jsx Целия файл

@@ -20,7 +20,13 @@ const ProductSelected = () => {
20 20
   useEffect(() => {
21 21
 
22 22
     if (products.length > 0) {
23
-      setFilterProducts(products.filter(({ selected }) => selected))
23
+
24
+      let selectedProducts = products.filter(({ selected }) => selected) || []
25
+      
26
+      //sort
27
+      selectedProducts = selectedProducts.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
28
+      setFilterProducts(selectedProducts)
29
+      
24 30
     }
25 31
 
26 32
   }, [products])
@@ -68,8 +74,8 @@ const ProductSelected = () => {
68 74
             />
69 75
 
70 76
             <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
71
-            NEW
72
-          </Button>
77
+              NEW
78
+            </Button>
73 79
 
74 80
             <Box sx={{ pb: 5, pt: 3 }}>
75 81
               <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>

Loading…
Отказ
Запис