777 viewsJS Amazona

hi Basir

when I click the place order button , it does create the order in backend , i get the 201 message in “Network” header tab in the inspect. but the console shows following error

“PlaceOrderScreen.js:57 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘_id’) at HTMLButtonElement.eval (PlaceOrderScreen.js:57:58)”

below is the code for place order button

const PlaceOrderScreen = {
    after_render: async () => {
        .addEventListener(‘click’, async () => {
        const order = convertCartToOrder();
        const data = await createOrder(order);

        if (data.error){
        } else {
            document.location.hash =`/order/${data.order._id}`;

I get the error at code in bold. Any suggestion how to correct it. i have seen answer to similar question but could not get rid of this issue.
Thanks in advance.

Bassir Answered question March 10, 2023