30 lines
789 B
TypeScript
30 lines
789 B
TypeScript
"use client"
|
|
|
|
import { useTransition } from "react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Spinner } from "@/components/ui/spinner";
|
|
import { toast } from "sonner";
|
|
import { updateUserAction } from "@/lib/user/actions";
|
|
|
|
export function UpdateButton() {
|
|
const [isPending, startTransition] = useTransition();
|
|
|
|
return (
|
|
<Button
|
|
variant="secondary"
|
|
disabled={isPending}
|
|
onClick={() =>
|
|
startTransition(async () => {
|
|
try {
|
|
await updateUserAction();
|
|
toast.success("Profile updated");
|
|
} catch {
|
|
toast.error("Failed to update profile. Your session may have expired. Try signing in again.");
|
|
}
|
|
})
|
|
}
|
|
>
|
|
{isPending && <Spinner />}Update
|
|
</Button>
|
|
);
|
|
} |