Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
"use client";
import { mutationOptions } from "@next-safe-action/adapter-tanstack-query";
import { Button } from "@rallly/ui/button";
import {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
useDialog,
} from "@rallly/ui/dialog";
import { Tooltip, TooltipContent, TooltipTrigger } from "@rallly/ui/tooltip";
import { useMutation } from "@tanstack/react-query";
import { XIcon } from "lucide-react";
import { useTransition } from "react";
import { Trans } from "@/i18n/client";
import { removeInstanceLicenseAction } from "../actions";
export function RemoveLicenseButton() {
const [isPending, startTransition] = useTransition();
const dialog = useDialog();
const removeInstanceLicense = useMutation(
mutationOptions(removeInstanceLicenseAction),
);
return (
<Dialog {...dialog.dialogProps}>
<Tooltip>
<TooltipTrigger
render={
<DialogTrigger
render={
<Button variant="ghost" onClick={() => dialog.trigger()} />
}
>
<XIcon data-icon="inline-start" />
<span className="sr-only">
<Trans i18nKey="removeLicense" defaults="Remove license" />
</span>
</DialogTrigger>
}
/>
<TooltipContent>
<Trans i18nKey="removeLicense" defaults="Remove license" />
</TooltipContent>
</Tooltip>
<DialogContent size="sm">
<DialogHeader>
<DialogTitle>
<Trans i18nKey="removeLicense" defaults="Remove license" />
</DialogTitle>
<DialogDescription>
<Trans
i18nKey="removeLicenseDescription"
defaults="Are you sure you want to remove this license?"
/>
</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose render={<Button />}>
<Trans i18nKey="cancel" defaults="Cancel" />
</DialogClose>
<Button
loading={isPending}
variant="destructive"
onClick={() =>
startTransition(async () => {
try {
await removeInstanceLicense.mutateAsync();
} catch {
// The mutation cache toasts the error; keep the dialog open to retry
return;
}
dialog.dismiss();
})
}
>
<Trans i18nKey="removeLicense" defaults="Remove license" />
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}