2023-07-15 17:46:19 +03:00
|
|
|
import { useState } from 'react'
|
|
|
|
import { ErrorInfo } from '../components/BackendError';
|
2023-07-20 17:11:03 +03:00
|
|
|
import { postNewRSForm } from '../utils/backendAPI';
|
2023-07-15 17:46:19 +03:00
|
|
|
|
2023-07-15 17:57:25 +03:00
|
|
|
function useNewRSForm() {
|
2023-07-15 17:46:19 +03:00
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const [error, setError] = useState<ErrorInfo>(undefined);
|
|
|
|
|
2023-07-15 17:57:25 +03:00
|
|
|
async function createSchema({data, file, onSuccess}: {
|
|
|
|
data: any, file?: File,
|
|
|
|
onSuccess: (newID: string) => void
|
|
|
|
}) {
|
2023-07-15 17:46:19 +03:00
|
|
|
setError(undefined);
|
|
|
|
if (file) {
|
2023-07-15 17:57:25 +03:00
|
|
|
data['file'] = file;
|
|
|
|
data['fileName'] = file.name;
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
2023-07-15 17:57:25 +03:00
|
|
|
postNewRSForm({
|
|
|
|
data: data,
|
|
|
|
showError: true,
|
|
|
|
setLoading: setLoading,
|
|
|
|
onError: error => setError(error),
|
|
|
|
onSucccess: response => onSuccess(response.data.id)
|
2023-07-15 17:46:19 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-15 17:57:25 +03:00
|
|
|
return { createSchema, error, setError, loading };
|
2023-07-15 17:46:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export default useNewRSForm;
|