From 59356aad27777338b41616b85f52b0cee00b85be Mon Sep 17 00:00:00 2001 From: csawatzky Date: Mon, 21 Apr 2025 14:26:59 -0600 Subject: [PATCH] update as in site api --- src/jobsite/SiteActions.tsx | 5 ++-- src/maps/mapDrawers/SiteDrawer.tsx | 5 ++-- .../ConstructionMapController.tsx | 4 +-- src/pages/Site.tsx | 4 +-- src/pages/Sites.tsx | 2 +- src/providers/pond/siteAPI.tsx | 27 ++++++++++--------- 6 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/jobsite/SiteActions.tsx b/src/jobsite/SiteActions.tsx index 0dd8473..47db103 100644 --- a/src/jobsite/SiteActions.tsx +++ b/src/jobsite/SiteActions.tsx @@ -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); 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(); diff --git a/src/maps/mapDrawers/SiteDrawer.tsx b/src/maps/mapDrawers/SiteDrawer.tsx index d28a017..e2578ba 100644 --- a/src/maps/mapDrawers/SiteDrawer.tsx +++ b/src/maps/mapDrawers/SiteDrawer.tsx @@ -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.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); diff --git a/src/maps/mapObjectControllers/ConstructionMapController.tsx b/src/maps/mapObjectControllers/ConstructionMapController.tsx index 68e27ba..4e7884d 100644 --- a/src/maps/mapObjectControllers/ConstructionMapController.tsx +++ b/src/maps/mapObjectControllers/ConstructionMapController.tsx @@ -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"); }) diff --git a/src/pages/Site.tsx b/src/pages/Site.tsx index 842e977..5832fc9 100644 --- a/src/pages/Site.tsx +++ b/src/pages/Site.tsx @@ -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(); diff --git a/src/pages/Sites.tsx b/src/pages/Sites.tsx index 69784ac..e749643 100644 --- a/src/pages/Sites.tsx +++ b/src/pages/Sites.tsx @@ -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]); diff --git a/src/providers/pond/siteAPI.tsx b/src/providers/pond/siteAPI.tsx index 133d888..5f6ac21 100644 --- a/src/providers/pond/siteAPI.tsx +++ b/src/providers/pond/siteAPI.tsx @@ -7,9 +7,9 @@ import { or } from "utils"; import { pondURL } from "./pond"; export interface ISiteAPIContext { - addSite: (site: pond.SiteSettings) => Promise; - getSite: (siteID: string) => Promise; - getSitePage: (siteID: string) => Promise; + addSite: (site: pond.SiteSettings, as?: string) => Promise; + getSite: (siteID: string, as?: string) => Promise; + getSitePage: (siteID: string, as?: string) => Promise; 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>; updateLink: ( parentKey: string, parentType: string, objectID: string, objectType: string, - permissions: string[] + permissions: string[], + as?: string ) => Promise; } @@ -50,19 +52,19 @@ interface Props {} export default function SiteProvider(props: PropsWithChildren) { 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) { ); }; - const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean) => { + const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, as?: string) => { if (as) return put( pondURL( @@ -140,7 +142,8 @@ export default function SiteProvider(props: PropsWithChildren) { 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) { removeSite, updateSite, updateLink, - getSitePage + getSitePage// }}> {children}