Home > Blockchain >  How can make I make the specific button disabled after clicking?
How can make I make the specific button disabled after clicking?

Time:11-08

I created a confirm sell wherein the seller will be able to click a specific transaction, and once that transaction is complete, the status will be completed and the button should be disabled permanently.

enter image description here

In this latest transaction, I will only confirm the shoe with a status of pending

Result

This is what happened after clicking the pending button.

Confirm Button

const confirmSell = async (e) => {
    try {
        await userRequest.put(`/order/${e}`, {status: 'complete'})
        setExecuting(true)
    } catch (error) {
        console.log({error: error.message})
    }
}

Actual Button

<Button variant="contained" 
   onClick={(e) => confirmSell(recent._id)} 
   disabled={executing} 
   color="success">Confirm 
</Button>

CodePudding user response:

Perhaps, you can do something like this:

<Button id="submit" variant="contained" 
   onClick={(e) => confirmSell(recent._id)} 
   disabled={executing} 
   color="success">Confirm 
</Button>
const confirmSell = async (e) => {
    try {
        await userRequest.put(`/order/${e}`, {status: 'complete'})
        document.getElementById("submit").disabled=true;
    } catch (error) {
        console.log({error: error.message})
    }
}

OR

You can check this example: This image shows your final view

NOTE: Remember to get product id and handle confirm event once user click confirm

  • Related