Skip to content

Commit

Permalink
PA message flow read only (#595)
Browse files Browse the repository at this point in the history
* Move document query to a helper method

* Pa Messages page

* Read-only for main form

* readonly select stations and zones

* remove commented out css
  • Loading branch information
PaulJKim authored Jan 27, 2025
1 parent 7a125e4 commit fd8fdd5
Show file tree
Hide file tree
Showing 22 changed files with 291 additions and 133 deletions.
4 changes: 4 additions & 0 deletions assets/css/dashboard/new-pa-message/new-pa-message.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
}
}

.close-button {
margin-right: 0;
}

// Hide the default Bootstrap validation icons.
.form-control.is-invalid {
background-image: none;
Expand Down
12 changes: 12 additions & 0 deletions assets/css/dashboard/new-pa-message/select-zones-page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@
.btn {
padding: 6px 12px;
height: fit-content;

&:disabled:not(.button-active) {
background-color: inherit;
border-color: inherit;
color: $text-secondary;
}
}
}
}
Expand Down Expand Up @@ -222,6 +228,12 @@
.btn {
padding: 6px 12px;
height: fit-content;

&:disabled:not(.button-active) {
background-color: inherit;
border-color: inherit;
color: $text-secondary;
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions assets/css/pa-messages.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
--bs-body-bg: #{$dark-bg};
--bs-body-color: #{$text-secondary};
--bs-border-color: #{$border-primary};

&:disabled {
border-color: $bg-elevation-5;
background-color: $bg-elevation-4;
}

&[type="number"] {
-moz-appearance: textfield; /* Firefox */
appearance: textfield;
Expand Down
1 change: 1 addition & 0 deletions assets/css/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ $text-error: #ffb4ab;

$bg-elevation-3: #1e2933;
$bg-elevation-4: #2b3741;
$bg-elevation-5: #2e3f4d;

$button-secondary-outline-bg: #c1c7ce;
$button-secondary-outline-hover-bg: #c1c7ce14;
Expand Down
4 changes: 3 additions & 1 deletion assets/js/components/Dashboard/DaysPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ interface Props {
days: number[];
onChangeDays: (days: number[]) => void;
error: string | null;
disabled?: boolean;
}

const DaysPicker = ({ days, onChangeDays, error }: Props) => {
const DaysPicker = ({ days, onChangeDays, error, disabled = false }: Props) => {
const [dayLabel, setDayLabel] = useState(
fp.find(
({ value }) => fp.isEqual(value, fp.sortBy(fp.identity, days)),
Expand Down Expand Up @@ -81,6 +82,7 @@ const DaysPicker = ({ days, onChangeDays, error }: Props) => {
<Dropdown.Toggle
id="days-picker"
className="w-100 d-flex align-items-center justify-content-between"
disabled={disabled}
>
{dayLabel}
</Dropdown.Toggle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { updateExistingPaMessage } from "Utils/api";
import { Alert } from "Models/alert";
import { AudioPreview } from "Components/PaMessageForm/types";
import { STATIC_TEMPLATES } from "Components/PaMessageForm/StaticTemplatePage";
import { isPaMessageAdmin } from "Utils/auth";

const useAlert = (id: string | null | undefined) => {
const { data: alerts, isLoading } = useSWR<Array<Alert>>(
Expand Down Expand Up @@ -94,11 +95,12 @@ const EditPaMessage = ({ paMessage, alert }: Props) => {
const navigate = useNavigate();
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [errors, setErrors] = useState<string[]>([]);
const isReadOnly = !isPaMessageAdmin();

return (
<PaMessageForm
key={paMessage.updated_at}
title="Edit PA/ESS message"
title={`${isReadOnly ? "View" : "Edit"} PA/ESS message`}
errors={errors}
errorMessage={errorMessage}
onError={setErrorMessage}
Expand All @@ -124,6 +126,7 @@ const EditPaMessage = ({ paMessage, alert }: Props) => {
}
}
}}
isReadOnly={isReadOnly}
/>
);
};
Expand Down
9 changes: 8 additions & 1 deletion assets/js/components/Dashboard/IntervalPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ interface Props {
interval: string;
onChangeInterval: (interval: string) => void;
validated: boolean;
disabled?: boolean;
}

const IntervalPicker = ({ interval, onChangeInterval, validated }: Props) => {
const IntervalPicker = ({
interval,
onChangeInterval,
validated,
disabled = false,
}: Props) => {
return (
<Form.Group>
<Form.Label
Expand All @@ -30,6 +36,7 @@ const IntervalPicker = ({ interval, onChangeInterval, validated }: Props) => {
onChange={(input) => onChangeInterval(input.target.value)}
required
isInvalid={validated && (!Number.isInteger(+interval) || +interval < 1)}
disabled={disabled}
/>
<Form.Control.Feedback type="invalid">
Interval value must be a positive integer
Expand Down
Loading

0 comments on commit fd8fdd5

Please sign in to comment.