import React from "react"; import { t } from "../i18next_wrapper"; import { AlertCardProps, AlertCardTemplateProps, FirmwareMissingProps, SeedDataMissingProps, SeedDataMissingState, TourNotTakenProps, CommonAlertCardProps, DismissAlertProps, Bulletin, BulletinAlertComponentState } from "./interfaces"; import { formatLogTime } from "../logs"; import { FlashFirmwareBtn } from "../devices/components/fbos_settings/firmware_hardware_status"; import { DropDownItem, Row, Col, FBSelect, docLink, Markdown } from "../ui"; import { Content } from "../constants"; import { TourList } from "../help/tour_list"; import { splitProblemTag } from "./alerts"; import { destroy } from "../api/crud"; import { isFwHardwareValue, FIRMWARE_CHOICES_DDI, getFirmwareChoices } from "../devices/components/firmware_hardware_support"; import { updateConfig } from "../devices/actions"; import { fetchBulletinContent, seedAccount } from "./actions"; import { startCase } from "lodash"; import { DevSettings } from "../account/dev/dev_support"; import { Session } from "../session"; export const AlertCard = (props: AlertCardProps) => { const { alert, timeSettings, findApiAlertById, dispatch } = props; const commonProps = { alert, timeSettings, findApiAlertById, dispatch }; switch (alert.problem_tag) { case "farmbot_os.firmware.missing": return ; case "api.seed_data.missing": return ; case "api.tour.not_taken": return ; case "api.user.not_welcomed": return ; case "api.documentation.unread": return ; case "api.bulletin.unread": return ; case "api.demo_account.in_use": return ; default: return ; } }; const dismissAlert = (props: DismissAlertProps) => () => (props.id && props.findApiAlertById && props.dispatch) && props.dispatch(destroy(props.findApiAlertById(props.id))); const timeOk = (timestamp: number) => timestamp > 1550000000; const AlertCardTemplate = (props: AlertCardTemplateProps) => { const { alert, findApiAlertById, dispatch } = props; return

{t(props.title)}

{timeOk(alert.created_at) &&

{formatLogTime(alert.created_at, props.timeSettings)}

} {alert.id && }
{t(props.message)} {props.children}
; }; const ICON_LOOKUP: { [x: string]: string } = { "info": "info-circle", "success": "check-square", "warn": "exclamation-triangle", }; class BulletinAlert extends React.Component { state: BulletinAlertComponentState = { bulletin: undefined, no_content: false }; componentDidMount() { fetchBulletinContent(this.props.alert.slug) .then(bulletin => bulletin ? this.setState({ bulletin }) : this.setState({ no_content: true })); } get bulletinData(): Bulletin { return this.state.bulletin || { content: this.state.no_content ? t("Unable to load content.") : t("Loading..."), href: undefined, href_label: undefined, type: "info", slug: this.props.alert.slug, title: undefined, }; } render() { const { content, href, href_label, type, title } = this.bulletinData; return {href && {href_label || t("Find out more")} } ; } } const UnknownAlert = (props: CommonAlertCardProps) => { const { problem_tag, slug, priority } = props.alert; const { author, noun, verb } = splitProblemTag(problem_tag); return ; }; const FirmwareChoiceTable = () =>
{t("FarmBot Version")} {t("Electronics Board")} {t("Firmware Name")}
{"Genesis v1.2"} {"RAMPS"} {FIRMWARE_CHOICES_DDI["arduino"].label}
{"Genesis v1.3"} {"Farmduino"} {FIRMWARE_CHOICES_DDI["farmduino"].label}
{"Genesis v1.4"} {"Farmduino"} {FIRMWARE_CHOICES_DDI["farmduino_k14"].label}
{"Genesis v1.5"} {"Farmduino"} {FIRMWARE_CHOICES_DDI["farmduino_k15"].label}
{"Express v1.0"} {"Farmduino"} {FIRMWARE_CHOICES_DDI["express_k10"].label}
; export const changeFirmwareHardware = (dispatch: Function | undefined) => (ddi: DropDownItem) => { if (isFwHardwareValue(ddi.value)) { dispatch?.(updateConfig({ firmware_hardware: ddi.value })); } }; const FirmwareMissing = (props: FirmwareMissingProps) => ; const SEED_DATA_OPTIONS = (): DropDownItem[] => [ { label: "Genesis v1.2", value: "genesis_1.2" }, { label: "Genesis v1.3", value: "genesis_1.3" }, { label: "Genesis v1.4", value: "genesis_1.4" }, { label: "Genesis v1.4 XL", value: "genesis_xl_1.4" }, ...(DevSettings.futureFeaturesEnabled() ? [ { label: "Express v1.0", value: "express_1.0" }, { label: "Express v1.0 XL", value: "express_xl_1.0" }, ] : []), { label: "Custom Bot", value: "none" }, ]; const SEED_DATA_OPTIONS_DDI: Record = {}; SEED_DATA_OPTIONS().map(ddi => SEED_DATA_OPTIONS_DDI[ddi.value] = ddi); class SeedDataMissing extends React.Component { state: SeedDataMissingState = { selection: "" }; get dismiss() { const { alert, findApiAlertById, dispatch } = this.props; return dismissAlert({ id: alert.id, findApiAlertById, dispatch }); } render() { return ; } } const TourNotTaken = (props: TourNotTakenProps) =>

{t("Choose a tour to begin")}:

; const UserNotWelcomed = (props: CommonAlertCardProps) =>

{t("You're currently viewing the")} {t("Message Center")}. {" "}{t(Content.MESSAGE_CENTER_WELCOME)}

{t(Content.MESSAGE_DISMISS)}

; const DocumentationUnread = (props: CommonAlertCardProps) =>

{t("Head over to")}   {t("software.farm.bot")}  {t("to get started")}.

{t("Read the docs")}
; const DemoAccount = (props: CommonAlertCardProps) =>

{t("Please note:")}  {t(Content.DEMO_NOTE)}

{t(Content.MAKE_A_REAL_ACCOUNT)}  Session.clear()} title={"my.farm.bot"}> {"my.farm.bot"} .

Session.clear()} title={t("Make a real account")}> {t("Make a real account")}
;