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

25 lines
864 B
TypeScript
Raw Permalink Normal View History

2019-04-19 16:48:43 -06:00
import axios from "axios";
import { API } from "../api";
import { Bulletin } from "./interfaces";
2019-05-03 13:51:02 -06:00
import { DropDownItem } from "../ui";
import { UnsafeError } from "../interfaces";
import { toastErrors } from "../toast_errors";
2019-06-24 15:39:49 -06:00
import { info } from "../toast/toast";
2019-05-03 13:51:02 -06:00
import { t } from "../i18next_wrapper";
2019-04-19 16:48:43 -06:00
2019-04-23 12:44:10 -06:00
const url = (slug: string) => `${API.current.globalBulletinPath}${slug}`;
2019-04-19 16:48:43 -06:00
2019-04-23 12:44:10 -06:00
export const fetchBulletinContent =
(slug: string): Promise<Bulletin | undefined> => {
return axios
.get<Bulletin>(url(slug))
.then(response => Promise.resolve(response.data));
};
2019-05-03 13:51:02 -06:00
export const seedAccount = (onClick: () => void) => (ddi: DropDownItem) =>
axios.post(API.current.accountSeedPath, { product_line: ddi.value })
.then(() => {
info(t("Seeding in progress."), "Busy");
onClick();
}, (err: UnsafeError) => toastErrors({ err }));