update status function added.

This commit is contained in:
Christiaan Evers 2021-11-10 01:18:21 +01:00
parent a887b0d690
commit f8b0a2d0aa
3 changed files with 36 additions and 17 deletions

View File

@ -2,11 +2,9 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="ffab9a85-d9fb-41e5-9b26-b6bb18eb7f17" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/requests/updates/index.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/components/Loader/index.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/components/Loader/index.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/requests/updates/index.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/requests/updates/index.ts" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/screens/GeoMap.tsx" beforeDir="false" afterPath="$PROJECT_DIR$/src/screens/GeoMap.tsx" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/typings/index.d.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/typings/index.d.ts" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -71,7 +69,7 @@
<workItem from="1629286329005" duration="875000" />
<workItem from="1630189077321" duration="694000" />
<workItem from="1635667952517" duration="2107000" />
<workItem from="1635678316673" duration="19266000" />
<workItem from="1635678316673" duration="21523000" />
</task>
<servers />
</component>

View File

@ -1,13 +1,24 @@
import axios from "axios";
export const updateNeighbourhoodResponsible = async (userInfo: UserInfo, x: any) => {
export const updateElectionNeighbourhoodResponsible = async (userInfo: UserInfo, updateInfo: { electionNeighbourhoodId: number }) => {
const config = {
headers: {
'Content-type': 'application/json',
Authorization: `Bearer ${userInfo.access}`
}
}
const {data} = await axios.post(`/api/update-responsible`, x, config)
const {data} = await axios.post(`/api/update-responsible`, updateInfo, config)
return data;
}
export const updateElectionNeighbourhoodStatus = async (userInfo: UserInfo, updateInfo: { electionNeighbourhoodId: number, status: number }) => {
const config = {
headers: {
'Content-type': 'application/json',
Authorization: `Bearer ${userInfo.access}`
}
}
const {data} = await axios.post(`/api/update-status`, updateInfo, config)
return data;
}

View File

@ -8,7 +8,7 @@ import {getLatestElection} from "../actions/election-actions";
import {useDispatch, useSelector} from "react-redux";
import {AlertMessage} from "../components/Alert";
import {Loader} from "../components/Loader";
import {updateNeighbourhoodResponsible} from "../requests/updates";
import {updateElectionNeighbourhoodResponsible, updateElectionNeighbourhoodStatus} from "../requests/updates";
const useStyles = makeStyles((theme: Theme) => ({
GeoMapContainer: {
@ -75,7 +75,7 @@ export const GeoMap = ({Location, history}: {Location: any, history: any}) => {
const electionNeighbourhood: ElectionNeighbourhood = election.election_to_neighbourhood.find(x => x.neighbourhood.code === neighbourhood.properties.Buurt_code) as ElectionNeighbourhood;
if(electionNeighbourhood){
layer.options.fillOpacity = Number(electionNeighbourhood.status)
layer.bindPopup(`${neighbourhood.properties.Buurt} ${Math.round(Number(electionNeighbourhood.status)*100)}%`)
layer.bindPopup(`${neighbourhood.properties.Buurt}`)
}
layer.on({
click: (event: any) => {
@ -87,17 +87,27 @@ export const GeoMap = ({Location, history}: {Location: any, history: any}) => {
}
const subscribeToNeighbourhood = () => {
const updateInfo: { electionNeighbourhoodId: number } = {
electionNeighbourhoodId: selectedElectionNeighbourhood ? selectedElectionNeighbourhood._id : 0
if(selectedElectionNeighbourhood){
const updateInfo: { electionNeighbourhoodId: number } = {
electionNeighbourhoodId: selectedElectionNeighbourhood._id
}
updateElectionNeighbourhoodResponsible(userInfo, updateInfo).then((updatedElectionNeighbourhood: ElectionNeighbourhood) => {
setSelectedElectionNeighbourhood(updatedElectionNeighbourhood);
})
}
console.log(updateInfo);
updateNeighbourhoodResponsible(userInfo, updateInfo).then((updatedElectionNeighbourhood: ElectionNeighbourhood) => {
setSelectedElectionNeighbourhood(updatedElectionNeighbourhood);
})
}
const changeNeighbourhoodStatus = (percentage: number) => {
console.log(percentage);
const changeNeighbourhoodStatus = (percentage: number, selectedElectionNeighbourhood: ElectionNeighbourhood) => {
if(selectedElectionNeighbourhood) {
const updateInfo: { electionNeighbourhoodId: number, status: number } = {
electionNeighbourhoodId: selectedElectionNeighbourhood._id,
status: Math.round(percentage)/100
}
updateElectionNeighbourhoodStatus(userInfo, updateInfo).then((updatedElectionNeighbourhood: ElectionNeighbourhood) => {
setSelectedElectionNeighbourhood(updatedElectionNeighbourhood);
})
//setSelectedElectionNeighbourhood({...selectedElectionNeighbourhood, status: (Math.round(percentage) / 100)})
}
}
return (
@ -166,7 +176,7 @@ export const GeoMap = ({Location, history}: {Location: any, history: any}) => {
size={'small'}
variant={'standard'}
value={(Math.round(selectedElectionNeighbourhood.status*100))}
onChange={(event) => changeNeighbourhoodStatus(Number(event.target.value))}
onChange={(event) => changeNeighbourhoodStatus(Number(event.target.value), selectedElectionNeighbourhood)}
/>
</Grid>
</Grid>