import { ClockIcon } from "@heroicons/react/outline"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect } from "react"; import { useForm } from "react-hook-form"; import { useToggleQuery } from "@lib/hooks/useToggleQuery"; import showToast from "@lib/notification"; import { trpc } from "@lib/trpc"; import { Dialog, DialogContent } from "@components/Dialog"; import Loader from "@components/Loader"; import Shell from "@components/Shell"; import { Alert } from "@components/ui/Alert"; import Button from "@components/ui/Button"; function convertMinsToHrsMins(mins: number) { const h = Math.floor(mins / 60); const m = mins % 60; const hours = h < 10 ? "0" + h : h; const minutes = m < 10 ? "0" + m : m; return `${hours}:${minutes}`; } export default function Availability() { const queryMe = trpc.useQuery(["viewer.me"]); const formModal = useToggleQuery("edit"); const formMethods = useForm<{ startHours: string; startMins: string; endHours: string; endMins: string; bufferHours: string; bufferMins: string; }>({}); const router = useRouter(); useEffect(() => { /** * This hook populates the form with new values as soon as the user is loaded or changes */ const user = queryMe.data; if (formMethods.formState.isDirty || !user) { return; } formMethods.reset({ startHours: convertMinsToHrsMins(user.startTime).split(":")[0], startMins: convertMinsToHrsMins(user.startTime).split(":")[1], endHours: convertMinsToHrsMins(user.endTime).split(":")[0], endMins: convertMinsToHrsMins(user.endTime).split(":")[1], bufferHours: convertMinsToHrsMins(user.bufferTime).split(":")[0], bufferMins: convertMinsToHrsMins(user.bufferTime).split(":")[1], }); }, [formMethods, queryMe.data]); if (queryMe.status === "loading") { return ; } if (queryMe.status !== "success") { return ; } const user = queryMe.data; 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.

{ router.push(isOpen ? formModal.hrefOn : formModal.hrefOff); }}>

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

{ const startMins = parseInt(values.startHours) * 60 + parseInt(values.startMins); const endMins = parseInt(values.endHours) * 60 + parseInt(values.endMins); const bufferMins = parseInt(values.bufferHours) * 60 + parseInt(values.bufferMins); // 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", }, }); if (!response.ok) { showToast("Something went wrong", "error"); return; } await queryMe.refetch(); router.push(formModal.hrefOff); showToast("The start and end times for your day have been changed successfully.", "success"); })}>
:
:
:
); }