feat: hide the deploy button when the Dokku server is not connected
This commit is contained in:
@ -21,12 +21,14 @@ export default function DeployButtonModal({
|
||||
const { deploy, getAppExists } = useTerminal()
|
||||
const [isDeploying, setIsDeploying] = useState(false)
|
||||
const [isDeployed, setIsDeployed] = useState(false)
|
||||
const [deployButtonVisible, setDeployButtonEnabled] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
const checkDeployment = async () => {
|
||||
if (getAppExists) {
|
||||
const exists = await getAppExists(data.id)
|
||||
setIsDeployed(exists)
|
||||
setDeployButtonEnabled(exists.success)
|
||||
setIsDeployed((exists.success && exists.exists) ?? false)
|
||||
}
|
||||
}
|
||||
checkDeployment()
|
||||
@ -50,10 +52,12 @@ export default function DeployButtonModal({
|
||||
<>
|
||||
<Popover>
|
||||
<PopoverTrigger asChild>
|
||||
<Button variant="outline">
|
||||
<Globe className="w-4 h-4 mr-2" />
|
||||
Deploy
|
||||
</Button>
|
||||
{deployButtonVisible && (
|
||||
<Button variant="outline">
|
||||
<Globe className="w-4 h-4 mr-2" />
|
||||
Deploy
|
||||
</Button>
|
||||
)}
|
||||
</PopoverTrigger>
|
||||
<PopoverContent
|
||||
className="p-4 w-full max-w-xs sm:max-w-sm md:max-w-md lg:max-w-lg xl:max-w-xl rounded-lg shadow-lg"
|
||||
|
@ -20,7 +20,9 @@ interface TerminalContextType {
|
||||
createNewTerminal: (command?: string) => Promise<void>
|
||||
closeTerminal: (id: string) => void
|
||||
deploy: (callback: () => void) => void
|
||||
getAppExists: ((appName: string) => Promise<boolean>) | null
|
||||
getAppExists:
|
||||
| ((appName: string) => Promise<{ success: boolean; exists?: boolean }>)
|
||||
| null
|
||||
}
|
||||
|
||||
const TerminalContext = createContext<TerminalContextType | undefined>(
|
||||
@ -92,16 +94,18 @@ export const TerminalProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
})
|
||||
}
|
||||
|
||||
const getAppExists = async (appName: string): Promise<boolean> => {
|
||||
const getAppExists = async (
|
||||
appName: string
|
||||
): Promise<{ success: boolean; exists?: boolean }> => {
|
||||
console.log("Is there a socket: " + !!socket)
|
||||
if (!socket) {
|
||||
console.error("Couldn't check if app exists: No socket")
|
||||
return false
|
||||
return { success: false }
|
||||
}
|
||||
const response: { exists: boolean } = await new Promise((resolve) =>
|
||||
socket.emit("getAppExists", { appName }, resolve)
|
||||
const response: { success: boolean; exists?: boolean } = await new Promise(
|
||||
(resolve) => socket.emit("getAppExists", { appName }, resolve)
|
||||
)
|
||||
return response.exists
|
||||
return response
|
||||
}
|
||||
|
||||
const value = {
|
||||
|
Reference in New Issue
Block a user