-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateDataset.tsx
More file actions
55 lines (44 loc) · 1.46 KB
/
CreateDataset.tsx
File metadata and controls
55 lines (44 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React, {useState} from "react";
import {Box, Container} from "@material-ui/core";
import Form from "@rjsf/material-ui";
import datasetSchema from "../../schema/datasetSchema.json";
import {createDataset} from "../../utils/dataset";
import LoadingOverlay from "react-loading-overlay-ts";
import {useNavigate} from "react-router";
import {FormProps} from "@rjsf/core";
import {ClowderButton} from "../styledComponents/ClowderButton";
type Props = {
setOpen: any
}
export default function CreateDataset(props: Props) {
const {setOpen} = props;
const history = useNavigate();
// const [disabled, setDisabled] = useState(true);
const [loading, setLoading] = useState(false);
const onSave = async (formData:FormData) => {
setLoading(true);
const response = await createDataset(formData);
setLoading(false);
setOpen(false);
// zoom into that newly created dataset
if (response !== {} && response["id"] !== undefined) {
history(`/datasets/${response["id"]}`);
}
};
return (
<Container>
<LoadingOverlay
active={loading}
spinner
text="Saving..."
>
<Form schema={datasetSchema["schema"] as FormProps<any>["schema"]} uiSchema={datasetSchema["uiSchema"]} // widgets={widgets}
onSubmit={({formData}, _) => {onSave(formData);}}>
<Box className="inputGroup">
<ClowderButton variant="contained" type="submit" className="form-button-block">Create</ClowderButton>
</Box>
</Form>
</LoadingOverlay>
</Container>
);
}