Bulk update category order and improve number formatting

Category order is now updated via a bulk API endpoint instead of individual requests, improving efficiency. Number formatting in pricing tiers form now avoids cursor jumping by only formatting decimals when necessary.
This commit is contained in:
NotII
2025-10-02 04:17:27 +01:00
parent be952509a1
commit d1f3e6b214
2 changed files with 11 additions and 4 deletions

View File

@@ -180,10 +180,15 @@ export default function CategoriesPage() {
return updatedCat || cat;
}));
// Save the new order to the server
// Save the new order to the server using bulk update
try {
await apiRequest(`/categories/${dragId}`, "PUT", {
order: filteredSiblings.find(cat => cat._id === dragId)?.order,
const categoriesToUpdate = filteredSiblings.map(cat => ({
_id: cat._id,
order: cat.order
}));
await apiRequest("/categories/bulk-order", "PUT", {
categories: categoriesToUpdate
});
} catch (error) {
toast.error("Failed to update category order");

View File

@@ -21,7 +21,9 @@ export const PricingTiers = ({
handleAddTier,
}: PricingTiersProps) => {
const formatNumber = (num: number) => {
return Number(num.toFixed(2)).toString();
// Only format to 2 decimal places if the number has decimal places
// This prevents cursor jumping when user types whole numbers
return num % 1 === 0 ? num.toString() : num.toFixed(2);
};
const formatTotal = (num: number) => {