diff --git a/app/controllers/api/product_categories_controller.rb b/app/controllers/api/product_categories_controller.rb index c126e9616..dc9ce614b 100644 --- a/app/controllers/api/product_categories_controller.rb +++ b/app/controllers/api/product_categories_controller.rb @@ -36,11 +36,12 @@ class API::ProductCategoriesController < API::ApiController def position authorize @product_category + render json: @product_category, status: :not_modified and return if @product_category.position == params[:position] if @product_category.insert_at(params[:position]) render :show else - render json: @product_category.errors, status: :unprocessable_entity + render json: @product_category.errors.full_messages, status: :unprocessable_entity end end diff --git a/app/frontend/src/javascript/components/store/categories/product-categories-tree.tsx b/app/frontend/src/javascript/components/store/categories/product-categories-tree.tsx index ba503d5dd..8b7e6b10a 100644 --- a/app/frontend/src/javascript/components/store/categories/product-categories-tree.tsx +++ b/app/frontend/src/javascript/components/store/categories/product-categories-tree.tsx @@ -113,9 +113,13 @@ export const ProductCategoriesTree: React.FC = ({ pr if (activeData.offset === 'down' && sortedId === active.id && activeData.index < newIndex && active.id !== over.id) { category = { ...category, parent_id: Number(over.id) }; droppedItem = category; + newPosition = 1; } else if (activeData.offset === 'down' && sortedId === active.id && (activeData.index > newIndex || active.id === over.id)) { - category = { ...category, parent_id: getPreviousAdopter(over.id) }; + const adopter = getPreviousAdopter(over.id); + const siblingsLength = getChildren(adopter)?.length | 0; + category = { ...category, parent_id: adopter }; droppedItem = category; + newPosition = siblingsLength + 1; } return category; }); @@ -129,14 +133,15 @@ export const ProductCategoriesTree: React.FC = ({ pr if (activeData.offset === 'down' && sortedId === active.id && activeData.index < newIndex) { category = { ...category, parent_id: Number(over.id) }; droppedItem = category; - newPosition = 0; + newPosition = 1; } else if (activeData.offset === 'down' && sortedId === active.id && activeData.index > newIndex) { category = { ...category, parent_id: getPreviousAdopter(over.id) }; droppedItem = category; - newPosition = getChildren(getPreviousAdopter(over.id))?.length || 0; + newPosition = getChildren(getPreviousAdopter(over.id))?.length || 1; } else if (sortedId === active.id) { category = { ...category, parent_id: null }; droppedItem = category; + newPosition = getCategory(over.id).position + 1; } return category; }); @@ -153,7 +158,7 @@ export const ProductCategoriesTree: React.FC = ({ pr if (sortedId === active.id) { category = { ...category, parent_id: Number(over.id) }; droppedItem = category; - newPosition = 0; + newPosition = 1; } return category; }); @@ -166,7 +171,7 @@ export const ProductCategoriesTree: React.FC = ({ pr } else if (sortedId === active.id && activeData.offset === 'down') { category = { ...category, parent_id: getPreviousAdopter(over.id) }; droppedItem = category; - newPosition = getChildren(getPreviousAdopter(over.id))?.length || 0; + newPosition = getChildren(getPreviousAdopter(over.id))?.length || 1; } return category; }); @@ -182,6 +187,7 @@ export const ProductCategoriesTree: React.FC = ({ pr if (sortedId === active.id) { category = { ...category, parent_id: null }; droppedItem = category; + newPosition = getCategory(getCategory(over.id).parent_id).position + 1; } return category; }); @@ -219,15 +225,17 @@ export const ProductCategoriesTree: React.FC = ({ pr } // [B]:Child if (overStatus === 'child') { + const parent = newOrder.find(c => c.id === getCategory(over.id).parent_id); if (activeData.index < newIndex) { - const parent = newOrder.find(c => c.id === getCategory(over.id).parent_id); newIndex = newOrder.findIndex(c => c.id === getChildren(parent.id).pop().id); const newIdsOrder = arrayMove(currentIdsOrder, activeData.index, newIndex); newOrder = newIdsOrder.map(sortedId => getCategory(sortedId)); + newPosition = parent.position; } else { newIndex = currentIdsOrder.indexOf(getCategory(over.id).parent_id); const newIdsOrder = arrayMove(currentIdsOrder, activeData.index, newIndex); newOrder = newIdsOrder.map(sortedId => getCategory(sortedId)); + newPosition = parent.position; } } // insert children back diff --git a/app/frontend/src/javascript/components/store/categories/product-categories.tsx b/app/frontend/src/javascript/components/store/categories/product-categories.tsx index 43637532d..4cb5590d5 100644 --- a/app/frontend/src/javascript/components/store/categories/product-categories.tsx +++ b/app/frontend/src/javascript/components/store/categories/product-categories.tsx @@ -52,6 +52,7 @@ const ProductCategories: React.FC = ({ onSuccess, onErro .then(c => { ProductCategoryAPI .updatePosition(c, position) + .then(refreshCategories) .catch(error => onError(error)); }) .catch(error => onError(error)); diff --git a/app/frontend/src/javascript/components/store/show-order.tsx b/app/frontend/src/javascript/components/store/show-order.tsx index 32fd6ece0..54b89a359 100644 --- a/app/frontend/src/javascript/components/store/show-order.tsx +++ b/app/frontend/src/javascript/components/store/show-order.tsx @@ -156,7 +156,7 @@ export const ShowOrder: React.FC = ({ orderId, currentUser, onSu
-
+
{order.order_items_attributes.map(item => (
diff --git a/app/frontend/src/stylesheets/modules/store/orders.scss b/app/frontend/src/stylesheets/modules/store/orders.scss index 24eba0de8..37d9de724 100644 --- a/app/frontend/src/stylesheets/modules/store/orders.scss +++ b/app/frontend/src/stylesheets/modules/store/orders.scss @@ -91,6 +91,10 @@ color: var(--gray-hard-light); } } + .actions { + grid-template-columns: auto; + grid-auto-flow: column; + } } .subgrid { diff --git a/app/frontend/src/stylesheets/modules/store/store.scss b/app/frontend/src/stylesheets/modules/store/store.scss index da8ec70ef..a2d60e9d9 100644 --- a/app/frontend/src/stylesheets/modules/store/store.scss +++ b/app/frontend/src/stylesheets/modules/store/store.scss @@ -164,6 +164,7 @@ } } aside { + justify-self: stretch; margin: 2.4rem 0; grid-row: 4 / 5; top: 4rem; @@ -198,7 +199,7 @@ grid-template-areas: "min min min" "minus input plus" "btn btn btn"; - grid-template-columns: repeat(4, minmax(0, min-content)); + grid-template-columns: min-content 1fr min-content; justify-content: center; gap: 1.6rem; border-top: 1px solid var(--gray-soft-dark); diff --git a/app/models/product_category.rb b/app/models/product_category.rb index e98f4245b..57474e5ed 100644 --- a/app/models/product_category.rb +++ b/app/models/product_category.rb @@ -14,5 +14,5 @@ class ProductCategory < ApplicationRecord has_many :products, dependent: :nullify - acts_as_list scope: :parent, top_of_list: 0 + acts_as_list scope: :parent, top_of_list: 1 end