feat: add activate warranty to order details page

Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
Chloe
2024-06-26 16:35:18 +07:00
parent d801de0cf1
commit 7f4fa09027
11 changed files with 71 additions and 27 deletions

View File

@@ -1,5 +1,5 @@
import customerAddress from './customer-address';
import orderCard from './order-card';
import orderCard from './order';
const customerDetailsFragment = /* GraphQL */ `
${customerAddress}

View File

@@ -28,4 +28,19 @@ const orderCard = /* GraphQL */ `
${lineItemFragment}
`;
export const orderMetafields = /* GraphQL */ `
fragment OrderMetafield on Order {
id
warrantyStatus: metafield(namespace: "custom", key: "warranty_status") {
value
}
warrantyActivationDeadline: metafield(
namespace: "custom"
key: "warranty_activation_deadline"
) {
value
}
}
`;
export default orderCard;

View File

@@ -38,7 +38,7 @@ import { getCustomerQuery } from './queries/customer';
import { getMenuQuery } from './queries/menu';
import { getMetaobjectQuery, getMetaobjectsQuery } from './queries/metaobject';
import { getImageQuery, getMetaobjectsByIdsQuery } from './queries/node';
import { getCustomerOrderQuery } from './queries/order';
import { getCustomerOrderQuery, getOrderMetafieldsQuery } from './queries/order';
import { getCustomerOrderMetafieldsQuery, getCustomerOrdersQuery } from './queries/orders';
import { getPageQuery, getPagesQuery } from './queries/page';
import {
@@ -1161,3 +1161,27 @@ export const getOrdersMetafields = async (): Promise<{ [key: string]: OrderMetaf
{} as { [key: string]: OrderMetafield }
);
};
export const getOrderMetafields = async (orderId: string): Promise<OrderMetafield> => {
const res = await adminFetch<{
data: {
order: {
id: string;
} & ShopifyOrderMetafield;
};
variables: {
id: string;
};
}>({
query: getOrderMetafieldsQuery,
variables: { id: `gid://shopify/Order/${orderId}` },
tags: [`${TAGS.orderMetafields}/${orderId}`]
});
const order = res.body.data.order;
return {
warrantyStatus: order.warrantyStatus?.value ?? null,
warrantyActivationDeadline: order.warrantyActivationDeadline?.value ?? null
};
};

View File

@@ -1,4 +1,5 @@
import lineItemFragment from '../fragments/line-item';
import { orderMetafields } from '../fragments/order';
// NOTE: https://shopify.dev/docs/api/customer/latest/queries/customer
export const getCustomerOrderQuery = /* GraphQL */ `
@@ -220,3 +221,12 @@ export const getCustomerOrderQuery = /* GraphQL */ `
}
${lineItemFragment}
`;
export const getOrderMetafieldsQuery = /* GraphQL */ `
query getOrderMetafields($id: ID!) {
order(id: $id) {
...OrderMetafield
}
}
${orderMetafields}
`;

View File

@@ -1,4 +1,5 @@
import customerDetailsFragment from '../fragments/customer-details';
import { orderMetafields } from '../fragments/order';
const customerFragment = `#graphql
`;
@@ -19,18 +20,10 @@ export const getCustomerOrderMetafieldsQuery = /* GraphQL */ `
customer(id: $id) {
orders(first: 20, sortKey: PROCESSED_AT, reverse: true) {
nodes {
id
warrantyStatus: metafield(namespace: "custom", key: "warranty_status") {
value
}
warrantyActivationDeadline: metafield(
namespace: "custom"
key: "warranty_activation_deadline"
) {
value
}
...OrderMetafield
}
}
}
}
${orderMetafields}
`;