mirror of
https://github.com/langgenius/dify.git
synced 2026-05-03 17:08:03 +08:00
refactor: enhance app input handling and modal state management
- Improved the useAppInputsFormSchema hook to handle workflow apps by ensuring workflow data is available before proceeding. - Added guards in useCommonModalState to prevent errors from uninitialized state and ensure proper error notifications. - Enhanced useOAuthClientState to validate the presence of schema and handle missing form values more robustly. - Cleaned up code for better readability and maintainability.
This commit is contained in:
@ -205,7 +205,12 @@ export function useAppInputsFormSchema({
|
|||||||
if (!currentApp)
|
if (!currentApp)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
// For workflow apps, wait until workflow data is available
|
||||||
|
if (!isBasicApp && !currentWorkflow)
|
||||||
|
return []
|
||||||
|
|
||||||
// Build base schema based on app type
|
// Build base schema based on app type
|
||||||
|
// Note: currentWorkflow is guaranteed to be defined here due to the early return above
|
||||||
const baseSchema = isBasicApp
|
const baseSchema = isBasicApp
|
||||||
? buildBasicAppSchema(currentApp, fileUploadConfig)
|
? buildBasicAppSchema(currentApp, fileUploadConfig)
|
||||||
: buildWorkflowSchema(currentWorkflow!, fileUploadConfig)
|
: buildWorkflowSchema(currentWorkflow!, fileUploadConfig)
|
||||||
|
|||||||
@ -237,6 +237,15 @@ export const useCommonModalState = ({
|
|||||||
|
|
||||||
// Handle verify
|
// Handle verify
|
||||||
const handleVerify = useCallback(() => {
|
const handleVerify = useCallback(() => {
|
||||||
|
// Guard against uninitialized state
|
||||||
|
if (!detail?.provider || !subscriptionBuilder?.id) {
|
||||||
|
Toast.notify({
|
||||||
|
type: 'error',
|
||||||
|
message: 'Subscription builder not initialized',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const apiKeyCredentialsFormValues = apiKeyCredentialsFormRef.current?.getFormValues({}) || DEFAULT_FORM_VALUES
|
const apiKeyCredentialsFormValues = apiKeyCredentialsFormRef.current?.getFormValues({}) || DEFAULT_FORM_VALUES
|
||||||
const credentials = apiKeyCredentialsFormValues.values
|
const credentials = apiKeyCredentialsFormValues.values
|
||||||
|
|
||||||
@ -255,8 +264,8 @@ export const useCommonModalState = ({
|
|||||||
|
|
||||||
verifyCredentials(
|
verifyCredentials(
|
||||||
{
|
{
|
||||||
provider: detail?.provider || '',
|
provider: detail.provider,
|
||||||
subscriptionBuilderId: subscriptionBuilder?.id || '',
|
subscriptionBuilderId: subscriptionBuilder.id,
|
||||||
credentials,
|
credentials,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@ -164,11 +164,18 @@ export const useOAuthClientState = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isCustom) {
|
if (isCustom) {
|
||||||
|
// Short-circuit if no schema to validate
|
||||||
|
if (!oauthClientSchema?.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const clientFormValues = clientFormRef.current?.getFormValues({}) as {
|
const clientFormValues = clientFormRef.current?.getFormValues({}) as {
|
||||||
values: TriggerOAuthClientParams
|
values: TriggerOAuthClientParams
|
||||||
isCheckValidated: boolean
|
isCheckValidated: boolean
|
||||||
}
|
} | undefined
|
||||||
if (!clientFormValues.isCheckValidated)
|
|
||||||
|
// Handle missing ref or form values
|
||||||
|
if (!clientFormValues || !clientFormValues.isCheckValidated)
|
||||||
return
|
return
|
||||||
|
|
||||||
const clientParams = { ...clientFormValues.values }
|
const clientParams = { ...clientFormValues.values }
|
||||||
@ -194,7 +201,7 @@ export const useOAuthClientState = ({
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}, [clientType, providerName, oauthConfig?.params, configureOAuth, handleAuthorization, onClose, t])
|
}, [clientType, providerName, oauthClientSchema, oauthConfig?.params, configureOAuth, handleAuthorization, onClose, t])
|
||||||
|
|
||||||
// Polling effect for authorization verification
|
// Polling effect for authorization verification
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user