Skip to content

Commit

Permalink
Scheduler time zone addons + a11y improvements for form elements. (#1949
Browse files Browse the repository at this point in the history
)

* Scheduler time zone addons + a11y improvements for form elements.

* layout tweaks

* format

* format?

* format??

* compile scheduler

* reviewed translations

---------

Co-authored-by: Andrew <[email protected]>
  • Loading branch information
amazingphilippe and andrewleith authored Oct 29, 2024
1 parent 5d09877 commit fb55586
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/scheduler.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions app/assets/javascripts/scheduler/Confirmation/Confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export const Confirmation = () => {
const date = selected + "T" + time;

const timeFormat =
_24hr === "on" ? time : dayjs(date).format(translate("time_format"));
_24hr === "on"
? dayjs(date).format("H [h] mm")
: dayjs(date).format("h:mm A");

return selected.length > 0 && time ? (
<div>
Expand All @@ -20,7 +22,7 @@ export const Confirmation = () => {
<strong>
{translate("date_prefix")}
{dayjs(date).format(translate("date_format"))} {translate("at")}{" "}
{timeFormat}
{timeFormat}, {translate("local_time_suffix")}
</strong>
</p>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/scheduler/Date/Date.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export const Date = () => {
const date = selected[0];

if (!date) {
return <div className="date-display"></div>;
return <span className="date-display"></span>;
}
const txt = formattedDay(selected[0]);
return <div className="date-display">{txt}</div>;
return <span className="date-display">{txt}</span>;
};
16 changes: 13 additions & 3 deletions app/assets/javascripts/scheduler/DateTime/DateTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, { useContext } from "react";
import { Date } from "../Date/Date";
import { Toggle } from "../Toggle/Toggle";
import { Time } from "../Time/Time";
import { store } from "./index";
import { store, I18nContext } from "./index";

export const DateTime = () => {
const { selected } = useContext(store);
const { translate } = useContext(I18nContext);

if (typeof selected[0] === "undefined") {
return null;
Expand All @@ -16,8 +17,17 @@ export const DateTime = () => {
<div className="selected-date-time-box">
<div className="triangle"></div>
<div className="date-time-box">
<Date />
<Time name="time" />
<div classNAme="form-group">
<label className="form-label" for="time">
<span>
{translate("select_time_label")} <Date />
</span>
</label>
<span id="time-hint" className="form-hint">
{translate("select_time_hint")}
</span>
<Time name="time" />
</div>
<Toggle />
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/scheduler/DateTime/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { store, StateProvider } from "../store";
export { I18nContext } from "../i18n";
2 changes: 1 addition & 1 deletion app/assets/javascripts/scheduler/Time/Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const Time = ({ name }) => {
});
}}
id={name}
aria-label={name}
aria-describedby={`${name}-hint`}
value={time}
>
{valid_time_values.map((item) => {
Expand Down
14 changes: 11 additions & 3 deletions app/assets/javascripts/scheduler/Toggle/Toggle.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import React, { useContext } from "react";
import { store } from "./index";
import { store, I18nContext } from "./index";

export const Toggle = () => {
const { _24hr, time, dispatch } = useContext(store);
const { translate } = useContext(I18nContext);

if (time === "") {
return <div className="choice choice--radios"></div>;
}

return (
<div className="choice choice--radios">
<fieldset
className="form-group choice choice--radios"
id="time-toggle"
role="radio-group"
>
<legend className="form-label w-full">
<span>{translate("select_time_format_label")}</span>
</legend>
<div className="choice__item">
<input
name="time-toggle"
Expand Down Expand Up @@ -37,6 +45,6 @@ export const Toggle = () => {
/>
<label htmlFor="_24">24h</label>
</div>
</div>
</fieldset>
);
};
6 changes: 6 additions & 0 deletions app/assets/javascripts/scheduler/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ export const EN = {
time_format: "h:mm A",
cancel: "You can cancel this send before the scheduled time.",
select_date: "Select a date and time to schedule the send.",
select_time_label: "What time on",
select_time_hint: "The clock uses your local time zone",
select_time_format_label: "Time format",
is_24: "24 hr time selected",
is_am_pm: "AM PM time selected",
local_time_suffix: "local time",
};
6 changes: 6 additions & 0 deletions app/assets/javascripts/scheduler/locales/fr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ export const FR = {
time_format: "H [h] mm",
cancel: "Vous pourrez annuler cet envoi avant l’heure prévue.",
select_date: "Sélectionnez une date et une heure pour programmer l’envoi.",
select_time_label: "Heure d'envoi le",
select_time_hint: "L'heure affichée correspond à votre fuseau horaire",
select_time_format_label: "Format de l'heure",
is_24: "Mode 24 heures activé",
is_am_pm: "Mode AM PM activé",
local_time_suffix: "heure locale",
};
5 changes: 1 addition & 4 deletions app/assets/javascripts/scheduler/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ export const StateProvider = ({ value, children }) => {
...state,
_24hr: action.payload,
time_values: populateTimes(action.payload),
updateMessage:
action.payload === "off"
? "24 hr time selected"
: "AM PM time selected ",
updateMessage: action.payload === "off" ? "is_am_pm" : "is_24",
};
break;
case "CALENDAR_UPDATES":
Expand Down

0 comments on commit fb55586

Please sign in to comment.