This commit is contained in:
parent
43b4279e2d
commit
0f5d9b9b68
|
|
@ -87,6 +87,10 @@ export default function SetupPage() {
|
|||
const [perplexityAPIKey, setPerplexityAPIKey] = useState("")
|
||||
const [openrouterAPIKey, setOpenrouterAPIKey] = useState("")
|
||||
|
||||
// 只允许点击一次
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
//const supabaseClient = await supabase(); // Await the client creation
|
||||
|
|
@ -131,7 +135,10 @@ export default function SetupPage() {
|
|||
const handleShouldProceed = (proceed: boolean) => {
|
||||
if (proceed) {
|
||||
if (currentStep === SETUP_STEP_COUNT) {
|
||||
//handleSaveSetupSetting()
|
||||
if (!isSubmitting) {
|
||||
handleSaveSetupSetting()
|
||||
}
|
||||
} else {
|
||||
setCurrentStep(currentStep + 1)
|
||||
}
|
||||
|
|
@ -140,7 +147,79 @@ export default function SetupPage() {
|
|||
}
|
||||
}
|
||||
|
||||
// const handleSaveSetupSetting = async () => {
|
||||
|
||||
// const session = (await supabase.auth.getSession()).data.session
|
||||
// if (!session) {
|
||||
// return router.push(getLocalizedPath("login"))
|
||||
// }
|
||||
|
||||
// const user = session.user
|
||||
// const profile = await getProfileByUserId(user.id)
|
||||
|
||||
// const updateProfilePayload: TablesUpdate<"profiles"> = {
|
||||
// ...profile,
|
||||
// has_onboarded: true,
|
||||
// display_name: displayName,
|
||||
// username,
|
||||
// openai_api_key: openaiAPIKey,
|
||||
// openai_organization_id: openaiOrgID,
|
||||
// anthropic_api_key: anthropicAPIKey,
|
||||
// google_gemini_api_key: googleGeminiAPIKey,
|
||||
// mistral_api_key: mistralAPIKey,
|
||||
// groq_api_key: groqAPIKey,
|
||||
// perplexity_api_key: perplexityAPIKey,
|
||||
// openrouter_api_key: openrouterAPIKey,
|
||||
// use_azure_openai: useAzureOpenai,
|
||||
// azure_openai_api_key: azureOpenaiAPIKey,
|
||||
// azure_openai_endpoint: azureOpenaiEndpoint,
|
||||
// azure_openai_35_turbo_id: azureOpenai35TurboID,
|
||||
// azure_openai_45_turbo_id: azureOpenai45TurboID,
|
||||
// azure_openai_45_vision_id: azureOpenai45VisionID,
|
||||
// azure_openai_embeddings_id: azureOpenaiEmbeddingsID
|
||||
// }
|
||||
|
||||
// const updatedProfile = await updateProfile(profile.id, updateProfilePayload)
|
||||
// setProfile(updatedProfile)
|
||||
|
||||
// const workspaces = await getWorkspacesByUserId(profile.user_id)
|
||||
// const homeWorkspace = workspaces.find(w => w.is_home)
|
||||
|
||||
// if (!homeWorkspace) {
|
||||
// throw new Error("Home workspace not found for user during setup. This should not happen.")
|
||||
// }
|
||||
|
||||
// const baseUrl = typeof window !== "undefined"
|
||||
// ? `http://${window.location.hostname}:30000/v1`
|
||||
// : "http://localhost:30000/v1"
|
||||
|
||||
// if (typeof window !== "undefined") {
|
||||
// await createModel(
|
||||
// {
|
||||
// user_id: profile.user_id,
|
||||
// name: "Default",
|
||||
// model_id: "GPT",
|
||||
// base_url: baseUrl,
|
||||
// api_key: "token-abc123",
|
||||
// description: "Default LLM model created during onboarding",
|
||||
// context_length: 131072
|
||||
// },
|
||||
// homeWorkspace.id
|
||||
// )
|
||||
// }
|
||||
|
||||
// // There will always be a home workspace
|
||||
// setSelectedWorkspace(homeWorkspace!)
|
||||
// setWorkspaces(workspaces)
|
||||
|
||||
// return router.push(getLocalizedPath(`${homeWorkspace?.id}/chat`))
|
||||
// }
|
||||
|
||||
const handleSaveSetupSetting = async () => {
|
||||
if (isSubmitting) return
|
||||
setIsSubmitting(true)
|
||||
|
||||
try {
|
||||
const session = (await supabase.auth.getSession()).data.session
|
||||
if (!session) {
|
||||
return router.push(getLocalizedPath("login"))
|
||||
|
|
@ -178,7 +257,7 @@ export default function SetupPage() {
|
|||
const homeWorkspace = workspaces.find(w => w.is_home)
|
||||
|
||||
if (!homeWorkspace) {
|
||||
throw new Error("Home workspace not found for user during setup. This should not happen.")
|
||||
throw new Error("Home workspace not found.")
|
||||
}
|
||||
|
||||
const baseUrl = typeof window !== "undefined"
|
||||
|
|
@ -200,12 +279,16 @@ export default function SetupPage() {
|
|||
)
|
||||
}
|
||||
|
||||
// There will always be a home workspace
|
||||
setSelectedWorkspace(homeWorkspace!)
|
||||
setSelectedWorkspace(homeWorkspace)
|
||||
setWorkspaces(workspaces)
|
||||
|
||||
return router.push(getLocalizedPath(`${homeWorkspace?.id}/chat`))
|
||||
router.push(getLocalizedPath(`${homeWorkspace.id}/chat`))
|
||||
} catch (err) {
|
||||
console.error("Setup failed:", err)
|
||||
setIsSubmitting(false) // 失败后允许重试
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const renderStep = (stepNum: number) => {
|
||||
switch (stepNum) {
|
||||
|
|
@ -285,7 +368,8 @@ export default function SetupPage() {
|
|||
stepNum={currentStep}
|
||||
stepTitle={t("setup.SetupComplete")}
|
||||
onShouldProceed={handleShouldProceed}
|
||||
showNextButton={true}
|
||||
//showNextButton={true}
|
||||
showNextButton={!isSubmitting} // 禁用按钮
|
||||
showBackButton={true}
|
||||
>
|
||||
<FinishStep displayName={displayName} />
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@ export const StepContainer: FC<StepContainerProps> = ({
|
|||
ref={buttonRef}
|
||||
size="sm"
|
||||
onClick={() => onShouldProceed(true)}
|
||||
disabled={!showNextButton}
|
||||
>
|
||||
{t("setup.next")}
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Reference in New Issue