diff --git a/src/harvestPlan/DuplicateHarvestPlan.tsx b/src/harvestPlan/DuplicateHarvestPlan.tsx index 505673d..5f083af 100644 --- a/src/harvestPlan/DuplicateHarvestPlan.tsx +++ b/src/harvestPlan/DuplicateHarvestPlan.tsx @@ -48,7 +48,7 @@ export default function DuplicateHarvestPlan(props: Props) { if (title !== "") { planSettings.title = title; } - harvestPlanAPI.addHarvestPlan(planSettings).then(resp => { + harvestPlanAPI.addHarvestPlan(planSettings, as).then(resp => { let tasks = planTasks; tasks.forEach(task => { task.settings.objectKey = resp.data.harvestPlan; diff --git a/src/harvestPlan/HarvestSettings.tsx b/src/harvestPlan/HarvestSettings.tsx index a736217..4873146 100644 --- a/src/harvestPlan/HarvestSettings.tsx +++ b/src/harvestPlan/HarvestSettings.tsx @@ -307,7 +307,7 @@ export default function HarvestSettings(props: Props) { }); setNewPlan(HarvestPlan.create(pond.HarvestPlan.fromObject({ settings: newPlanSettings }))); - harvestPlanAPI.addHarvestPlan(newPlanSettings).then(resp => { + harvestPlanAPI.addHarvestPlan(newPlanSettings, as).then(resp => { setPlanKey(resp.data.harvestPlan); openSnack("Plan Created"); }); @@ -373,7 +373,7 @@ export default function HarvestSettings(props: Props) { tempPlan.settings.fallEquipment = fallEqCost; if (planKey) { harvestPlanAPI - .updateHarvestPlan(planKey, tempPlan.settings) + .updateHarvestPlan(planKey, tempPlan.settings, undefined, as) .then(resp => openSnack("Plan Updated")); } closeDialog(true, tempPlan); @@ -381,7 +381,7 @@ export default function HarvestSettings(props: Props) { const deletePlan = () => { if (planKey) { - harvestPlanAPI.removeHarvestPlan(planKey).then(resp => { + harvestPlanAPI.removeHarvestPlan(planKey, as).then(resp => { openSnack("Plan Deleted"); }); } diff --git a/src/providers/pond/harvestPlanAPI.tsx b/src/providers/pond/harvestPlanAPI.tsx index 492642a..605283e 100644 --- a/src/providers/pond/harvestPlanAPI.tsx +++ b/src/providers/pond/harvestPlanAPI.tsx @@ -7,8 +7,8 @@ import { or } from "utils"; import { pondURL } from "./pond"; export interface IHarvestPlanAPIContext { - addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings) => Promise; - getHarvestPlan: (harvestPlanId: string) => Promise; + addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, as?: string) => Promise; + getHarvestPlan: (harvestPlanId: string, as?: string) => Promise; listHarvestPlans: ( limit: number, offset: number, @@ -24,12 +24,14 @@ export interface IHarvestPlanAPIContext { offset: number ) => Promise>; removeHarvestPlan: ( - harvestPlanId: string + harvestPlanId: string, + as?: string ) => Promise>; updateHarvestPlan: ( key: string, harvestPlan: pond.HarvestPlanSettings, - asRoot?: true + asRoot?: true, + as?: string ) => Promise>; } @@ -42,19 +44,19 @@ interface Props {} export default function HarvestPlanProvider(props: PropsWithChildren) { const { children } = props; const { get, del, post, put } = useHTTP(); - const [{ as }] = useGlobalState(); + //const [{ as }] = useGlobalState(); - const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings) => { + const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, as?: string) => { if (as) return post(pondURL("/harvestPlans?as=" + as), harvestPlan); return post(pondURL("/harvestPlans"), harvestPlan); }; - const getHarvestPlan = (harvestPlanId: string) => { + const getHarvestPlan = (harvestPlanId: string, as?: string) => { if (as) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + as)); return get(pondURL("/harvestPlans/" + harvestPlanId)); }; - const removeHarvestPlan = (key: string) => { + const removeHarvestPlan = (key: string, as?: string) => { if (as) return del(pondURL("/harvestPlans/" + key + "?as=" + as)); return del(pondURL("/harvestPlans/" + key)); @@ -94,7 +96,8 @@ export default function HarvestPlanProvider(props: PropsWithChildren) { const updateHarvestPlan = ( key: string, harvestPlan: pond.HarvestPlanSettings, - asRoot?: boolean + asRoot?: boolean, + as?: string ) => { if (as) return put(