Next.js Discord

Discord Forum

Close Dialog and Return Message from the server actions

Unanswered
Jenn posted this in #help-forum
Open in Discord
I'm using Next.js with Shadcn and Supabase. In my datatable, each row has a dropdown with actions, and clicking on an action opens a dialog to cancel an order.

What is expected to happen: Once I clicked confirm it should close the dialog and return a message that says Successfully updated it on the database.

What currently happens:
- Clicking confirm does not close the dialog.
- No return message as I am unsure of how I can implement this with the Shadcn DataTable
- The function updateOrder does function correctly and data is reflected in the database.

export const updateToCancelledOrder = async (order_id: string) => {
    const cookieStore = cookies()
    const supabase = createServerActionClient({ cookies: () => cookieStore })

    try{

        const { data, error } = await supabase
        .from('orders')
        .update({ order_status : 'Cancelled' })
        .eq('order_id', order_id)  

        return { message: 'Successfully updated it on the database' }
        revalidatePath('/')

    }catch(error){
       return { message: 'There was an error.' }
    }
}

Also in : https://stackoverflow.com/questions/77627178/how-can-i-close-the-dialog-and-then-also-return-a-message-once-it-was-succesfull

0 Replies