i want to use two models on order index page using customer account ui menuActionExtension. is it possible?
my code:
import { useEffect, useState } from “react”;
import { Button, reactExtension, useApi } from “@shopify/ui-extensions-react/customer-account”;
// Main entry point for the extension
export default reactExtension(
“customer-account.order.action.menu-item.render”,
() =>
);
function MenuActionExtension() {
const api = useApi(“customer-account.order.action.menu-item.render”);
const { orderId } = api;
console.log(orderId); // Verify that orderId is available
const [isFulfilled, setIsFulfilled] = useState(false);
const [loading, setLoading] = useState(true);
useEffect(() => {
const fetchOrderFulfillment = async () => {
let latestShipmentStatus = null;
try {
const orderQuery = {
query: query { order(id: "${orderId}") { fulfillments(first: 10) { nodes { id, latestShipmentStatus } } } },
};
const result = await fetch(
“shopify://customer-account/api/unstable/graphql.json”,
{
method: “POST”,
headers: {
“Content-Type”: “application/json”,
},
body: JSON.stringify(orderQuery),
}
);
const { data } = await result.json();
console.log(data);
if (!data?.order) {
// Handle case when order is null or doesn’t exist
console.log(“Order data is null or invalid.”);
setIsFulfilled(false);
} else if (data.order.fulfillments.nodes.length === 0) {
// No fulfillments found
setIsFulfilled(false);
} else {
// Check fulfillment status
latestShipmentStatus = data.order.fulfillments.nodes[0].latestShipmentStatus;
setIsFulfilled(latestShipmentStatus === ‘fulfilled’);
}
} catch (error) {
console.log(“Error fetching order data:”, error);
setIsFulfilled(null); // Error state
} finally {
setLoading(false); // Stop loading regardless of success or error
}
};
fetchOrderFulfillment();
}, [orderId]);
return (
<>
{isFulfilled ? (
Contact Us
) : (
Cancel
)}
</>
);
}