Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | 185x 185x | import { Copy } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/ahuora-design-system/ui/button";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import {
type EconomicsStudyRead,
useEconomicsStudiesDuplicateCreateMutation,
} from "@/api/apiStore.gen";
export function DuplicateEconomicsStudyButton({
study,
onDuplicated,
}: {
study: EconomicsStudyRead;
onDuplicated?: (study: EconomicsStudyRead) => void;
}) {
const [duplicateStudy, duplicateState] =
useEconomicsStudiesDuplicateCreateMutation();
const handleDuplicate = async () => {
try {
const duplicate = await duplicateStudy({
id: study.id,
duplicateStudyRequest: {},
}).unwrap();
toast.success("Economics study duplicated");
onDuplicated?.(duplicate);
} catch {
toast.error("Could not duplicate the economics study");
}
};
return (
<ToolTipCover asChild content="Duplicate study" side="bottom">
<Button
type="button"
size="xs"
variant="ghost"
className="shrink-0 text-muted-foreground"
aria-label={`Duplicate economics study ${study.name}`}
disabled={duplicateState.isLoading}
onClick={() => void handleDuplicate()}
>
<Copy className="size-4" aria-hidden="true" />
</Button>
</ToolTipCover>
);
}
|