2019-06-19 14:40:52 +00:00
|
|
|
import {
|
|
|
|
collectionDetailsFragment,
|
|
|
|
collectionProductFragment
|
2020-07-07 10:14:12 +00:00
|
|
|
} from "@saleor/fragments/collections";
|
|
|
|
import {
|
|
|
|
productErrorFragment,
|
|
|
|
shopErrorFragment
|
|
|
|
} from "@saleor/fragments/errors";
|
2020-08-28 12:45:11 +00:00
|
|
|
import makeMutation from "@saleor/hooks/makeMutation";
|
2020-07-07 10:14:12 +00:00
|
|
|
import gql from "graphql-tag";
|
|
|
|
|
2019-06-19 14:40:52 +00:00
|
|
|
import {
|
|
|
|
CollectionAssignProduct,
|
|
|
|
CollectionAssignProductVariables
|
|
|
|
} from "./types/CollectionAssignProduct";
|
|
|
|
import {
|
|
|
|
CollectionBulkDelete,
|
|
|
|
CollectionBulkDeleteVariables
|
|
|
|
} from "./types/CollectionBulkDelete";
|
|
|
|
import {
|
|
|
|
CollectionBulkPublish,
|
|
|
|
CollectionBulkPublishVariables
|
|
|
|
} from "./types/CollectionBulkPublish";
|
|
|
|
import {
|
|
|
|
CollectionUpdate,
|
|
|
|
CollectionUpdateVariables
|
|
|
|
} from "./types/CollectionUpdate";
|
|
|
|
import {
|
|
|
|
CollectionUpdateWithHomepage,
|
|
|
|
CollectionUpdateWithHomepageVariables
|
|
|
|
} from "./types/CollectionUpdateWithHomepage";
|
|
|
|
import {
|
|
|
|
CreateCollection,
|
|
|
|
CreateCollectionVariables
|
|
|
|
} from "./types/CreateCollection";
|
|
|
|
import {
|
|
|
|
RemoveCollection,
|
|
|
|
RemoveCollectionVariables
|
|
|
|
} from "./types/RemoveCollection";
|
|
|
|
import {
|
|
|
|
UnassignCollectionProduct,
|
|
|
|
UnassignCollectionProductVariables
|
|
|
|
} from "./types/UnassignCollectionProduct";
|
|
|
|
|
|
|
|
const collectionUpdate = gql`
|
|
|
|
${collectionDetailsFragment}
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CollectionUpdate($id: ID!, $input: CollectionInput!) {
|
|
|
|
collectionUpdate(id: $id, input: $input) {
|
|
|
|
collection {
|
|
|
|
...CollectionDetailsFragment
|
|
|
|
}
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionUpdateMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionUpdate,
|
|
|
|
CollectionUpdateVariables
|
|
|
|
>(collectionUpdate);
|
|
|
|
|
|
|
|
const collectionUpdateWithHomepage = gql`
|
|
|
|
${collectionDetailsFragment}
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2020-07-07 10:14:12 +00:00
|
|
|
${shopErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CollectionUpdateWithHomepage(
|
|
|
|
$id: ID!
|
|
|
|
$input: CollectionInput!
|
|
|
|
$homepageId: ID
|
|
|
|
) {
|
|
|
|
homepageCollectionUpdate(collection: $homepageId) {
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: shopErrors {
|
|
|
|
...ShopErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
shop {
|
|
|
|
homepageCollection {
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
collectionUpdate(id: $id, input: $input) {
|
|
|
|
collection {
|
|
|
|
...CollectionDetailsFragment
|
|
|
|
}
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionUpdateWithHomepageMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionUpdateWithHomepage,
|
|
|
|
CollectionUpdateWithHomepageVariables
|
|
|
|
>(collectionUpdateWithHomepage);
|
|
|
|
|
|
|
|
const assignCollectionProduct = gql`
|
|
|
|
${collectionProductFragment}
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CollectionAssignProduct(
|
|
|
|
$collectionId: ID!
|
|
|
|
$productIds: [ID!]!
|
|
|
|
$first: Int
|
|
|
|
$after: String
|
|
|
|
$last: Int
|
|
|
|
$before: String
|
|
|
|
) {
|
|
|
|
collectionAddProducts(collectionId: $collectionId, products: $productIds) {
|
|
|
|
collection {
|
|
|
|
id
|
|
|
|
products(first: $first, after: $after, before: $before, last: $last) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
...CollectionProductFragment
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
hasPreviousPage
|
|
|
|
startCursor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionAssignProductMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionAssignProduct,
|
|
|
|
CollectionAssignProductVariables
|
|
|
|
>(assignCollectionProduct);
|
|
|
|
|
|
|
|
const createCollection = gql`
|
|
|
|
${collectionDetailsFragment}
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CreateCollection($input: CollectionCreateInput!) {
|
|
|
|
collectionCreate(input: $input) {
|
|
|
|
collection {
|
|
|
|
...CollectionDetailsFragment
|
|
|
|
}
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionCreateMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
CreateCollection,
|
|
|
|
CreateCollectionVariables
|
|
|
|
>(createCollection);
|
|
|
|
|
|
|
|
const removeCollection = gql`
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation RemoveCollection($id: ID!) {
|
|
|
|
collectionDelete(id: $id) {
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionRemoveMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
RemoveCollection,
|
|
|
|
RemoveCollectionVariables
|
|
|
|
>(removeCollection);
|
|
|
|
|
|
|
|
const unassignCollectionProduct = gql`
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation UnassignCollectionProduct(
|
|
|
|
$collectionId: ID!
|
|
|
|
$productIds: [ID]!
|
|
|
|
$first: Int
|
|
|
|
$after: String
|
|
|
|
$last: Int
|
|
|
|
$before: String
|
|
|
|
) {
|
|
|
|
collectionRemoveProducts(
|
|
|
|
collectionId: $collectionId
|
|
|
|
products: $productIds
|
|
|
|
) {
|
|
|
|
collection {
|
|
|
|
id
|
|
|
|
products(first: $first, after: $after, before: $before, last: $last) {
|
|
|
|
edges {
|
|
|
|
node {
|
|
|
|
id
|
|
|
|
isPublished
|
|
|
|
name
|
|
|
|
productType {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
thumbnail {
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
hasPreviousPage
|
|
|
|
startCursor
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
|
|
|
}
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useUnassignCollectionProductMutation = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
UnassignCollectionProduct,
|
|
|
|
UnassignCollectionProductVariables
|
|
|
|
>(unassignCollectionProduct);
|
|
|
|
|
|
|
|
const collectionBulkDelete = gql`
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CollectionBulkDelete($ids: [ID]!) {
|
|
|
|
collectionBulkDelete(ids: $ids) {
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionBulkDelete = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionBulkDelete,
|
|
|
|
CollectionBulkDeleteVariables
|
|
|
|
>(collectionBulkDelete);
|
|
|
|
|
|
|
|
const collectionBulkPublish = gql`
|
2020-03-05 14:59:55 +00:00
|
|
|
${productErrorFragment}
|
2019-06-19 14:40:52 +00:00
|
|
|
mutation CollectionBulkPublish($ids: [ID]!, $isPublished: Boolean!) {
|
|
|
|
collectionBulkPublish(ids: $ids, isPublished: $isPublished) {
|
2020-03-05 14:59:55 +00:00
|
|
|
errors: productErrors {
|
|
|
|
...ProductErrorFragment
|
2019-06-19 14:40:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2020-08-28 12:45:11 +00:00
|
|
|
export const useCollectionBulkPublish = makeMutation<
|
2019-06-19 14:40:52 +00:00
|
|
|
CollectionBulkPublish,
|
|
|
|
CollectionBulkPublishVariables
|
|
|
|
>(collectionBulkPublish);
|