Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Disable pro provider configuration for pro providers that support the new flow #1465

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
72 changes: 58 additions & 14 deletions desktop/src/lib/modals/useLoginProModal.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BottomActionBar, BottomActionBarError, Form, useStreamingTerminal } from "@/components"
import { useProInstanceManager, useProInstances, useProviders } from "@/contexts"
import { useProInstanceManager, useProInstances, useProvider, useProviders } from "@/contexts"
import { canHealthCheck, exists, useFormErrors } from "@/lib"
import { Routes } from "@/routes"
import {
Expand All @@ -23,14 +23,17 @@ import {
ModalHeader,
ModalOverlay,
Tooltip,
VStack,
useDisclosure,
VStack,
} from "@chakra-ui/react"
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
import { SubmitHandler, useForm } from "react-hook-form"
import { useNavigate } from "react-router"
import { ConfigureProviderOptionsForm, useSetupProvider } from "@/views/Providers"
import { To } from "react-router-dom"
import { useQueryClient } from "@tanstack/react-query"
import { client } from "@/client"
import { QueryKeys } from "@/queryKeys"

type TFormValues = {
[FieldName.PRO_HOST]: string
Expand Down Expand Up @@ -98,17 +101,6 @@ export function useLoginProModal() {

const { proURLError } = useFormErrors(Object.values(FieldName), formState)

useEffect(() => {
if (login.status === "success") {
const providerID = login.provider?.config?.name

if (!exists(providerID)) {
return
}
completeSetupProvider({ providerID, suggestedOptions })
}
}, [completeSetupProvider, login.provider, login.status, suggestedOptions])

const resetModal = useCallback(
(checkDanglingProInstance: boolean = false) => {
reset()
Expand Down Expand Up @@ -167,6 +159,58 @@ export function useLoginProModal() {
}, 0)
}, [completeConfigureProvider, navigate, providers, proInstances, resetModal, state.providerID])

const [provider] = useProvider(state.providerID)

const supportsProFlow = useMemo(() => {
return canHealthCheck(provider?.config)
}, [provider])

const queryClient = useQueryClient()

const saveAndSkipForm = useCallback(async () => {
if (!state.providerID) {
return
}

;(
await client.providers.configure(state.providerID, {
useAsDefaultProvider: true,
reuseMachine: false,
options: {},
})
).unwrap()

await queryClient.invalidateQueries(QueryKeys.PROVIDERS)

completeFlow()
}, [queryClient, state.providerID, completeFlow])

const skippedConfigurationRef = useRef<boolean>(false)

useEffect(() => {
if (login.status === "success" && !skippedConfigurationRef.current) {
const providerID = login.provider?.config?.name

if (!exists(providerID)) {
return
}

completeSetupProvider({ providerID, suggestedOptions })

if (supportsProFlow) {
skippedConfigurationRef.current = true
saveAndSkipForm()
}
}
}, [
completeSetupProvider,
supportsProFlow,
saveAndSkipForm,
login.provider,
login.status,
suggestedOptions,
])

const modal = useMemo(() => {
return (
<Modal
Expand Down Expand Up @@ -255,7 +299,7 @@ export function useLoginProModal() {
</BottomActionBar>
)}
</Form>
{state.currentStep === "configure-provider" && (
{!supportsProFlow && state.currentStep === "configure-provider" && (
<>
<Divider />
<Heading size="md" as="h2">
Expand Down
Loading