updated the bin yard api with as fix
This commit is contained in:
parent
e2f5eb0557
commit
76744c1b6f
5 changed files with 26 additions and 22 deletions
|
|
@ -344,7 +344,7 @@ export default function BinSettings(props: Props) {
|
||||||
setBinYardOptions(y);
|
setBinYardOptions(y);
|
||||||
} else {
|
} else {
|
||||||
binYardAPI
|
binYardAPI
|
||||||
.listBinYards(350, 0, "desc", as ? as : userID)
|
.listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let data = resp.data.yard ? resp.data.yard : [];
|
let data = resp.data.yard ? resp.data.yard : [];
|
||||||
let yards: Option[] = data.map((yard: pond.BinYard) => {
|
let yards: Option[] = data.map((yard: pond.BinYard) => {
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ export default function BinYard(props: Props) {
|
||||||
const [leaving, setLeaving] = useState<boolean>(false);
|
const [leaving, setLeaving] = useState<boolean>(false);
|
||||||
const [yardPermissions, setYardPermissions] = useState<Dictionary<pond.Permission[]>>({});
|
const [yardPermissions, setYardPermissions] = useState<Dictionary<pond.Permission[]>>({});
|
||||||
const [searchSelected, setSearchSelected] = useState(false);
|
const [searchSelected, setSearchSelected] = useState(false);
|
||||||
const [{ user }] = useGlobalState();
|
const [{ user, as }] = useGlobalState();
|
||||||
const [addingYard, setAddingYard] = useState(false)
|
const [addingYard, setAddingYard] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -240,7 +240,7 @@ export default function BinYard(props: Props) {
|
||||||
newBinYard.description = addYardDescription;
|
newBinYard.description = addYardDescription;
|
||||||
newBinYard.owner = user.id();
|
newBinYard.owner = user.id();
|
||||||
binYardAPI
|
binYardAPI
|
||||||
.addBinYard(newBinYard)
|
.addBinYard(newBinYard, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
// loadYards();
|
// loadYards();
|
||||||
let newYards = [...binYards]
|
let newYards = [...binYards]
|
||||||
|
|
@ -271,7 +271,7 @@ export default function BinYard(props: Props) {
|
||||||
newBinYard.name = addYardName;
|
newBinYard.name = addYardName;
|
||||||
newBinYard.description = addYardDescription;
|
newBinYard.description = addYardDescription;
|
||||||
binYardAPI
|
binYardAPI
|
||||||
.updateBinYard(newBinYard.key, newBinYard)
|
.updateBinYard(newBinYard.key, newBinYard, undefined, as)
|
||||||
.then(_resp => {
|
.then(_resp => {
|
||||||
loadYards();
|
loadYards();
|
||||||
openSnackbar("success", "Bin Yard updated");
|
openSnackbar("success", "Bin Yard updated");
|
||||||
|
|
@ -355,7 +355,7 @@ export default function BinYard(props: Props) {
|
||||||
const deleteYard = (index: number) => {
|
const deleteYard = (index: number) => {
|
||||||
let newBinYards = binYards;
|
let newBinYards = binYards;
|
||||||
binYardAPI
|
binYardAPI
|
||||||
.removeBinYard(binYards[index].key)
|
.removeBinYard(binYards[index].key, as)
|
||||||
.then(_resp => {
|
.then(_resp => {
|
||||||
newBinYards.splice(index, 1);
|
newBinYards.splice(index, 1);
|
||||||
if (index + 1 === tab) {
|
if (index + 1 === tab) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import DisplayDrawer from "common/DisplayDrawer";
|
||||||
import MapMarkerSettings from "maps/MapMarkerSettings";
|
import MapMarkerSettings from "maps/MapMarkerSettings";
|
||||||
//import Bins from "pages/Bins";
|
//import Bins from "pages/Bins";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useBinYardAPI, useSnackbar } from "providers";
|
import { useBinYardAPI, useGlobalState, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -18,6 +18,7 @@ interface Props {
|
||||||
|
|
||||||
export default function BinYardDrawer(props: Props) {
|
export default function BinYardDrawer(props: Props) {
|
||||||
const { open, onClose, selectedYard, yards, removeMarker, updateMarker, moveMap } = props;
|
const { open, onClose, selectedYard, yards, removeMarker, updateMarker, moveMap } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [yard, setYard] = useState<pond.BinYardSettings>(pond.BinYardSettings.create());
|
const [yard, setYard] = useState<pond.BinYardSettings>(pond.BinYardSettings.create());
|
||||||
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
||||||
const { openSnack } = useSnackbar();
|
const { openSnack } = useSnackbar();
|
||||||
|
|
@ -96,7 +97,7 @@ export default function BinYardDrawer(props: Props) {
|
||||||
settings.longitude = 0;
|
settings.longitude = 0;
|
||||||
settings.latitude = 0;
|
settings.latitude = 0;
|
||||||
binyardAPI
|
binyardAPI
|
||||||
.updateBinYard(yard.key, settings)
|
.updateBinYard(yard.key, settings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Marker Removed");
|
openSnack("Marker Removed");
|
||||||
//then use the removeMarker prop function to update the markers in the parent map
|
//then use the removeMarker prop function to update the markers in the parent map
|
||||||
|
|
@ -138,7 +139,7 @@ export default function BinYardDrawer(props: Props) {
|
||||||
let settings = yard;
|
let settings = yard;
|
||||||
settings.theme = newTheme;
|
settings.theme = newTheme;
|
||||||
binyardAPI
|
binyardAPI
|
||||||
.updateBinYard(yard.key, settings)
|
.updateBinYard(yard.key, settings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("marker settings updated");
|
openSnack("marker settings updated");
|
||||||
updateMarker(yard.key, settings);
|
updateMarker(yard.key, settings);
|
||||||
|
|
|
||||||
|
|
@ -376,7 +376,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
let yardEntries: Result[] = [];
|
let yardEntries: Result[] = [];
|
||||||
|
|
||||||
binYardAPI
|
binYardAPI
|
||||||
.listBinYards(400, 0, "asc")
|
.listBinYards(400, 0, "asc", undefined, undefined, undefined, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
resp.data.yard.forEach(yard => {
|
resp.data.yard.forEach(yard => {
|
||||||
if (yard.settings) {
|
if (yard.settings) {
|
||||||
|
|
@ -433,7 +433,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
openSnack("Failed to load yard data");
|
openSnack("Failed to load yard data");
|
||||||
});
|
});
|
||||||
}, [binYardAPI, openSnack]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [binYardAPI, openSnack, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const loadBins = useCallback(() => {
|
const loadBins = useCallback(() => {
|
||||||
binAPI
|
binAPI
|
||||||
|
|
@ -931,7 +931,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
yard.longitude = long;
|
yard.longitude = long;
|
||||||
yard.latitude = lat;
|
yard.latitude = lat;
|
||||||
binYardAPI
|
binYardAPI
|
||||||
.updateBinYard(yard.key, yard)
|
.updateBinYard(yard.key, yard, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("BinYard Location Updated");
|
openSnack("BinYard Location Updated");
|
||||||
if (yardOptions.includes(yard)) {
|
if (yardOptions.includes(yard)) {
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,15 @@ import { AxiosResponse } from "axios";
|
||||||
import { useGlobalState } from "providers";
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
export interface IBinYardAPIContext {
|
export interface IBinYardAPIContext {
|
||||||
addBinYard: (bin: pond.BinYardSettings) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
|
addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
|
||||||
updateBinYard: (
|
updateBinYard: (
|
||||||
key: string,
|
key: string,
|
||||||
binYard: pond.BinYardSettings,
|
binYard: pond.BinYardSettings,
|
||||||
asRoot?: true
|
asRoot?: true,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>;
|
) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>;
|
||||||
removeBinYard: (key: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
|
removeBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
|
||||||
getBinYard: (key: string) => Promise<AxiosResponse<pond.BinYard>>;
|
getBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.BinYard>>;
|
||||||
listBinYards: (
|
listBinYards: (
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -22,7 +23,8 @@ export interface IBinYardAPIContext {
|
||||||
orderBy?: string,
|
orderBy?: string,
|
||||||
search?: string,
|
search?: string,
|
||||||
asRoot?: boolean,
|
asRoot?: boolean,
|
||||||
specificUser?: string
|
specificUser?: string,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListBinYardsResponse>>;
|
) => Promise<AxiosResponse<pond.ListBinYardsResponse>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -33,14 +35,14 @@ interface Props {}
|
||||||
export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { get, post, put, del } = useHTTP();
|
const { get, post, put, del } = useHTTP();
|
||||||
const [{ as }] = useGlobalState();
|
//const [{ as }] = useGlobalState();
|
||||||
|
|
||||||
const addBinYard = (binYard: pond.BinYardSettings) => {
|
const addBinYard = (binYard: pond.BinYardSettings, as?: string) => {
|
||||||
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${as}`), binYard);
|
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${as}`), binYard);
|
||||||
return post<pond.AddBinYardResponse>(pondURL("/binyard"), binYard);
|
return post<pond.AddBinYardResponse>(pondURL("/binyard"), binYard);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean) => {
|
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, as?: string) => {
|
||||||
if (as) {
|
if (as) {
|
||||||
if (asRoot) {
|
if (asRoot) {
|
||||||
return put<pond.UpdateBinYardResponse>(
|
return put<pond.UpdateBinYardResponse>(
|
||||||
|
|
@ -58,12 +60,12 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeBinYard = (key: string) => {
|
const removeBinYard = (key: string, as?: string) => {
|
||||||
if (as) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + as));
|
if (as) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + as));
|
||||||
return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key));
|
return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getBinYard = (key: string) => {
|
const getBinYard = (key: string, as?: string) => {
|
||||||
if (as) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + as));
|
if (as) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + as));
|
||||||
return get<pond.BinYard>(pondURL("/binYard/" + key));
|
return get<pond.BinYard>(pondURL("/binYard/" + key));
|
||||||
};
|
};
|
||||||
|
|
@ -75,7 +77,8 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
||||||
orderBy?: string,
|
orderBy?: string,
|
||||||
search?: string,
|
search?: string,
|
||||||
asRoot?: boolean,
|
asRoot?: boolean,
|
||||||
specificUser?: string
|
specificUser?: string,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let asText = "";
|
let asText = "";
|
||||||
if (as) asText = "&as=" + as;
|
if (as) asText = "&as=" + as;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue