Skip to content

Commit

Permalink
validate that PA messages specify at least one day (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
panentheos authored Nov 25, 2024
1 parent 2593fb5 commit 0a070dd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions assets/js/components/Dashboard/DaysPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from "react";
import { Col, Dropdown, Form, Row } from "react-bootstrap";
import fp from "lodash/fp";
import cx from "classnames";

enum DayItem {
All = "All days",
Expand Down Expand Up @@ -38,9 +39,10 @@ const DAY_MAPPINGS = [
interface Props {
days: number[];
onChangeDays: (days: number[]) => void;
error: string | null;
}

const DaysPicker = ({ days, onChangeDays }: Props) => {
const DaysPicker = ({ days, onChangeDays, error }: Props) => {
const [dayLabel, setDayLabel] = useState(
fp.find(
({ value }) => fp.isEqual(value, fp.sortBy(fp.identity, days)),
Expand All @@ -53,7 +55,11 @@ const DaysPicker = ({ days, onChangeDays }: Props) => {
<Form.Label className="label body--regular" htmlFor="days-picker">
Days
</Form.Label>
<Row md={1} lg="auto" className="align-items-center">
<Row
md={1}
lg="auto"
className={cx("align-items-center", { "is-invalid": !!error })}
>
<Col>
<Dropdown
onSelect={(eventKey) => {
Expand Down Expand Up @@ -108,6 +114,7 @@ const DaysPicker = ({ days, onChangeDays }: Props) => {
</Col>
)}
</Row>
<Form.Control.Feedback type="invalid">{error}</Form.Control.Feedback>
</Form.Group>
);
};
Expand Down
9 changes: 8 additions & 1 deletion assets/js/components/Dashboard/PaMessageForm/MainForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ const MainForm = ({

if (
form.checkValidity() === false ||
days.length === 0 ||
signIds.length === 0 ||
audioState !== AudioPreview.Reviewed
) {
Expand Down Expand Up @@ -288,7 +289,13 @@ const MainForm = ({
</Form.Group>
</Row>
<Row className="days">
<DaysPicker days={days} onChangeDays={setDays} />
<DaysPicker
days={days}
onChangeDays={setDays}
error={
validated && !days.length ? "Select at least one day" : null
}
/>
</Row>
<Row md="auto">
<Col>
Expand Down
1 change: 1 addition & 0 deletions lib/screenplay/pa_messages/pa_message.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ defmodule Screenplay.PaMessages.PaMessage do
])
|> validate_length(:sign_ids, min: 1)
|> validate_subset(:days_of_week, 1..7)
|> validate_length(:days_of_week, min: 1)
|> validate_number(:interval_in_minutes, greater_than: 0)
|> validate_inclusion(:priority, 1..4)
|> validate_start_date()
Expand Down

0 comments on commit 0a070dd

Please sign in to comment.