import { Button, Checkbox, Flex, FormControl, FormHelperText, FormLabel, Input } from '@invoke-ai/ui-library'; import { useAppDispatch, useAppSelector } from 'app/store/storeHooks'; import { useInstallModel } from 'features/modelManagerV2/hooks/useInstallModel'; import { selectShouldInstallInPlace, shouldInstallInPlaceChanged, } from 'features/modelManagerV2/store/modelManagerV2Slice'; import { t } from 'i18next'; import type { ChangeEvent } from 'react'; import { memo, useCallback } from 'react'; import type { SubmitHandler } from 'react-hook-form'; import { useForm } from 'react-hook-form'; type SimpleImportModelConfig = { location: string; }; export const InstallModelForm = memo(() => { const inplace = useAppSelector(selectShouldInstallInPlace); const dispatch = useAppDispatch(); const [installModel, { isLoading }] = useInstallModel(); const { register, handleSubmit, formState, reset } = useForm({ defaultValues: { location: '', }, mode: 'onChange', }); const resetForm = useCallback(() => reset(undefined, { keepValues: true }), [reset]); const onSubmit = useCallback>( (values) => { if (!values?.location) { return; } installModel({ source: values.location, inplace: inplace, onSuccess: resetForm, onError: resetForm, }); }, [installModel, resetForm, inplace] ); const onChangeInplace = useCallback( (e: ChangeEvent) => { dispatch(shouldInstallInPlaceChanged(e.target.checked)); }, [dispatch] ); return (
{t('modelManager.urlOrLocalPath')} {t('modelManager.urlOrLocalPathHelper')} {t('modelManager.inplaceInstall')} ({t('modelManager.localOnly')}) {t('modelManager.inplaceInstallDesc')}
); }); InstallModelForm.displayName = 'InstallModelForm';