import React, { useEffect } from 'react'; import { useForm, Controller } from 'react-hook-form'; import { Button, Input, Label, OGDialog, OGDialogTemplate } from '@librechat/client'; import type { ConfigFieldDetail } from '~/common'; import { useLocalize } from '~/hooks'; interface MCPConfigDialogProps { isOpen: boolean; onOpenChange: (isOpen: boolean) => void; fieldsSchema: Record; initialValues: Record; onSave: (updatedValues: Record) => void; isSubmitting?: boolean; onRevoke?: () => void; serverName: string; } export default function MCPConfigDialog({ isOpen, onOpenChange, fieldsSchema, initialValues, onSave, isSubmitting = false, onRevoke, serverName, }: MCPConfigDialogProps) { const localize = useLocalize(); const { control, handleSubmit, reset, formState: { errors }, } = useForm>({ defaultValues: initialValues, }); useEffect(() => { if (isOpen) { reset(initialValues); } }, [isOpen, initialValues, reset]); const onFormSubmit = (data: Record) => { onSave(data); }; const handleRevoke = () => { if (onRevoke) { onRevoke(); } }; const dialogTitle = localize('com_ui_configure_mcp_variables_for', { 0: serverName }); return ( {Object.entries(fieldsSchema).map(([key, details]) => (
( )} /> {details.description && (

)} {errors[key] &&

{errors[key]?.message}

}
))} } selection={{ selectHandler: handleSubmit(onFormSubmit), selectClasses: 'bg-green-500 hover:bg-green-600 text-white', selectText: isSubmitting ? localize('com_ui_saving') : localize('com_ui_save'), }} buttons={ onRevoke && ( ) } footerClassName="flex justify-end gap-2 px-6 pb-6 pt-2" showCancelButton={true} />
); }