mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 01:37:48 -05:00
Updating systems too!
This commit is contained in:
@@ -266,14 +266,15 @@ exports.updateSystem = async function (req, res, next) {
|
|||||||
res.locals.system.showScreenName = res.locals.showScreenName;
|
res.locals.system.showScreenName = res.locals.showScreenName;
|
||||||
res.locals.system.ignoreUnknownTalkgroup = res.locals.ignoreUnknownTalkgroup;
|
res.locals.system.ignoreUnknownTalkgroup = res.locals.ignoreUnknownTalkgroup;
|
||||||
|
|
||||||
res.locals.system.save(function (err) {
|
|
||||||
if (err) {
|
await res.locals.system.save().catch( err => {
|
||||||
|
res.status(500);
|
||||||
res.json({
|
res.json({
|
||||||
success: false,
|
success: false,
|
||||||
message: err
|
message: err
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
});
|
||||||
var returnSys = (({
|
var returnSys = (({
|
||||||
name,
|
name,
|
||||||
shortName,
|
shortName,
|
||||||
@@ -305,8 +306,8 @@ exports.updateSystem = async function (req, res, next) {
|
|||||||
res.json(returnSys);
|
res.json(returnSys);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// -------------------------------------------
|
// -------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import Restricted from "./Restricted"
|
|||||||
import About from "../Components/About"
|
import About from "../Components/About"
|
||||||
import System from "../System/System"
|
import System from "../System/System"
|
||||||
import ListSystems from "../System/ListSystems"
|
import ListSystems from "../System/ListSystems"
|
||||||
import UpdateSystemContainer from "../System/UpdateSystemContainer"
|
import UpdateSystem from "../System/UpdateSystem"
|
||||||
import CreateSystem from "../System/CreateSystem"
|
import CreateSystem from "../System/CreateSystem"
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ const App = (params) => {
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/about" element={ <Restricted><About/></Restricted>} />
|
<Route path="/about" element={ <Restricted><About/></Restricted>} />
|
||||||
<Route path="/system/:shortName" element={ <Restricted><System/></Restricted>} />
|
<Route path="/system/:shortName" element={ <Restricted><System/></Restricted>} />
|
||||||
<Route path="/update-system/:shortName" component={Restricted(UpdateSystemContainer, store)} />
|
<Route path="/update-system/:shortName" element={ <Restricted><UpdateSystem/></Restricted>} />
|
||||||
<Route path="/create-system" element={ <Restricted><CreateSystem/></Restricted>} />
|
<Route path="/create-system" element={ <Restricted><CreateSystem/></Restricted>} />
|
||||||
<Route path="/list-systems" element={ <Restricted><ListSystems/></Restricted>} />
|
<Route path="/list-systems" element={ <Restricted><ListSystems/></Restricted>} />
|
||||||
<Route path="/" element={ <Restricted><ListSystems/></Restricted>} />
|
<Route path="/" element={ <Restricted><ListSystems/></Restricted>} />
|
||||||
|
|||||||
@@ -39,8 +39,6 @@ const CreateSystem = (props) => {
|
|||||||
console.log(message);
|
console.log(message);
|
||||||
setRequestMessage(message);
|
setRequestMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
import React, { Component } from "react"
|
import React, { useEffect, useLayoutEffect, useState, useRef, useCallback, useMemo } from "react";
|
||||||
import SystemForm from "./SystemForm";
|
import SystemForm from "./SystemForm";
|
||||||
import {
|
import {
|
||||||
Container,
|
Container,
|
||||||
Header
|
Header
|
||||||
} from "semantic-ui-react";
|
} from "semantic-ui-react";
|
||||||
|
import { useUpdateSystemMutation, useGetSystemsQuery, } from '../features/api/apiSlice'
|
||||||
|
import { useSelector, useDispatch } from 'react-redux'
|
||||||
|
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||||
|
|
||||||
class UpdateSystem extends Component {
|
const UpdateSystem = (props) => {
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
const { screenName } = useSelector((state) => state.user);
|
||||||
this.handleSystemSubmit = this.handleSystemSubmit.bind(this);
|
const { shortName } = useParams();
|
||||||
|
const { data: systemsData, isSuccess: isSystemsSuccess } = useGetSystemsQuery();
|
||||||
|
const [updateSystem, { error }] = useUpdateSystemMutation();
|
||||||
|
const [requestMessage, setRequestMessage] = useState("");
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
let system = false;
|
||||||
|
if (isSystemsSuccess) {
|
||||||
|
system = systemsData.systems.find(sys => sys.shortName == shortName);
|
||||||
}
|
}
|
||||||
|
|
||||||
state = {
|
|
||||||
requestMessage: ""
|
const handleSystemSubmit = async (system) => {
|
||||||
|
try {
|
||||||
|
const originalPromiseResult = await updateSystem(system).unwrap();
|
||||||
|
navigate("/system/" + shortName)
|
||||||
|
} catch (error) {
|
||||||
|
const message = error.data.message;
|
||||||
|
console.log(message);
|
||||||
|
setRequestMessage(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.props.fetchSystems()
|
|
||||||
}
|
|
||||||
|
|
||||||
handleSystemSubmit(system) {
|
return (
|
||||||
this.props
|
<Container text>
|
||||||
.updateSystem(system)
|
<Header as="h1">Update System</Header>
|
||||||
.then(requestMessage => {
|
<SystemForm onSubmit={handleSystemSubmit} system={system} isEditing={true} requestMessage={requestMessage} screenName={screenName} />
|
||||||
if (requestMessage) {
|
</Container>
|
||||||
// report to the user is there was a problem during registration
|
)
|
||||||
this.setState({
|
|
||||||
requestMessage
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.props.changeUrl("/system/"+system.shortName)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return(
|
|
||||||
<Container text>
|
|
||||||
<Header as="h1">Update System</Header>
|
|
||||||
<SystemForm onSubmit={this.handleSystemSubmit} system={this.props.system} isEditing={true} requestMessage={this.state.requestMessage} screenName={this.props.user.screenName}/>
|
|
||||||
</Container>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default UpdateSystem
|
export default UpdateSystem
|
||||||
|
|||||||
@@ -145,9 +145,27 @@ export const apiSlice = createApi({
|
|||||||
} catch {}
|
} catch {}
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
updateSystem: builder.mutation({
|
||||||
|
query: (system) => ({
|
||||||
|
url: `/systems/${system.shortName}`,
|
||||||
|
method: 'POST',
|
||||||
|
credentials: "include",
|
||||||
|
body: system,
|
||||||
|
}),
|
||||||
|
async onQueryStarted(system, { dispatch, queryFulfilled }) {
|
||||||
|
try {
|
||||||
|
const { data: updatedSystem } = await queryFulfilled
|
||||||
|
const patchResult = dispatch(
|
||||||
|
apiSlice.util.updateQueryData('getSystems', system.shortName, (systems) => {
|
||||||
|
const systemIndex = systems.findIndex((obj => obj.shortName == updatedSystem.shortName));
|
||||||
|
systems[systemIndex] = updatedSystem;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
} catch {}
|
||||||
|
},
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Export the auto-generated hook for the `getPosts` query endpoint
|
// Export the auto-generated hook for the `getPosts` query endpoint
|
||||||
export const { useGetGroupsQuery, useGetSystemsQuery, useGetTalkgroupsQuery, useGetErrorsQuery, useDeleteGroupMutation, useCreateGroupMutation, useCreateSystemMutation, useSaveGroupOrderMutation, useUpdateGroupMutation, useImportTalkgroupsMutation } = apiSlice
|
export const { useGetGroupsQuery, useGetSystemsQuery, useGetTalkgroupsQuery, useGetErrorsQuery, useDeleteGroupMutation, useCreateGroupMutation, useCreateSystemMutation, useUpdateSystemMutation, useSaveGroupOrderMutation, useUpdateGroupMutation, useImportTalkgroupsMutation } = apiSlice
|
||||||
|
|||||||
Reference in New Issue
Block a user