diff --git a/apps/ui-library/components/command-copy-button.tsx b/apps/ui-library/components/command-copy-button.tsx index a5fff1b356d..a6c249a8c07 100644 --- a/apps/ui-library/components/command-copy-button.tsx +++ b/apps/ui-library/components/command-copy-button.tsx @@ -6,7 +6,13 @@ import { useEffect, useState } from 'react' import { useSendTelemetryEvent } from 'lib/telemetry' import { Button_Shadcn_ } from 'ui' -export function CommandCopyButton({ command }: { command: string }) { +export function CommandCopyButton({ + command, + setShowCleanBranchWarning, +}: { + command: string + setShowCleanBranchWarning: (show: boolean) => void +}) { const [copied, setCopied] = useState(false) const sendTelemetryEvent = useSendTelemetryEvent() @@ -54,7 +60,7 @@ export function CommandCopyButton({ command }: { command: string }) { // Copy command to clipboard navigator.clipboard.writeText(command) setCopied(true) - + setShowCleanBranchWarning(true) // Parse command and send telemetry event const { framework, packageManager, title } = parseCommandForTelemetry(command) diff --git a/apps/ui-library/components/command.tsx b/apps/ui-library/components/command.tsx index fe93dedb7bc..580a95c02bf 100644 --- a/apps/ui-library/components/command.tsx +++ b/apps/ui-library/components/command.tsx @@ -1,9 +1,12 @@ 'use client' +import * as React from 'react' import { motion } from 'framer-motion' import { Tabs_Shadcn_, TabsContent_Shadcn_, TabsList_Shadcn_, TabsTrigger_Shadcn_ } from 'ui' import { CommandCopyButton } from './command-copy-button' import { useLocalStorage } from './use-local-storage' +import { useState, useEffect } from 'react' +import { Check } from 'lucide-react' interface CommandCopyProps { name: string @@ -16,6 +19,18 @@ const LOCAL_STORAGE_KEY = 'package-manager-copy-command' export function Command({ name, highlight }: CommandCopyProps) { const [value, setValue] = useLocalStorage(LOCAL_STORAGE_KEY, 'npm') + const [showCleanBranchWarning, setShowCleanBranchWarning] = useState(false) + + // only show the clean branch warning for 8 seconds + useEffect(() => { + if (showCleanBranchWarning) { + const timer = setTimeout(() => { + setShowCleanBranchWarning(false) + }, 8000) + + return () => clearTimeout(timer) + } + }, [showCleanBranchWarning]) const getBaseUrl = () => { if (process.env.NEXT_PUBLIC_VERCEL_TARGET_ENV === 'production') { @@ -53,7 +68,6 @@ export function Command({ name, highlight }: CommandCopyProps) { }} /> )} -
{(Object.keys(commands) as PackageManager[]).map((manager) => ( @@ -62,20 +76,29 @@ export function Command({ name, highlight }: CommandCopyProps) { ))} - - {(Object.keys(commands) as PackageManager[]).map((manager) => ( - -
-
- $ - {commands[manager]} + {showCleanBranchWarning ? ( +
+ Make sure you run this command in a clean Git branch so you can preview the changes + +
+ ) : ( + (Object.keys(commands) as PackageManager[]).map((manager) => ( + +
+
+ $ + {commands[manager]} +
+
+ +
-
- -
-
- - ))} + + )) + )}