Skip to content

Commit

Permalink
Collection shows channels after creation (#5376)
Browse files Browse the repository at this point in the history
* Wait for channels update before navigate

* Add changeset
  • Loading branch information
poulch authored Jan 29, 2025
1 parent b1af6f2 commit 6e46436
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-swans-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

After creating a new collection, you should see a list of assigned channels
44 changes: 21 additions & 23 deletions src/collections/views/CollectionCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,7 @@ export const CollectionCreate: React.FC<CollectionCreateProps> = ({ params }) =>
{ closeModal, openModal },
{ formId: COLLECTION_CREATE_FORM_ID },
);
const [createCollection, createCollectionOpts] = useCreateCollectionMutation({
onCompleted: data => {
if (data.collectionCreate.errors.length === 0) {
notify({
status: "success",
text: intl.formatMessage(commonMessages.savedChanges),
});
navigate(collectionUrl(data.collectionCreate.collection.id));
} else {
const backgroundImageError = data.collectionCreate.errors.find(
error => error.field === ("backgroundImage" as keyof CollectionCreateInput),
);

if (backgroundImageError) {
notify({
status: "error",
text: intl.formatMessage(commonMessages.somethingWentWrong),
});
}
}
},
});
const [createCollection, createCollectionOpts] = useCreateCollectionMutation({});
const handleCreate = async (formData: CollectionCreateData) => {
const result = await createCollection({
variables: {
Expand All @@ -103,7 +82,7 @@ export const CollectionCreate: React.FC<CollectionCreateProps> = ({ params }) =>
const id = result.data?.collectionCreate.collection?.id || null;

if (id) {
updateChannels({
await updateChannels({
variables: {
id,
input: {
Expand All @@ -118,6 +97,25 @@ export const CollectionCreate: React.FC<CollectionCreateProps> = ({ params }) =>
});
}

if (result.data.collectionCreate.errors.length === 0) {
notify({
status: "success",
text: intl.formatMessage(commonMessages.savedChanges),
});
navigate(collectionUrl(id));
} else {
const backgroundImageError = result.data.collectionCreate.errors.find(
error => error.field === ("backgroundImage" as keyof CollectionCreateInput),
);

if (backgroundImageError) {
notify({
status: "error",
text: intl.formatMessage(commonMessages.somethingWentWrong),
});
}
}

return { id, errors: getMutationErrors(result) };
};
const handleSubmit = createMetadataCreateHandler(
Expand Down

0 comments on commit 6e46436

Please sign in to comment.