Skip to content

Commit d16a146

Browse files
author
jan hof
committed
implemented config saving
1 parent 33c1fff commit d16a146

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/hooks/configHook.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import { useEffect, useState } from "react";
55
const useConfig = (namespace: string) => {
66
const [config, setConfig] = useState<JSONSchema6>();
77

8-
Axios.get("/api/webinterface/service/" + namespace).then((res) =>
9-
setConfig(res.data)
10-
);
8+
useEffect(() => {
9+
Axios.get("/api/webinterface/service/" + namespace).then((res) =>
10+
setConfig(res.data)
11+
);
12+
}, [namespace]);
1113

1214
return [config, setConfig];
1315
};

src/views/service/ServiceDetails.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import Form from "react-jsonschema-form";
44
import { RouteComponentProps } from "react-router-dom";
55
import { JSONSchema6 } from "json-schema";
66
import useConfig from "../../hooks/configHook";
7+
import Axios from "axios";
78

89
type ServiceDetailsProps = {
910
namespace: string;
1011
};
1112

1213
const ServiceDetails = (props: RouteComponentProps<ServiceDetailsProps>) => {
13-
const [config, setConfig] = useConfig(props.match.params.namespace);
14+
const namespace = props.match.params.namespace;
15+
const [config, setConfig] = useConfig(namespace);
1416

1517
return (
1618
<>
@@ -19,7 +21,9 @@ const ServiceDetails = (props: RouteComponentProps<ServiceDetailsProps>) => {
1921
<Form
2022
schema={config as JSONSchema6}
2123
onChange={() => console.log("changed")}
22-
onSubmit={() => console.log("submitted")}
24+
onSubmit={(e) =>
25+
Axios.post("/api/webinterface/service/" + namespace, e.formData)
26+
}
2327
onError={() => console.log("errors")}
2428
/>
2529
)}

0 commit comments

Comments
 (0)