Open robsoncloud opened 5 months ago
Hey
You are missing a refresh()
of the current page, like so: https://github.com/WebDevSimplified/next-js-ecommerce-mvp/blob/main/src/app/admin/products/_components/ProductActions.tsx#L26
<DropdownMenuItem
disabled={isPending}
onClick={() => {
startTransition(async () => {
await toggleProductAvailability(id, !isAvailableForPurchase)
router.refresh()
})
}}
>
Hey You are missing a
refresh()
of the current page, like so: https://github.com/WebDevSimplified/next-js-ecommerce-mvp/blob/main/src/app/admin/products/_components/ProductActions.tsx#L26<DropdownMenuItem disabled={isPending} onClick={() => { startTransition(async () => { await toggleProductAvailability(id, !isAvailableForPurchase) router.refresh() }) }} >
Nice one
I've added the router.refresh() and did not make any difference:
export async function toggleProductAvailability(id: string, isAvailableForPurchase: boolean) {
const product = await prisma.product.findUnique({ where: { id: id } })
// force await to simulate a delay
await new Promise(resolver => setTimeout(resolver, 3000))
if (product == null) return notFound()
await prisma.product.update({
where: { id: id }, data: {
isAvailableForPurchase
}
})
}
export function ActiveToggleDropdownItem({ id, isAvailableForPurchase }: ActiveToggleDropdownItemProps) {
const [isPending, startTransition] = useTransition()
const router = useRouter()
return (
<DropdownMenuItem disabled={isPending} onClick={() => {
startTransition(async () => {
await toggleProductAvailability(id, !isAvailableForPurchase)
router.refresh()
})
}}>
{isAvailableForPurchase ? "Deactivate" : "Activate"}
</DropdownMenuItem>
)
}
The dropdown button remains enabled
Hello there,
Is there a reason why the Activate/Deactivate button never transition to disabled?
My package.json