Browse Source

auto sort to latest on selected product

master
azri 1 week ago
parent
commit
ef1dc073e7
1 changed files with 9 additions and 3 deletions
  1. 9
    3
      src/components/ProductSelected/ProductSelected.jsx

+ 9
- 3
src/components/ProductSelected/ProductSelected.jsx View File

20
   useEffect(() => {
20
   useEffect(() => {
21
 
21
 
22
     if (products.length > 0) {
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
   }, [products])
32
   }, [products])
68
             />
74
             />
69
 
75
 
70
             <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
76
             <Button sx={{ position: "absolute", top: 20, left: 20, boxShadow: 0 }} variant="contained">
71
-            NEW
72
-          </Button>
77
+              NEW
78
+            </Button>
73
 
79
 
74
             <Box sx={{ pb: 5, pt: 3 }}>
80
             <Box sx={{ pb: 5, pt: 3 }}>
75
               <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>
81
               <Typography variant="body1" sx={{ fontWeight: "400", mb: 1 }}>

Loading…
Cancel
Save