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);
|
||||
} else {
|
||||
binYardAPI
|
||||
.listBinYards(350, 0, "desc", as ? as : userID)
|
||||
.listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
let data = resp.data.yard ? resp.data.yard : [];
|
||||
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 [yardPermissions, setYardPermissions] = useState<Dictionary<pond.Permission[]>>({});
|
||||
const [searchSelected, setSearchSelected] = useState(false);
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const [addingYard, setAddingYard] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
|
|
@ -240,7 +240,7 @@ export default function BinYard(props: Props) {
|
|||
newBinYard.description = addYardDescription;
|
||||
newBinYard.owner = user.id();
|
||||
binYardAPI
|
||||
.addBinYard(newBinYard)
|
||||
.addBinYard(newBinYard, as)
|
||||
.then(resp => {
|
||||
// loadYards();
|
||||
let newYards = [...binYards]
|
||||
|
|
@ -271,7 +271,7 @@ export default function BinYard(props: Props) {
|
|||
newBinYard.name = addYardName;
|
||||
newBinYard.description = addYardDescription;
|
||||
binYardAPI
|
||||
.updateBinYard(newBinYard.key, newBinYard)
|
||||
.updateBinYard(newBinYard.key, newBinYard, undefined, as)
|
||||
.then(_resp => {
|
||||
loadYards();
|
||||
openSnackbar("success", "Bin Yard updated");
|
||||
|
|
@ -355,7 +355,7 @@ export default function BinYard(props: Props) {
|
|||
const deleteYard = (index: number) => {
|
||||
let newBinYards = binYards;
|
||||
binYardAPI
|
||||
.removeBinYard(binYards[index].key)
|
||||
.removeBinYard(binYards[index].key, as)
|
||||
.then(_resp => {
|
||||
newBinYards.splice(index, 1);
|
||||
if (index + 1 === tab) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import DisplayDrawer from "common/DisplayDrawer";
|
|||
import MapMarkerSettings from "maps/MapMarkerSettings";
|
||||
//import Bins from "pages/Bins";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useBinYardAPI, useSnackbar } from "providers";
|
||||
import { useBinYardAPI, useGlobalState, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -18,6 +18,7 @@ interface Props {
|
|||
|
||||
export default function BinYardDrawer(props: Props) {
|
||||
const { open, onClose, selectedYard, yards, removeMarker, updateMarker, moveMap } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [yard, setYard] = useState<pond.BinYardSettings>(pond.BinYardSettings.create());
|
||||
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
||||
const { openSnack } = useSnackbar();
|
||||
|
|
@ -96,7 +97,7 @@ export default function BinYardDrawer(props: Props) {
|
|||
settings.longitude = 0;
|
||||
settings.latitude = 0;
|
||||
binyardAPI
|
||||
.updateBinYard(yard.key, settings)
|
||||
.updateBinYard(yard.key, settings, undefined, as)
|
||||
.then(resp => {
|
||||
openSnack("Marker Removed");
|
||||
//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;
|
||||
settings.theme = newTheme;
|
||||
binyardAPI
|
||||
.updateBinYard(yard.key, settings)
|
||||
.updateBinYard(yard.key, settings, undefined, as)
|
||||
.then(resp => {
|
||||
openSnack("marker settings updated");
|
||||
updateMarker(yard.key, settings);
|
||||
|
|
|
|||
|
|
@ -376,7 +376,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
|||
let yardEntries: Result[] = [];
|
||||
|
||||
binYardAPI
|
||||
.listBinYards(400, 0, "asc")
|
||||
.listBinYards(400, 0, "asc", undefined, undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
resp.data.yard.forEach(yard => {
|
||||
if (yard.settings) {
|
||||
|
|
@ -433,7 +433,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
|||
.catch(() => {
|
||||
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(() => {
|
||||
binAPI
|
||||
|
|
@ -931,7 +931,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
|||
yard.longitude = long;
|
||||
yard.latitude = lat;
|
||||
binYardAPI
|
||||
.updateBinYard(yard.key, yard)
|
||||
.updateBinYard(yard.key, yard, undefined, as)
|
||||
.then(resp => {
|
||||
openSnack("BinYard Location Updated");
|
||||
if (yardOptions.includes(yard)) {
|
||||
|
|
|
|||
|
|
@ -7,14 +7,15 @@ import { AxiosResponse } from "axios";
|
|||
import { useGlobalState } from "providers";
|
||||
|
||||
export interface IBinYardAPIContext {
|
||||
addBinYard: (bin: pond.BinYardSettings) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
|
||||
addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
|
||||
updateBinYard: (
|
||||
key: string,
|
||||
binYard: pond.BinYardSettings,
|
||||
asRoot?: true
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>;
|
||||
removeBinYard: (key: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
|
||||
getBinYard: (key: string) => Promise<AxiosResponse<pond.BinYard>>;
|
||||
removeBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
|
||||
getBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.BinYard>>;
|
||||
listBinYards: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -22,7 +23,8 @@ export interface IBinYardAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
specificUser?: string
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListBinYardsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -33,14 +35,14 @@ interface Props {}
|
|||
export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
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);
|
||||
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 (asRoot) {
|
||||
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));
|
||||
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));
|
||||
return get<pond.BinYard>(pondURL("/binYard/" + key));
|
||||
};
|
||||
|
|
@ -75,7 +77,8 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
specificUser?: string
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
) => {
|
||||
let asText = "";
|
||||
if (as) asText = "&as=" + as;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue