Skip to content

Commit

Permalink
Fix assigning products to collection (#4329)
Browse files Browse the repository at this point in the history
* Fix assigning products to collection

* Add changeset
  • Loading branch information
Droniu authored Oct 18, 2023
1 parent b792f98 commit 226b603
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/spotty-files-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix assigning products to collection
11 changes: 7 additions & 4 deletions src/collections/views/CollectionDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from "@dashboard/channels/utils";
import ActionDialog from "@dashboard/components/ActionDialog";
import useAppChannel from "@dashboard/components/AppLayout/AppChannelContext";
import { Container } from "@dashboard/components/AssignContainerDialog";
import AssignProductDialog from "@dashboard/components/AssignProductDialog";
import { Button } from "@dashboard/components/Button";
import ChannelsAvailabilityDialog from "@dashboard/components/ChannelsAvailabilityDialog";
Expand Down Expand Up @@ -242,16 +243,18 @@ export const CollectionDetails: React.FC<CollectionDetailsProps> = ({
variables => updatePrivateMetadata({ variables }),
);

const handleAssignationChange = async products => {
const handleAssignationChange = async (products: Container[]) => {
const productIds = products.map(product => product.id);

const toUnassignIds = Object.keys(assignedProductDict).filter(
s => assignedProductDict[s] && !products.includes(s),
s => assignedProductDict[s] && !productIds.includes(s),
);

const baseVariables = { ...paginationState, collectionId: id };

if (products.length > 0) {
if (productIds.length > 0) {
await assignProduct({
variables: { ...baseVariables, productIds: products },
variables: { ...baseVariables, productIds },
});
}

Expand Down

0 comments on commit 226b603

Please sign in to comment.