update as in site api

This commit is contained in:
csawatzky 2025-04-21 14:26:59 -06:00
parent 1acbfe36b0
commit 59356aad27
6 changed files with 26 additions and 21 deletions

View file

@ -27,7 +27,7 @@ import { isOffline } from "utils/environment";
import ObjectTeams from "teams/ObjectTeams";
import { siteScope, Site } from "models";
import ResponsiveDialog from "common/ResponsiveDialog";
import { useSiteAPI } from "providers";
import { useGlobalState, useSiteAPI } from "providers";
import { useSnackbar } from "hooks";
import GroupSettingsIcon from "@mui/icons-material/Settings";
import { makeStyles } from "@mui/styles";
@ -63,6 +63,7 @@ interface OpenState {
export default function SiteActions(props: Props) {
const classes = useStyles();
const [{as}] = useGlobalState();
const { site, permissions, refreshCallback } = props;
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [siteDialog, setSiteDialog] = useState(false);
@ -186,7 +187,7 @@ export default function SiteActions(props: Props) {
newSite.settings.siteName = siteName;
siteAPI
.updateSite(newSite.key(), newSite.settings)
.updateSite(newSite.key(), newSite.settings, undefined, as)
.then(resp => {
openSnack("Site Updated");
closeSiteDialog();

View file

@ -6,7 +6,7 @@ import { Device, Site } from "models";
import { ObjectHeater } from "models/ObjectHeater";
import ObjectHeaterCard from "objectHeater/ObjectHeaterCard";
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";
interface Props {
@ -34,6 +34,7 @@ export default function SiteDrawer(props: Props) {
updateMarker
} = props;
const [site, setSite] = useState<Site>(Site.create());
const [{as}] = useGlobalState();
const siteAPI = useSiteAPI();
const objectHeaterAPI = useObjectHeaterAPI();
const { openSnack } = useSnackbar();
@ -206,7 +207,7 @@ export default function SiteDrawer(props: Props) {
let settings = site.settings;
settings.theme = newTheme;
siteAPI
.updateSite(site.key(), settings)
.updateSite(site.key(), settings, undefined, as)
.then(resp => {
openSnack("marker settings updated");
updateMarker(site.key(), settings);

View file

@ -120,7 +120,7 @@ export default function ConstructionMapController(props: Props) {
newSite.settings.latitude = newLat;
siteAPI
.addSite(newSite.settings)
.addSite(newSite.settings, as)
.then(resp => {
openSnack("Added new Site Location");
loadSites();
@ -559,7 +559,7 @@ export default function ConstructionMapController(props: Props) {
site.settings.longitude = long;
site.settings.latitude = lat;
siteAPI
.updateSite(site.key(), site.settings)
.updateSite(site.key(), site.settings, undefined, as)
.then(resp => {
openSnack("Site location updated");
})

View file

@ -54,7 +54,7 @@ export default function Site() {
if (!loadingSite) {
setLoadingSite(true);
siteAPI
.getSitePage(siteKey)
.getSitePage(siteKey, as)
.then(resp => {
setSite(ISite.any(resp.data.site));
setHeaters(resp.data.heaterData);
@ -64,7 +64,7 @@ export default function Site() {
console.log(err);
});
}
}, [siteAPI]); //eslint-disable-line react-hooks/exhaustive-deps
}, [siteAPI, as]); //eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
loadSitePageData();

View file

@ -101,7 +101,7 @@ export default function Sites() {
const updateActive = (active: boolean, site: Site) => {
site.settings.active = active;
siteAPI
.updateSite(site.key(), site.settings)
.updateSite(site.key(), site.settings, undefined, as)
.then(resp => {})
.catch(err => {});
setSites([...sites]);

View file

@ -7,9 +7,9 @@ import { or } from "utils";
import { pondURL } from "./pond";
export interface ISiteAPIContext {
addSite: (site: pond.SiteSettings) => Promise<any>;
getSite: (siteID: string) => Promise<any>;
getSitePage: (siteID: string) => Promise<any>;
addSite: (site: pond.SiteSettings, as?: string) => Promise<any>;
getSite: (siteID: string, as?: string) => Promise<any>;
getSitePage: (siteID: string, as?: string) => Promise<any>;
listSites: (
limit: number,
offset: number,
@ -32,14 +32,16 @@ export interface ISiteAPIContext {
updateSite: (
key: string,
site: pond.SiteSettings,
asRoot?: true
asRoot?: true,
as?: string
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
updateLink: (
parentKey: string,
parentType: string,
objectID: string,
objectType: string,
permissions: string[]
permissions: string[],
as?: string
) => Promise<any>;
}
@ -50,19 +52,19 @@ interface Props {}
export default function SiteProvider(props: PropsWithChildren<Props>) {
const { children } = props;
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));
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);
return post(pondURL("/sites"), site);
};
const getSite = (siteID: string) => {
const getSite = (siteID: string, as?: string) => {
if (as) return get(pondURL("/site/" + siteID + "?as=" + as));
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)
return put<pond.UpdateSiteResponse>(
pondURL(
@ -140,7 +142,8 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
parentType: string,
objectID: string,
objectType: string,
permissions: string[]
permissions: string[],
as?: string
) => {
if (as)
return post(pondURL(`/sites/` + parentID + `/link?as=${as}`), {
@ -169,7 +172,7 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
removeSite,
updateSite,
updateLink,
getSitePage
getSitePage//
}}>
{children}
</SiteAPIContext.Provider>