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"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="ffab9a85-d9fb-41e5-9b26-b6bb18eb7f17" name="Default Changelist" comment=""> <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$/.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/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> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -71,7 +69,7 @@
<workItem from="1629286329005" duration="875000" /> <workItem from="1629286329005" duration="875000" />
<workItem from="1630189077321" duration="694000" /> <workItem from="1630189077321" duration="694000" />
<workItem from="1635667952517" duration="2107000" /> <workItem from="1635667952517" duration="2107000" />
<workItem from="1635678316673" duration="19266000" /> <workItem from="1635678316673" duration="21523000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -1,13 +1,24 @@
import axios from "axios"; import axios from "axios";
export const updateNeighbourhoodResponsible = async (userInfo: UserInfo, x: any) => { export const updateElectionNeighbourhoodResponsible = async (userInfo: UserInfo, updateInfo: { electionNeighbourhoodId: number }) => {
const config = { const config = {
headers: { headers: {
'Content-type': 'application/json', 'Content-type': 'application/json',
Authorization: `Bearer ${userInfo.access}` 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; return data;
} }

View File

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