import { ClockIcon } from "@heroicons/react/outline"; import { useSession } from "next-auth/client"; import Link from "next/link"; import { useRouter } from "next/router"; import { useRef, useState } from "react"; import { trpc } from "@lib/trpc"; import Loader from "@components/Loader"; import Modal from "@components/Modal"; import Shell from "@components/Shell"; import { Alert } from "@components/ui/Alert"; export default function Availability() { const queryMe = trpc.useQuery(["viewer.me"]); // eslint-disable-next-line @typescript-eslint/no-unused-vars const [session, loading] = useSession(); const router = useRouter(); const [showAddModal, setShowAddModal] = useState(false); const [successModalOpen, setSuccessModalOpen] = useState(false); const [showChangeTimesModal, setShowChangeTimesModal] = useState(false); const titleRef = useRef(); const slugRef = useRef(); const descriptionRef = useRef(); const lengthRef = useRef(); const isHiddenRef = useRef(); const startHoursRef = useRef(); const startMinsRef = useRef(); const endHoursRef = useRef(); const endMinsRef = useRef(); const bufferHoursRef = useRef(); const bufferMinsRef = useRef(); if (queryMe.status === "loading") { return ; } if (queryMe.status !== "success") { return ; } const user = queryMe.data; function toggleAddModal() { setShowAddModal(!showAddModal); } function toggleChangeTimesModal() { setShowChangeTimesModal(!showChangeTimesModal); } const closeSuccessModal = () => { setSuccessModalOpen(false); router.replace(router.asPath); }; function convertMinsToHrsMins(mins) { let h = Math.floor(mins / 60); let m = mins % 60; h = h < 10 ? "0" + h : h; m = m < 10 ? "0" + m : m; return `${h}:${m}`; } // eslint-disable-next-line @typescript-eslint/no-unused-vars async function createEventTypeHandler(event) { event.preventDefault(); const enteredTitle = titleRef.current.value; const enteredSlug = slugRef.current.value; const enteredDescription = descriptionRef.current.value; const enteredLength = lengthRef.current.value; const enteredIsHidden = isHiddenRef.current.checked; // TODO: Add validation // eslint-disable-next-line @typescript-eslint/no-unused-vars const response = await fetch("/api/availability/eventtype", { method: "POST", body: JSON.stringify({ title: enteredTitle, slug: enteredSlug, description: enteredDescription, length: enteredLength, hidden: enteredIsHidden, }), headers: { "Content-Type": "application/json", }, }); if (enteredTitle && enteredLength) { router.replace(router.asPath); toggleAddModal(); } } async function updateStartEndTimesHandler(event) { event.preventDefault(); const enteredStartHours = parseInt(startHoursRef.current.value); const enteredStartMins = parseInt(startMinsRef.current.value); const enteredEndHours = parseInt(endHoursRef.current.value); const enteredEndMins = parseInt(endMinsRef.current.value); const enteredBufferHours = parseInt(bufferHoursRef.current.value); const enteredBufferMins = parseInt(bufferMinsRef.current.value); const startMins = enteredStartHours * 60 + enteredStartMins; const endMins = enteredEndHours * 60 + enteredEndMins; const bufferMins = enteredBufferHours * 60 + enteredBufferMins; // TODO: Add validation // eslint-disable-next-line @typescript-eslint/no-unused-vars const response = await fetch("/api/availability/day", { method: "PATCH", body: JSON.stringify({ start: startMins, end: endMins, buffer: bufferMins }), headers: { "Content-Type": "application/json", }, }); setShowChangeTimesModal(false); setSuccessModalOpen(true); } return (

Change the start and end times of your day

Currently, your day is set to start at {convertMinsToHrsMins(user.startTime)} and end at{" "} {convertMinsToHrsMins(user.endTime)}.

Something doesn't look right?

Troubleshoot your availability to explore why your times are showing as they are.

{showChangeTimesModal && (

Set the start and end time of your day and a minimum buffer between your meetings.

:
:
:
)}
); }