Farmbot-Web-App/frontend/regimens/actions.ts

26 lines
774 B
TypeScript
Raw Normal View History

2017-06-29 12:54:02 -06:00
import { Regimen } from "./interfaces";
2018-06-14 12:48:30 -06:00
import { edit } from "../api/crud";
2018-08-01 07:12:15 -06:00
import { isTaggedRegimen } from "../resources/tagged_resources";
2018-05-01 22:14:41 -06:00
import { SelectRegimen } from "./editor/interfaces";
import { Actions } from "../constants";
2018-08-01 07:12:15 -06:00
import { TaggedRegimen } from "farmbot";
2017-06-29 12:54:02 -06:00
export function editRegimen(r: TaggedRegimen | undefined,
update: Partial<Regimen>) {
return (dispatch: Function) => {
r && isTaggedRegimen(r) && dispatch(edit(r, update));
};
2017-06-29 12:54:02 -06:00
}
2018-05-01 22:14:41 -06:00
export function selectRegimen(payload: string): SelectRegimen {
if (payload.startsWith("Regimen")) {
return { type: Actions.SELECT_REGIMEN, payload };
2017-06-29 12:54:02 -06:00
} else {
throw new Error("Not a regimen.");
2017-06-29 12:54:02 -06:00
}
}
2019-04-09 19:45:59 -06:00
export const unselectRegimen = () => ({
type: Actions.SELECT_REGIMEN, payload: undefined
});