2017-07-26 10:01:48 -06:00
|
|
|
import * as React from "react";
|
2019-04-02 13:59:37 -06:00
|
|
|
|
2018-01-20 07:46:44 -07:00
|
|
|
import {
|
|
|
|
Row, Col, BlurableInput, FBSelect, DropDownItem
|
|
|
|
} from "../../ui/index";
|
2017-07-26 10:01:48 -06:00
|
|
|
import { repeatOptions } from "./map_state_to_props_add_edit";
|
|
|
|
import { keyBy } from "lodash";
|
2017-07-26 13:30:22 -06:00
|
|
|
import { FarmEventViewModel } from "./edit_fe_form";
|
2018-01-02 13:16:05 -07:00
|
|
|
import { EventTimePicker } from "./event_time_picker";
|
2018-08-02 15:46:58 -06:00
|
|
|
import { TimeUnit } from "farmbot/dist/resources/api_resources";
|
2019-04-02 13:59:37 -06:00
|
|
|
import { t } from "../../i18next_wrapper";
|
2017-07-26 10:01:48 -06:00
|
|
|
|
|
|
|
type Ev = React.SyntheticEvent<HTMLInputElement>;
|
|
|
|
type Key = keyof FarmEventViewModel;
|
|
|
|
|
|
|
|
export interface RepeatFormProps {
|
|
|
|
/** Should the form controls be grayed out? */
|
|
|
|
disabled: boolean;
|
2017-10-23 06:58:42 -06:00
|
|
|
/** Should the form be shown _at all_? */
|
2017-07-26 10:01:48 -06:00
|
|
|
hidden: boolean;
|
|
|
|
onChange(key: Key, value: string): void;
|
|
|
|
timeUnit: TimeUnit;
|
|
|
|
repeat: string;
|
|
|
|
endDate: string;
|
|
|
|
endTime: string;
|
2018-01-02 13:16:05 -07:00
|
|
|
tzOffset: number;
|
2019-01-13 16:39:26 -07:00
|
|
|
dateError?: string;
|
|
|
|
timeError?: string;
|
2017-07-26 10:01:48 -06:00
|
|
|
}
|
|
|
|
|
2017-08-28 05:49:13 -06:00
|
|
|
const indexKey: keyof DropDownItem = "value";
|
2017-07-26 10:01:48 -06:00
|
|
|
const OPTN_LOOKUP = keyBy(repeatOptions, indexKey);
|
|
|
|
|
|
|
|
export function FarmEventRepeatForm(props: RepeatFormProps) {
|
2017-08-28 05:49:13 -06:00
|
|
|
const { disabled, onChange, repeat, endDate, endTime, timeUnit } = props;
|
|
|
|
const changeHandler =
|
2017-07-26 10:01:48 -06:00
|
|
|
(key: Key) => (e: Ev) => onChange(key, e.currentTarget.value);
|
2018-12-30 11:57:22 -07:00
|
|
|
return props.hidden ? <div /> : <div>
|
|
|
|
<label>
|
|
|
|
{t("Every")}
|
|
|
|
</label>
|
|
|
|
<Row>
|
|
|
|
<Col xs={4}>
|
|
|
|
<BlurableInput
|
|
|
|
disabled={disabled}
|
|
|
|
placeholder="(Number)"
|
|
|
|
type="number"
|
|
|
|
className="add-event-repeat-frequency"
|
|
|
|
name="repeat"
|
|
|
|
value={repeat}
|
2019-01-13 16:39:26 -07:00
|
|
|
onCommit={changeHandler("repeat")}
|
|
|
|
min={1} />
|
2018-12-30 11:57:22 -07:00
|
|
|
</Col>
|
|
|
|
<Col xs={8}>
|
|
|
|
<FBSelect
|
|
|
|
list={repeatOptions}
|
|
|
|
onChange={(e) => onChange("timeUnit", "" + e.value)}
|
|
|
|
selectedItem={OPTN_LOOKUP[timeUnit] || OPTN_LOOKUP["daily"]} />
|
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
<label>
|
|
|
|
{t("Until")}
|
|
|
|
</label>
|
|
|
|
<Row>
|
|
|
|
<Col xs={6}>
|
|
|
|
<BlurableInput
|
|
|
|
disabled={disabled}
|
|
|
|
type="date"
|
|
|
|
className="add-event-end-date"
|
|
|
|
name="endDate"
|
|
|
|
value={endDate}
|
2019-01-13 16:39:26 -07:00
|
|
|
onCommit={changeHandler("endDate")}
|
|
|
|
error={props.dateError} />
|
2018-12-30 11:57:22 -07:00
|
|
|
</Col>
|
|
|
|
<Col xs={6}>
|
|
|
|
<EventTimePicker
|
|
|
|
disabled={disabled}
|
|
|
|
className="add-event-end-time"
|
|
|
|
name="endTime"
|
|
|
|
tzOffset={props.tzOffset}
|
|
|
|
value={endTime}
|
2019-01-13 16:39:26 -07:00
|
|
|
onCommit={changeHandler("endTime")}
|
|
|
|
error={props.timeError} />
|
2018-12-30 11:57:22 -07:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
</div>;
|
2017-07-26 10:01:48 -06:00
|
|
|
}
|