From 0a070ddfc610484f863be9daba75703768738da2 Mon Sep 17 00:00:00 2001 From: Brett Heath-Wlaz Date: Mon, 25 Nov 2024 11:19:00 -0500 Subject: [PATCH] validate that PA messages specify at least one day (#569) --- assets/js/components/Dashboard/DaysPicker.tsx | 11 +++++++++-- .../components/Dashboard/PaMessageForm/MainForm.tsx | 9 ++++++++- lib/screenplay/pa_messages/pa_message.ex | 1 + 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/assets/js/components/Dashboard/DaysPicker.tsx b/assets/js/components/Dashboard/DaysPicker.tsx index c2206040..af667e4c 100644 --- a/assets/js/components/Dashboard/DaysPicker.tsx +++ b/assets/js/components/Dashboard/DaysPicker.tsx @@ -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", @@ -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)), @@ -53,7 +55,11 @@ const DaysPicker = ({ days, onChangeDays }: Props) => { Days - + { @@ -108,6 +114,7 @@ const DaysPicker = ({ days, onChangeDays }: Props) => { )} + {error} ); }; diff --git a/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx b/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx index 82881fd6..6000057d 100644 --- a/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx +++ b/assets/js/components/Dashboard/PaMessageForm/MainForm.tsx @@ -125,6 +125,7 @@ const MainForm = ({ if ( form.checkValidity() === false || + days.length === 0 || signIds.length === 0 || audioState !== AudioPreview.Reviewed ) { @@ -288,7 +289,13 @@ const MainForm = ({ - + diff --git a/lib/screenplay/pa_messages/pa_message.ex b/lib/screenplay/pa_messages/pa_message.ex index a338aff7..3a90f986 100644 --- a/lib/screenplay/pa_messages/pa_message.ex +++ b/lib/screenplay/pa_messages/pa_message.ex @@ -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()