mirror of
https://github.com/ONLYOFFICE/desktop-sdk.git
synced 2026-03-31 10:23:12 +08:00
Fixed Bug 78626 - When adding a provider for Ai Agent, special characters are not filtered in the Name field.
This commit is contained in:
@ -16,6 +16,7 @@ import {
|
|||||||
dialogButtonContainerStyles,
|
dialogButtonContainerStyles,
|
||||||
} from "./Providers.styles";
|
} from "./Providers.styles";
|
||||||
import { Input } from "@/components/input";
|
import { Input } from "@/components/input";
|
||||||
|
import { Loader } from "@/components/loader";
|
||||||
|
|
||||||
type AddProviderDialogProps = {
|
type AddProviderDialogProps = {
|
||||||
onClose: VoidFunction;
|
onClose: VoidFunction;
|
||||||
@ -45,6 +46,10 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
const isRequestRunningRef = React.useRef(isRequestRunning);
|
const isRequestRunningRef = React.useRef(isRequestRunning);
|
||||||
|
|
||||||
const dialogRef = React.useRef<HTMLDivElement>(null);
|
const dialogRef = React.useRef<HTMLDivElement>(null);
|
||||||
|
const buttonRef = React.useRef<HTMLButtonElement>(null);
|
||||||
|
const [buttonWidth, setButtonWidth] = React.useState<number | undefined>(
|
||||||
|
undefined
|
||||||
|
);
|
||||||
|
|
||||||
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setValue((prevValue) => ({
|
setValue((prevValue) => ({
|
||||||
@ -64,7 +69,7 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
|
|
||||||
const result = await addProvider({
|
const result = await addProvider({
|
||||||
type: selectedProviderInfo.type,
|
type: selectedProviderInfo.type,
|
||||||
name: value.name,
|
name: value.name.trim(),
|
||||||
key: value.key,
|
key: value.key,
|
||||||
baseUrl: value.url,
|
baseUrl: value.url,
|
||||||
});
|
});
|
||||||
@ -88,6 +93,13 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
}));
|
}));
|
||||||
}, [selectedProviderInfo]);
|
}, [selectedProviderInfo]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (buttonRef.current && buttonWidth === undefined) {
|
||||||
|
const width = buttonRef.current.offsetWidth + 1;
|
||||||
|
setButtonWidth(width);
|
||||||
|
}
|
||||||
|
}, [buttonWidth]);
|
||||||
|
|
||||||
const isDisabled =
|
const isDisabled =
|
||||||
!value.name || !value.url || !!error.key || !!error.url || !!error.name;
|
!value.name || !value.url || !!error.key || !!error.url || !!error.name;
|
||||||
|
|
||||||
@ -114,6 +126,7 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
isError={!!error.name}
|
isError={!!error.name}
|
||||||
placeholder={t("EnterName")}
|
placeholder={t("EnterName")}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
|
maxLength={128}
|
||||||
/>
|
/>
|
||||||
</FieldContainer>
|
</FieldContainer>
|
||||||
<FieldContainer header={t("URL")} error={error.url}>
|
<FieldContainer header={t("URL")} error={error.url}>
|
||||||
@ -143,10 +156,16 @@ const AddProviderDialog = ({ onClose }: AddProviderDialogProps) => {
|
|||||||
{t("Cancel")}
|
{t("Cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
ref={buttonRef}
|
||||||
onClick={onSubmitAction}
|
onClick={onSubmitAction}
|
||||||
disabled={isDisabled || isRequestRunning}
|
disabled={isDisabled || isRequestRunning}
|
||||||
|
style={buttonWidth ? { width: `${buttonWidth}px` } : undefined}
|
||||||
>
|
>
|
||||||
{t("AddProvider")}
|
{isRequestRunning ? (
|
||||||
|
<Loader className="border-[var(--text-contrast-background)] border-r-transparent" />
|
||||||
|
) : (
|
||||||
|
t("AddProvider")
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user