Skip to content
Merged
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
97 changes: 1 addition & 96 deletions refact-agent/gui/src/components/Buttons/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { forwardRef, useCallback } from "react";
import React, { forwardRef } from "react";
import { IconButton, Button, Flex } from "@radix-ui/themes";
import {
PaperPlaneIcon,
Expand All @@ -8,9 +8,6 @@ import {
} from "@radix-ui/react-icons";
import classNames from "classnames";
import styles from "./button.module.css";
import { useOpenUrl } from "../../hooks/useOpenUrl";
import { useAppSelector } from "../../hooks";
import { selectApiKey } from "../../features/Config/configSlice";
import { PuzzleIcon } from "../../images/PuzzleIcon";

type IconButtonProps = React.ComponentProps<typeof IconButton>;
Expand Down Expand Up @@ -78,95 +75,3 @@ export const RightButtonGroup: React.FC<React.PropsWithChildren & FlexProps> = (
/>
);
};

type AgentUsageLinkButtonProps = ButtonProps & {
href?: string;
onClick?: () => void;
target?: HTMLFormElement["target"];
isPlanFree?: boolean;
children?: React.ReactNode;
disabled?: boolean;
};

const SUBSCRIPTION_URL =
// "https://refact.smallcloud.ai/refact/update-subscription";
"https://app.refact.ai/my-workspace";

// const SUBSCRIPTION_FALLBACK_URL = "https://refact.smallcloud.ai/";
const SUBSCRIPTION_FALLBACK_URL = "https://app.refact.ai/";

export const AgentUsageLinkButton: React.FC<AgentUsageLinkButtonProps> = ({
href,
isPlanFree,
children,
onClick,
disabled,
...rest
}) => {
const openUrl = useOpenUrl();
const apiKey = useAppSelector(selectApiKey);
const [isLoading, setIsLoading] = React.useState(false);
const [error, setError] = React.useState<string | null>(null);

const fetchSubscriptionUrl = useCallback(async (): Promise<string | null> => {
try {
const response = await fetch(SUBSCRIPTION_URL, {
method: "GET",
headers: {
Authorization: `Bearer ${apiKey}`,
},
});

if (!response.ok) {
openUrl(SUBSCRIPTION_FALLBACK_URL);
return null;
}

const data = (await response.json()) as { url: string };
return data.url;
} catch (e) {
openUrl(SUBSCRIPTION_FALLBACK_URL);
return null;
}
}, [apiKey, openUrl]);

const handleClick = useCallback(
async (event: React.FormEvent) => {
event.preventDefault();

if (isLoading) return;

try {
setIsLoading(true);
setError(null);

if (href && isPlanFree) {
openUrl(href);
} else if (isPlanFree !== undefined && !isPlanFree) {
const url = await fetchSubscriptionUrl();
if (url) {
openUrl(url);
}
}

onClick?.();
} catch (err) {
// eslint-disable-next-line no-console
console.error("Error in LinkButton:", err);
setError(err instanceof Error ? err.message : "An error occurred");
} finally {
setIsLoading(false);
}
},
[href, isPlanFree, onClick, openUrl, fetchSubscriptionUrl, isLoading],
);

return (
<form onSubmit={(event) => void handleClick(event)}>
<Button type="submit" disabled={disabled ?? isLoading} {...rest}>
{isLoading ? "Loading..." : children}
</Button>
{error && <div className={styles.error}>{error}</div>}
</form>
);
};
2 changes: 0 additions & 2 deletions refact-agent/gui/src/components/Buttons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ export {
BackToSideBarButton,
RightButton,
RightButtonGroup,
AgentUsageLinkButton,
AgentIntegrationsButton,
} from "./Buttons";

// export { ThinkingButton } from "./ThinkingButton";
Expand Down
3 changes: 0 additions & 3 deletions refact-agent/gui/src/components/Toolbar/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ export const Dropdown: React.FC<DropdownProps> = ({
const host = useAppSelector(selectHost);
const dispatch = useAppDispatch();
const ballance = useCoinBallance();

const coinBallance = ballance?.have_coins_exactly ?? 0;
// TODO: check how much of this is still used.
// const { maxAgentUsageAmount, currentAgentUsage } = useAgentUsage();

const isWorkspaceSelectionSkipped = useAppSelector(
selectIsSkippedWorkspaceSelection,
Expand Down