update as in site api
This commit is contained in:
parent
1acbfe36b0
commit
59356aad27
6 changed files with 26 additions and 21 deletions
|
|
@ -27,7 +27,7 @@ import { isOffline } from "utils/environment";
|
||||||
import ObjectTeams from "teams/ObjectTeams";
|
import ObjectTeams from "teams/ObjectTeams";
|
||||||
import { siteScope, Site } from "models";
|
import { siteScope, Site } from "models";
|
||||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||||
import { useSiteAPI } from "providers";
|
import { useGlobalState, useSiteAPI } from "providers";
|
||||||
import { useSnackbar } from "hooks";
|
import { useSnackbar } from "hooks";
|
||||||
import GroupSettingsIcon from "@mui/icons-material/Settings";
|
import GroupSettingsIcon from "@mui/icons-material/Settings";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
|
|
@ -63,6 +63,7 @@ interface OpenState {
|
||||||
|
|
||||||
export default function SiteActions(props: Props) {
|
export default function SiteActions(props: Props) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const { site, permissions, refreshCallback } = props;
|
const { site, permissions, refreshCallback } = props;
|
||||||
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
|
||||||
const [siteDialog, setSiteDialog] = useState(false);
|
const [siteDialog, setSiteDialog] = useState(false);
|
||||||
|
|
@ -186,7 +187,7 @@ export default function SiteActions(props: Props) {
|
||||||
newSite.settings.siteName = siteName;
|
newSite.settings.siteName = siteName;
|
||||||
|
|
||||||
siteAPI
|
siteAPI
|
||||||
.updateSite(newSite.key(), newSite.settings)
|
.updateSite(newSite.key(), newSite.settings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Site Updated");
|
openSnack("Site Updated");
|
||||||
closeSiteDialog();
|
closeSiteDialog();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import { Device, Site } from "models";
|
||||||
import { ObjectHeater } from "models/ObjectHeater";
|
import { ObjectHeater } from "models/ObjectHeater";
|
||||||
import ObjectHeaterCard from "objectHeater/ObjectHeaterCard";
|
import ObjectHeaterCard from "objectHeater/ObjectHeaterCard";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useObjectHeaterAPI, useSiteAPI, useSnackbar } from "providers";
|
import { useGlobalState, useObjectHeaterAPI, useSiteAPI, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -34,6 +34,7 @@ export default function SiteDrawer(props: Props) {
|
||||||
updateMarker
|
updateMarker
|
||||||
} = props;
|
} = props;
|
||||||
const [site, setSite] = useState<Site>(Site.create());
|
const [site, setSite] = useState<Site>(Site.create());
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const siteAPI = useSiteAPI();
|
const siteAPI = useSiteAPI();
|
||||||
const objectHeaterAPI = useObjectHeaterAPI();
|
const objectHeaterAPI = useObjectHeaterAPI();
|
||||||
const { openSnack } = useSnackbar();
|
const { openSnack } = useSnackbar();
|
||||||
|
|
@ -206,7 +207,7 @@ export default function SiteDrawer(props: Props) {
|
||||||
let settings = site.settings;
|
let settings = site.settings;
|
||||||
settings.theme = newTheme;
|
settings.theme = newTheme;
|
||||||
siteAPI
|
siteAPI
|
||||||
.updateSite(site.key(), settings)
|
.updateSite(site.key(), settings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("marker settings updated");
|
openSnack("marker settings updated");
|
||||||
updateMarker(site.key(), settings);
|
updateMarker(site.key(), settings);
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ export default function ConstructionMapController(props: Props) {
|
||||||
newSite.settings.latitude = newLat;
|
newSite.settings.latitude = newLat;
|
||||||
|
|
||||||
siteAPI
|
siteAPI
|
||||||
.addSite(newSite.settings)
|
.addSite(newSite.settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Added new Site Location");
|
openSnack("Added new Site Location");
|
||||||
loadSites();
|
loadSites();
|
||||||
|
|
@ -559,7 +559,7 @@ export default function ConstructionMapController(props: Props) {
|
||||||
site.settings.longitude = long;
|
site.settings.longitude = long;
|
||||||
site.settings.latitude = lat;
|
site.settings.latitude = lat;
|
||||||
siteAPI
|
siteAPI
|
||||||
.updateSite(site.key(), site.settings)
|
.updateSite(site.key(), site.settings, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Site location updated");
|
openSnack("Site location updated");
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export default function Site() {
|
||||||
if (!loadingSite) {
|
if (!loadingSite) {
|
||||||
setLoadingSite(true);
|
setLoadingSite(true);
|
||||||
siteAPI
|
siteAPI
|
||||||
.getSitePage(siteKey)
|
.getSitePage(siteKey, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
setSite(ISite.any(resp.data.site));
|
setSite(ISite.any(resp.data.site));
|
||||||
setHeaters(resp.data.heaterData);
|
setHeaters(resp.data.heaterData);
|
||||||
|
|
@ -64,7 +64,7 @@ export default function Site() {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [siteAPI]); //eslint-disable-line react-hooks/exhaustive-deps
|
}, [siteAPI, as]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadSitePageData();
|
loadSitePageData();
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ export default function Sites() {
|
||||||
const updateActive = (active: boolean, site: Site) => {
|
const updateActive = (active: boolean, site: Site) => {
|
||||||
site.settings.active = active;
|
site.settings.active = active;
|
||||||
siteAPI
|
siteAPI
|
||||||
.updateSite(site.key(), site.settings)
|
.updateSite(site.key(), site.settings, undefined, as)
|
||||||
.then(resp => {})
|
.then(resp => {})
|
||||||
.catch(err => {});
|
.catch(err => {});
|
||||||
setSites([...sites]);
|
setSites([...sites]);
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,9 @@ import { or } from "utils";
|
||||||
import { pondURL } from "./pond";
|
import { pondURL } from "./pond";
|
||||||
|
|
||||||
export interface ISiteAPIContext {
|
export interface ISiteAPIContext {
|
||||||
addSite: (site: pond.SiteSettings) => Promise<any>;
|
addSite: (site: pond.SiteSettings, as?: string) => Promise<any>;
|
||||||
getSite: (siteID: string) => Promise<any>;
|
getSite: (siteID: string, as?: string) => Promise<any>;
|
||||||
getSitePage: (siteID: string) => Promise<any>;
|
getSitePage: (siteID: string, as?: string) => Promise<any>;
|
||||||
listSites: (
|
listSites: (
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -32,14 +32,16 @@ export interface ISiteAPIContext {
|
||||||
updateSite: (
|
updateSite: (
|
||||||
key: string,
|
key: string,
|
||||||
site: pond.SiteSettings,
|
site: pond.SiteSettings,
|
||||||
asRoot?: true
|
asRoot?: true,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
||||||
updateLink: (
|
updateLink: (
|
||||||
parentKey: string,
|
parentKey: string,
|
||||||
parentType: string,
|
parentType: string,
|
||||||
objectID: string,
|
objectID: string,
|
||||||
objectType: string,
|
objectType: string,
|
||||||
permissions: string[]
|
permissions: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<any>;
|
) => Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,19 +52,19 @@ interface Props {}
|
||||||
export default function SiteProvider(props: PropsWithChildren<Props>) {
|
export default function SiteProvider(props: PropsWithChildren<Props>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { get, del, post, put } = useHTTP();
|
const { get, del, post, put } = useHTTP();
|
||||||
const [{ as }] = useGlobalState();
|
//const [{ as }] = useGlobalState();
|
||||||
|
|
||||||
const getSitePage = (siteID: string) => {
|
const getSitePage = (siteID: string, as?: string) => {
|
||||||
if (as) return get(pondURL("/sitePage/" + siteID + "?as=" + as));
|
if (as) return get(pondURL("/sitePage/" + siteID + "?as=" + as));
|
||||||
return get(pondURL("/sitePage/" + siteID));
|
return get(pondURL("/sitePage/" + siteID));
|
||||||
};
|
};
|
||||||
|
|
||||||
const addSite = (site: pond.SiteSettings) => {
|
const addSite = (site: pond.SiteSettings, as?: string) => {
|
||||||
if (as) return post(pondURL("/sites?as=" + as), site);
|
if (as) return post(pondURL("/sites?as=" + as), site);
|
||||||
return post(pondURL("/sites"), site);
|
return post(pondURL("/sites"), site);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSite = (siteID: string) => {
|
const getSite = (siteID: string, as?: string) => {
|
||||||
if (as) return get(pondURL("/site/" + siteID + "?as=" + as));
|
if (as) return get(pondURL("/site/" + siteID + "?as=" + as));
|
||||||
return get(pondURL("/site/" + siteID));
|
return get(pondURL("/site/" + siteID));
|
||||||
};
|
};
|
||||||
|
|
@ -121,7 +123,7 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean) => {
|
const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, as?: string) => {
|
||||||
if (as)
|
if (as)
|
||||||
return put<pond.UpdateSiteResponse>(
|
return put<pond.UpdateSiteResponse>(
|
||||||
pondURL(
|
pondURL(
|
||||||
|
|
@ -140,7 +142,8 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
||||||
parentType: string,
|
parentType: string,
|
||||||
objectID: string,
|
objectID: string,
|
||||||
objectType: string,
|
objectType: string,
|
||||||
permissions: string[]
|
permissions: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
if (as)
|
if (as)
|
||||||
return post(pondURL(`/sites/` + parentID + `/link?as=${as}`), {
|
return post(pondURL(`/sites/` + parentID + `/link?as=${as}`), {
|
||||||
|
|
@ -169,7 +172,7 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
||||||
removeSite,
|
removeSite,
|
||||||
updateSite,
|
updateSite,
|
||||||
updateLink,
|
updateLink,
|
||||||
getSitePage
|
getSitePage//
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</SiteAPIContext.Provider>
|
</SiteAPIContext.Provider>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue