diff --git a/src/components/organisms/LocationApproveWindow.tsx b/src/components/organisms/LocationApproveWindow.tsx index 7db4b31d..390719ca 100644 --- a/src/components/organisms/LocationApproveWindow.tsx +++ b/src/components/organisms/LocationApproveWindow.tsx @@ -58,8 +58,9 @@ const LocationApprove: FC = ({ isOpen, onClose, news, newFlashTitle }) = const { userStore } = store; const [shouldApprove, setApproveStatus] = useState(true); const [locationChanged, setLocationChanged] = useState(false); - const [newStreetLoc, setNewStreetLoc] = useState(null); - const [newGpsLoc, setNewGpsLoc] = useState(null); + const [newStreetLoc, setNewStreetLoc] = useState(undefined); + const [newGpsLoc, setNewGpsLoc] = useState(undefined); + const [newPointLoc, setNewPointLoc] = useState(undefined); const [locationToDisplay, setLocationToDisplay] = useState(news.curr_cbs_location_text); // Unauthorized user shouldn't be able to open the window in the first place const userInfo = userStore.userInfo && userStore.userInfo.data && userStore.userInfo.data.firstName ? @@ -68,14 +69,23 @@ const LocationApprove: FC = ({ isOpen, onClose, news, newFlashTitle }) = function handleApproveButton () { if (shouldApprove && locationChanged) { if (newStreetLoc) { - updateNews(news.id, locationQualificationOptions.MANUAL, newStreetLoc, null); + updateNews({ + newsId: news.id, + newLocationQualification: locationQualificationOptions.MANUAL, + streetLocation: newStreetLoc, + }); } else { - updateNews(news.id, locationQualificationOptions.MANUAL, null, newGpsLoc); + updateNews({ + newsId: news.id, + newLocationQualification: locationQualificationOptions.MANUAL, + gpsLocation: newGpsLoc, + pointLocation: newPointLoc, + }); } } else if (shouldApprove) { - updateNews(news.id, locationQualificationOptions.VERIFIED, null, null); + updateNews({newsId: news.id, newLocationQualification: locationQualificationOptions.VERIFIED}); } else { - updateNews(news.id, locationQualificationOptions.REJECTED, null, null); + updateNews({newsId: news.id, newLocationQualification: locationQualificationOptions.REJECTED}); } onCloseInitValues(); window.location.reload(); @@ -94,13 +104,14 @@ const LocationApprove: FC = ({ isOpen, onClose, news, newFlashTitle }) = const onMapLocationChange = useCallback( (location: IPoint) => { - setLocationChanged(true); + setNewPointLoc(location); store.fetchGpsLocation(location); if (store.gpsLocationData) { setNewGpsLoc(store.gpsLocationData); setLocationToDisplay(t('mapDialog.road') + " " + store.gpsLocationData.road1 + " - " + store.gpsLocationData.road_segment_name); } + setLocationChanged(true); }, [t, store], ); diff --git a/src/services/news.data.service.ts b/src/services/news.data.service.ts index 401de65c..6645fe7a 100644 --- a/src/services/news.data.service.ts +++ b/src/services/news.data.service.ts @@ -1,6 +1,7 @@ import axios from 'axios'; import { INewsFlash } from 'models/NewFlash'; import { IGpsData, IStreetData } from "models/WidgetData"; +import {IPoint} from "../models/Point"; const errorNews: INewsFlash = { lat: -1, @@ -68,16 +69,33 @@ function onErrorFetchNewsFlash() { return errorArr; } -export function updateNews(newsId: number, newLocationQualification: any, - streetLocation: IStreetData | null, gpsLocation: IGpsData | null) { +interface IUpdateNews { + newsId: number, + newLocationQualification: any, + streetLocation?: IStreetData, + gpsLocation?: IGpsData, + pointLocation?: IPoint, +} + +export function updateNews({ + newsId, + newLocationQualification, + streetLocation, + gpsLocation, + pointLocation, +} : IUpdateNews) { const data = []; - data.push(`newsflash_location_qualification=${newLocationQualification}`) + data.push(`newsflash_location_qualification=${newLocationQualification}`); + if (pointLocation) { + data.push(`lat=${pointLocation.latitude}`); + data.push(`lng=${pointLocation.longitude}`); + } if (gpsLocation) { - data.push(`road_segment_id=${gpsLocation.road_segment_id}`) - data.push(`road1=${gpsLocation.road1}`) + data.push(`road_segment_id=${gpsLocation.road_segment_id}`); + data.push(`road1=${gpsLocation.road1}`); } else if (streetLocation) { - data.push(`yishuv_name=${streetLocation.city.yishuv_name}`) - data.push(`street1_hebrew=${streetLocation.street.street_hebrew}`) + data.push(`yishuv_name=${streetLocation.city.yishuv_name}`); + data.push(`street1_hebrew=${streetLocation.street.street_hebrew}`); } const url = `${NEWS_FLASH_API}/${newsId}?${data.join('&')}`; axios