From d28166a2c3a632b87882eb3bdc3d8c12726369bf Mon Sep 17 00:00:00 2001 From: Bailey Pumfleet Date: Tue, 20 Apr 2021 15:41:36 +0100 Subject: [PATCH] Switch between 12 and 24 hours --- pages/[user]/[type].tsx | 53 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/pages/[user]/[type].tsx b/pages/[user]/[type].tsx index 55e3ebff5a..d11933c1fd 100644 --- a/pages/[user]/[type].tsx +++ b/pages/[user]/[type].tsx @@ -4,6 +4,8 @@ import Link from 'next/link'; import prisma from '../../lib/prisma'; import { useRouter } from 'next/router'; const dayjs = require('dayjs'); +import { Switch } from '@headlessui/react'; +import { GlobeIcon, ChevronDownIcon } from '@heroicons/react/solid'; const isSameOrBefore = require('dayjs/plugin/isSameOrBefore'); const isBetween = require('dayjs/plugin/isBetween'); const utc = require('dayjs/plugin/utc'); @@ -13,19 +15,27 @@ dayjs.extend(isBetween); dayjs.extend(utc); dayjs.extend(timezone); -import getSlots from '../../lib/slots' +import getSlots from '../../lib/slots'; + +function classNames(...classes) { + return classes.filter(Boolean).join(' ') +} export default function Type(props) { // Initialise state const [selectedDate, setSelectedDate] = useState(''); const [selectedMonth, setSelectedMonth] = useState(dayjs().month()); const [loading, setLoading] = useState(false); + const [isTimeOptionsOpen, setIsTimeOptionsOpen] = useState(false); + const [is24h, setIs24h] = useState(false); const [busy, setBusy] = useState([]); // Get router variables const router = useRouter(); const { user } = router.query; + const toggleTimeOptions = () => { setIsTimeOptionsOpen(!isTimeOptionsOpen); } + // Handle month changes const incrementMonth = () => { setSelectedMonth(selectedMonth + 1); @@ -108,7 +118,7 @@ export default function Type(props) { const availableTimes = times.map((time) =>
- {dayjs(time).tz(dayjs.tz.guess()).format("hh:mma")} + {dayjs(time).tz(dayjs.tz.guess()).format(is24h ? "HH:mm" : "hh:mma")}
); @@ -123,17 +133,50 @@ export default function Type(props) {
-
+
{props.user.avatar && Avatar}

{props.user.name}

{props.eventType.title}

-

+

{props.eventType.length} minutes

-

{props.eventType.description}

+ + { isTimeOptionsOpen && +
+ + + am/pm + + + Use setting + + + 24h + + +
+ } +

{props.eventType.description}