Let users set 12/24 hour time format (#2002)

This commit is contained in:
Bailey Pumfleet authored and GitHub committed 2022-02-28 16:24:47 +00:00
1 parent 2559873b2c
commit 7826a34b00
8 files changed
+53 -5

No files matched your search

+10 -3
View File
@@ -10,6 +10,7 @@ import { weekdayNames } from "@lib/core/i18n/weekday";
import { useLocale } from "@lib/hooks/useLocale";
import { TimeRange } from "@lib/types/schedule";
import { useMeQuery } from "@components/Shell";
import Button from "@components/ui/Button";
import Select from "@components/ui/form/Select";
@@ -46,6 +47,10 @@ type TimeRangeFieldProps = {
};
const TimeRangeField = ({ name }: TimeRangeFieldProps) => {
// Get user so we can determine 12/24 hour format preferences
const query = useMeQuery();
const user = query.data;
// Lazy-loaded options, otherwise adding a field has a noticable redraw delay.
const [options, setOptions] = useState<Option[]>([]);
const [selected, setSelected] = useState<number | undefined>();
@@ -57,7 +62,9 @@ const TimeRangeField = ({ name }: TimeRangeFieldProps) => {
const getOption = (time: ConfigType) => ({
value: dayjs(time).toDate().valueOf(),
label: dayjs(time).utc().format("HH:mm"),
label: dayjs(time)
.utc()
.format(user && user.timeFormat === 12 ? "h:mma" : "HH:mm"),
// .toLocaleTimeString(i18n.language, { minute: "numeric", hour: "numeric" }),
});
@@ -82,7 +89,7 @@ const TimeRangeField = ({ name }: TimeRangeFieldProps) => {
handleSelected(value);
return (
<Select
className="w-[6rem]"
className="w-30"
options={options}
onFocus={() => setOptions(timeOptions())}
onBlur={() => setOptions([])}
@@ -100,7 +107,7 @@ const TimeRangeField = ({ name }: TimeRangeFieldProps) => {
name={`${name}.end`}
render={({ field: { onChange, value } }) => (
<Select
className="w-[6rem]"
className="w-30"
options={options}
onFocus={() => setOptions(timeOptions({ selected }))}
onBlur={() => setOptions([])}