I'm using a server action to delete a product that is displayed in a table, but it doesn't update the data when I use the server action, what am I doing wrong? I saw in the documentation that it is simply calling revalidatePath
Server Action:
`export async function deleteProduct(id) {
const session = await auth()
if (!session) return { error: 'Não autenticado' }const headerList = headers();
const forwardedHost = headerList.get("x-forwarded-host");
const forwardedProto = headerList.get("x-forwarded-proto") || 'http';
const hostname = new URL(${forwardedProto}://${forwardedHost}).hostname;const user = await prisma.user.findUnique({
where: { domain: hostname, id: session.user.id }
});if (!user) {
return { error: 'Usuário não encontrado.' }
}const product = await prisma.product.findFirst({
where: {
id: id,
userId: user.role == "ADMIN" ? undefined : user.id,
}
});if (!product) {
return { error: 'Produto não encontrado ou não autorizado a deletar.' };
}await prisma.product.delete({
where: {
id: product.id,
}
});revalidatePath('/p')
return 'Deletado com sucesso ' + product.title
}`
Page.jsx:
`export default async function Products() {
const data = await findProducts(1);return (
<div>
<h1 className="text-xl font-medium mb-4 text-white">Produtos</h1>
<ProductDataTable columns={columns} data={{ ...data, pageSize: 50 }} />;
</div>
);
}`
how do I call the action:
<AlertDialogAction onClick={async () => { await deleteProduct(row.original.id)}} className="bg-red-800 hover:bg-red-900 w-full text-white shadow"> Continue </AlertDialogAction>