From 5c9acb1cb3bfe341378b91bbed344dd7202a00d7 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Sun, 14 Apr 2024 01:39:30 +0300 Subject: fix(web): Fix some JS console errors in the preview page --- apps/web/components/ui/action-button.tsx | 57 +++++++++++++++++--------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'apps/web/components/ui/action-button.tsx') diff --git a/apps/web/components/ui/action-button.tsx b/apps/web/components/ui/action-button.tsx index 5b862e07..e9cdc3c9 100644 --- a/apps/web/components/ui/action-button.tsx +++ b/apps/web/components/ui/action-button.tsx @@ -1,33 +1,38 @@ +import React from "react"; import { useClientConfig } from "@/lib/clientConfig"; import type { ButtonProps } from "./button"; import { Button } from "./button"; import LoadingSpinner from "./spinner"; -export function ActionButton({ - children, - loading, - spinner, - disabled, - ignoreDemoMode = false, - ...props -}: ButtonProps & { - loading: boolean; - spinner?: React.ReactNode; - ignoreDemoMode?: boolean; -}) { - const clientConfig = useClientConfig(); - spinner ||= ; - if (!ignoreDemoMode && clientConfig.demoMode) { - disabled = true; - } else if (disabled !== undefined) { - disabled ||= loading; - } else if (loading) { - disabled = true; +const ActionButton = React.forwardRef< + HTMLButtonElement, + ButtonProps & { + loading: boolean; + spinner?: React.ReactNode; + ignoreDemoMode?: boolean; } - return ( - - ); -} +>( + ( + { children, loading, spinner, disabled, ignoreDemoMode = false, ...props }, + ref, + ) => { + const clientConfig = useClientConfig(); + spinner ||= ; + if (!ignoreDemoMode && clientConfig.demoMode) { + disabled = true; + } else if (disabled !== undefined) { + disabled ||= loading; + } else if (loading) { + disabled = true; + } + return ( + + ); + }, +); +ActionButton.displayName = "ActionButton"; + +export { ActionButton }; -- cgit v1.2.3-70-g09d2