mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 13:00:39 +03:00
30 lines
805 B
TypeScript
30 lines
805 B
TypeScript
import { useState } from 'react'
|
|
import { ErrorInfo } from '../components/BackendError';
|
|
import { postNewRSForm } from '../backendAPI';
|
|
|
|
function useNewRSForm() {
|
|
const [loading, setLoading] = useState(false);
|
|
const [error, setError] = useState<ErrorInfo>(undefined);
|
|
|
|
async function createSchema({data, file, onSuccess}: {
|
|
data: any, file?: File,
|
|
onSuccess: (newID: string) => void
|
|
}) {
|
|
setError(undefined);
|
|
if (file) {
|
|
data['file'] = file;
|
|
data['fileName'] = file.name;
|
|
}
|
|
postNewRSForm({
|
|
data: data,
|
|
showError: true,
|
|
setLoading: setLoading,
|
|
onError: error => setError(error),
|
|
onSucccess: response => onSuccess(response.data.id)
|
|
});
|
|
}
|
|
|
|
return { createSchema, error, setError, loading };
|
|
}
|
|
|
|
export default useNewRSForm; |