diff --git a/web/app/components/base/form/components/base/base-field.tsx b/web/app/components/base/form/components/base/base-field.tsx index e48ce780c0..0195f38795 100644 --- a/web/app/components/base/form/components/base/base-field.tsx +++ b/web/app/components/base/form/components/base/base-field.tsx @@ -87,7 +87,7 @@ const BaseField = ({
{memorizedLabel} { - required && ( + required && !isValidElement(label) && ( * ) } diff --git a/web/app/components/base/form/components/base/base-form.tsx b/web/app/components/base/form/components/base/base-form.tsx index 7502911a34..ee78561250 100644 --- a/web/app/components/base/form/components/base/base-form.tsx +++ b/web/app/components/base/form/components/base/base-form.tsx @@ -5,6 +5,7 @@ import { } from 'react' import type { AnyFieldApi, + AnyFormApi, } from '@tanstack/react-form' import { useForm } from '@tanstack/react-form' import type { @@ -29,6 +30,7 @@ export type BaseFormProps = { formClassName?: string ref?: FormRef disabled?: boolean + formFromProps?: AnyFormApi } & Pick const BaseForm = ({ @@ -41,10 +43,12 @@ const BaseForm = ({ inputClassName, ref, disabled, + formFromProps, }: BaseFormProps) => { - const form = useForm({ + const formFromHook = useForm({ defaultValues, }) + const form: any = formFromProps || formFromHook const { getFormValues } = useGetFormValues(form) const { getValidators } = useGetValidators() @@ -102,10 +106,6 @@ const BaseForm = ({ return (
{ - e.preventDefault() - form?.handleSubmit() - }} > {formSchemas.map(renderFieldWrapper)}
diff --git a/web/app/components/base/form/form-scenarios/auth/index.tsx b/web/app/components/base/form/form-scenarios/auth/index.tsx index 5a88f94ac6..3927f90959 100644 --- a/web/app/components/base/form/form-scenarios/auth/index.tsx +++ b/web/app/components/base/form/form-scenarios/auth/index.tsx @@ -6,6 +6,7 @@ const AuthForm = ({ formSchemas = [], defaultValues, ref, + formFromProps, }: BaseFormProps) => { return ( ) } diff --git a/web/app/components/plugins/plugin-auth/authorize/add-api-key-button.tsx b/web/app/components/plugins/plugin-auth/authorize/add-api-key-button.tsx index 733ebbd945..ad15a37d5c 100644 --- a/web/app/components/plugins/plugin-auth/authorize/add-api-key-button.tsx +++ b/web/app/components/plugins/plugin-auth/authorize/add-api-key-button.tsx @@ -24,7 +24,7 @@ const AddApiKeyButton = ({ return ( <>
{renderI18nObject(item.label as Record)} + { + item.required && ( + * + ) + }
) @@ -157,7 +162,7 @@ const AddOAuthButton = ({ + + ) + } > { + const apiMap = useGetApi(pluginPayload) + + return useInvalidPluginOAuthClientSchema(apiMap.getOauthClientSchema) +} + export const useSetPluginOAuthCustomClientHook = (pluginPayload: PluginPayload) => { const apiMap = useGetApi(pluginPayload) return useSetPluginOAuthCustomClient(apiMap.setCustomOauthClient) } + +export const useDeletePluginOAuthCustomClientHook = (pluginPayload: PluginPayload) => { + const apiMap = useGetApi(pluginPayload) + + return useDeletePluginOAuthCustomClient(apiMap.deleteCustomOAuthClient) +} diff --git a/web/app/components/plugins/plugin-auth/hooks/use-get-api.ts b/web/app/components/plugins/plugin-auth/hooks/use-get-api.ts index 9b88cb0dad..14199ddc4d 100644 --- a/web/app/components/plugins/plugin-auth/hooks/use-get-api.ts +++ b/web/app/components/plugins/plugin-auth/hooks/use-get-api.ts @@ -20,6 +20,7 @@ export const useGetApi = ({ category = AuthCategory.tool, provider }: PluginPayl getOauthClientSchema: `/workspaces/current/tool-provider/builtin/${provider}/oauth/client-schema`, setCustomOauthClient: `/workspaces/current/tool-provider/builtin/${provider}/oauth/custom-client`, getCustomOAuthClientValues: `/workspaces/current/tool-provider/builtin/${provider}/oauth/custom-client`, + deleteCustomOAuthClient: `/workspaces/current/tool-provider/builtin/${provider}/oauth/custom-client`, } } @@ -35,5 +36,6 @@ export const useGetApi = ({ category = AuthCategory.tool, provider }: PluginPayl getOauthClientSchema: '', setCustomOauthClient: '', getCustomOAuthClientValues: '', + deleteCustomOAuthClient: '', } } diff --git a/web/service/use-plugins-auth.ts b/web/service/use-plugins-auth.ts index 7c72455a53..2dc0260647 100644 --- a/web/service/use-plugins-auth.ts +++ b/web/service/use-plugins-auth.ts @@ -2,7 +2,7 @@ import { useMutation, useQuery, } from '@tanstack/react-query' -import { get, post } from './base' +import { del, get, post } from './base' import { useInvalid } from './use-base' import type { Credential, @@ -131,6 +131,12 @@ export const useGetPluginOAuthClientSchema = ( }) } +export const useInvalidPluginOAuthClientSchema = ( + url: string, +) => { + return useInvalid([NAME_SPACE, 'oauth-client-schema', url]) +} + export const useSetPluginOAuthCustomClient = ( url: string, ) => { @@ -143,3 +149,13 @@ export const useSetPluginOAuthCustomClient = ( }, }) } + +export const useDeletePluginOAuthCustomClient = ( + url: string, +) => { + return useMutation({ + mutationFn: () => { + return del<{ result: string }>(url) + }, + }) +}