import * as React from 'react'; import { FormError } from 'components/common/Input/Input.styled'; import { InputLabel } from 'components/common/Input/InputLabel.styled'; import { ErrorMessage } from '@hookform/error-message'; import { useFormContext } from 'react-hook-form'; import ControlledInput from 'components/common/Input/ControlledInput'; import { Button } from 'components/common/Button/Button'; import * as S from 'widgets/ClusterConfigForm/ClusterConfigForm.styled'; import { useAppConfigFilesUpload } from 'lib/hooks/api/appConfig'; const Fileupload: React.FC<{ name: string; label: string }> = ({ name, label, }) => { const upload = useAppConfigFilesUpload(); const id = React.useId(); const { watch, setValue } = useFormContext(); const loc = watch(name); const handleFileChange = async (e: React.ChangeEvent) => { if (e.target.files) { const formData = new FormData(); const file = e.target.files[0]; formData.append('file', file); const resp = await upload.mutateAsync(formData); setValue(name, resp.location, { shouldValidate: true, shouldDirty: true, }); } }; const onReset = () => { setValue(name, '', { shouldValidate: true, shouldDirty: true }); }; return (
{label} {loc ? ( ) : ( {upload.isLoading ? (

Uploading...

) : ( )}
)}
); }; export default Fileupload;