UpgradeButton
uses useState
Upgrade a package within its ranges (upgradePackage, as tcm upgrade), then show it again.
import { refresh } from "#codebase/tcmts/react"; import { toasts } from "#codebase/tcmts/share"; import { upgradePackage } from "#codebase/tcmts/studio"; import { useState } from "react"; import { Button } from "react-aria-components"; export function UpgradeButton({ name }: { name: string }) { const [busy, setBusy] = useState(false); return ( <Button className="btn small" isPending={busy} onPress={async () => { setBusy(true); try { toasts.add({ title: await upgradePackage(name), tone: "ok" }, { timeout: 6000 }); refresh(); } catch (e) { toasts.add( { title: `Couldn't upgrade ${name}`, description: (e as Error).message, tone: "bad" }, { timeout: 12000 }, ); } setBusy(false); }} > {busy ? "Upgrading…" : "Upgrade"} </Button> ); }