Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: flickering in the token modal while creating access token #479

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ const CreateAccessToken = () => {
const createMutation = api.accessToken.create.useMutation({
onSuccess: ({ token }) => {
setAccessToken(token);
copy(token);
toast.success("Access token copied to clipboard.");

toast.promise(copy(token), {
loading: "Copying token...",
success: "Access token copied to clipboard.",
error: "Error copying token",
});
setOpen(true);
setLoading(false);
},

onError: (error) => {
Expand All @@ -33,17 +38,15 @@ const CreateAccessToken = () => {

onSettled: () => {
setLoading(false);
router.refresh();
},
});

return (
<Fragment>
<Button
onClick={(e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
onClick={async () => {
setLoading(true);
createMutation.mutate({
await createMutation.mutateAsync({
typeEnum: "api",
});
}}
Expand All @@ -67,6 +70,9 @@ const CreateAccessToken = () => {
open,
onOpenChange: (val) => {
setOpen(val);
if (!val) {
router.refresh();
}
},
}}
>
Expand All @@ -75,8 +81,11 @@ const CreateAccessToken = () => {
<Card
className="cursor-copy break-words p-3 mt-2"
onClick={() => {
copy(accessToken as string);
toast.success("Access token copied to clipboard.");
toast.promise(copy(accessToken), {
loading: "Copying token...",
success: "Access token copied to clipboard.",
error: "Error copying token",
});
}}
>
<code className="text-sm font-mono text-rose-600">
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default async function RootLayout({
<NextAuthProvider session={session}>
<TRPCReactProvider cookies={cookies().toString()}>
<main>{children}</main>
<Toaster richColors />
<Toaster closeButton richColors />
{nodeEnv === "development" && <ScreenSize />}
</TRPCReactProvider>
</NextAuthProvider>
Expand Down