fix: invert backend sorting to make new payloads appear first and fix group sorting
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 51s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 51s
This commit is contained in:
@@ -87,7 +87,7 @@ const formatRow = (row) => ({
|
|||||||
// GET data (for the frontend)
|
// GET data (for the frontend)
|
||||||
app.get('/api/data', verifyToken, async (req, res) => {
|
app.get('/api/data', verifyToken, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const result = await pool.query('SELECT * FROM orders ORDER BY id ASC');
|
const result = await pool.query('SELECT * FROM orders ORDER BY id DESC');
|
||||||
const formattedData = result.rows.map(formatRow);
|
const formattedData = result.rows.map(formatRow);
|
||||||
res.json(formattedData);
|
res.json(formattedData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { useMemo } from 'react';
|
|||||||
import { useParams, Link, useOutletContext } from 'react-router-dom';
|
import { useParams, Link, useOutletContext } from 'react-router-dom';
|
||||||
import { ArrowLeft, User, Tag, Package, DollarSign, Clock } from 'lucide-react';
|
import { ArrowLeft, User, Tag, Package, DollarSign, Clock } from 'lucide-react';
|
||||||
import type { OrderData } from '../types';
|
import type { OrderData } from '../types';
|
||||||
|
import { parseOrderDate } from '../dataService';
|
||||||
|
|
||||||
const ClientDetails = () => {
|
const ClientDetails = () => {
|
||||||
const { name } = useParams<{ name: string }>();
|
const { name } = useParams<{ name: string }>();
|
||||||
@@ -37,9 +38,7 @@ const ClientDetails = () => {
|
|||||||
|
|
||||||
// Sort grouped orders by date descending
|
// Sort grouped orders by date descending
|
||||||
const groupedOrders = Object.values(groupedOrdersMap).sort((a, b) => {
|
const groupedOrders = Object.values(groupedOrdersMap).sort((a, b) => {
|
||||||
const [dayA, monthA, yearA] = a.date.split('-').map(Number);
|
return parseOrderDate(b.date).getTime() - parseOrderDate(a.date).getTime();
|
||||||
const [dayB, monthB, yearB] = b.date.split('-').map(Number);
|
|
||||||
return new Date(yearB, monthB - 1, dayB).getTime() - new Date(yearA, monthA - 1, dayA).getTime();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { groupedOrders, totalSpent, totalItems };
|
return { groupedOrders, totalSpent, totalItems };
|
||||||
|
|||||||
Reference in New Issue
Block a user