mirror of
https://github.com/Xevion/bus-reminder.git
synced 2025-12-06 05:14:35 -06:00
Slight reformatting with prettier
This commit is contained in:
@@ -1,54 +1,59 @@
|
||||
import {NextPage} from "next";
|
||||
import {useForm} from "react-hook-form";
|
||||
import {useState} from "react";
|
||||
import {useRouter} from "next/router";
|
||||
|
||||
import { NextPage } from 'next';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
|
||||
const LoginPage: NextPage = () => {
|
||||
type FormProps = { token: string; }
|
||||
const {handleSubmit, register} = useForm<FormProps>();
|
||||
const [error, setError] = useState<boolean | null>(null);
|
||||
const router = useRouter();
|
||||
type FormProps = { token: string };
|
||||
const { handleSubmit, register } = useForm<FormProps>();
|
||||
const [error, setError] = useState<boolean | null>(null);
|
||||
const router = useRouter();
|
||||
|
||||
async function onSubmit(data: FormProps) {
|
||||
const response = await fetch(`/api/check?key=${data.token}`)
|
||||
if (response.status === 200) {
|
||||
setError(false);
|
||||
router.push({pathname: "/", query: {"key": data.token}}).then();
|
||||
} else
|
||||
setError(true);
|
||||
}
|
||||
async function onSubmit(data: FormProps) {
|
||||
const response = await fetch(`/api/check?key=${data.token}`);
|
||||
if (response.status === 200) {
|
||||
setError(false);
|
||||
router.push({ pathname: '/', query: { key: data.token } }).then();
|
||||
} else setError(true);
|
||||
}
|
||||
|
||||
return <div className="flex bg-zinc-900 min-h-screen h-full flex-col justify-center py-12 sm:px-6 lg:px-8">
|
||||
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
||||
<div className="bg-black/ py-8 px-4 shadow sm:rounded-lg sm:px-10">
|
||||
<form className="space-y-6" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div>
|
||||
<label htmlFor="password" className="block text-sm font-medium text-gray-400">
|
||||
Token
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<input
|
||||
{...register("token", {required: true})}
|
||||
className="bg-zinc-800/80 text-zinc-300 block w-full appearance-none rounded-md border border-zinc-700/80 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-indigo-800/50 focus:outline-none focus:ring-indigo-500 sm:text-sm"
|
||||
/>
|
||||
</div>
|
||||
{error ? <p className="mt-2 text-sm text-red-600" id="email-error">
|
||||
The token given was not valid.
|
||||
</p> : null}
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex w-full justify-center rounded-md border border-transparent bg-indigo-900/80 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-indigo-900 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
|
||||
>
|
||||
Sign in
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
return (
|
||||
<div className="flex bg-zinc-900 min-h-screen h-full flex-col justify-center py-12 sm:px-6 lg:px-8">
|
||||
<div className="mt-8 sm:mx-auto sm:w-full sm:max-w-md">
|
||||
<div className="bg-black/ py-8 px-4 shadow sm:rounded-lg sm:px-10">
|
||||
<form className="space-y-6" onSubmit={handleSubmit(onSubmit)}>
|
||||
<div>
|
||||
<label
|
||||
htmlFor="password"
|
||||
className="block text-sm font-medium text-gray-400"
|
||||
>
|
||||
Token
|
||||
</label>
|
||||
<div className="mt-1">
|
||||
<input
|
||||
{...register('token', { required: true })}
|
||||
className="bg-zinc-800/80 text-zinc-300 block w-full appearance-none rounded-md border border-zinc-700/80 px-3 py-2 placeholder-gray-400 shadow-sm focus:border-indigo-800/50 focus:outline-none focus:ring-indigo-500 sm:text-sm"
|
||||
/>
|
||||
</div>
|
||||
{error ? (
|
||||
<p className="mt-2 text-sm text-red-600" id="email-error">
|
||||
The token given was not valid.
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
<div>
|
||||
<button
|
||||
type="submit"
|
||||
className="flex w-full justify-center rounded-md border border-transparent bg-indigo-700 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-indigo-700/80 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
|
||||
>
|
||||
Sign in
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LoginPage;
|
||||
export default LoginPage;
|
||||
|
||||
@@ -45,9 +45,12 @@ const TimeConfigSchema = z.object({
|
||||
return parsed;
|
||||
}),
|
||||
// The days this configuration is active on.
|
||||
days: z.array(DayEnumSchema).nonempty().transform(arr => {
|
||||
return new Set<DayEnum>(arr);
|
||||
}),
|
||||
days: z
|
||||
.array(DayEnumSchema)
|
||||
.nonempty()
|
||||
.transform((arr) => {
|
||||
return new Set<DayEnum>(arr);
|
||||
}),
|
||||
// If a notification isn't delivery within 10 minutes e.g. "00:30", 24 hour time
|
||||
maxLate: z
|
||||
.string()
|
||||
@@ -211,11 +214,15 @@ const dayAsNumber: Record<string, DayEnum> = {
|
||||
|
||||
export async function getMatchingTime(
|
||||
config: Configuration,
|
||||
now = new Date()
|
||||
now: Date = new Date()
|
||||
): Promise<TimeConfig | null> {
|
||||
const times = config.times.filter((time) => {
|
||||
// If the day doesn't match, skip.
|
||||
if (!time.days.has(dayAsNumber[now.getDay().toString()])) return false;
|
||||
const nowTime = {
|
||||
hours: now.getHours(),
|
||||
minutes: now.getMinutes()
|
||||
};
|
||||
|
||||
const startTime = time.time;
|
||||
const endTime = addTime(
|
||||
@@ -223,8 +230,6 @@ export async function getMatchingTime(
|
||||
time.maxLate ?? { hours: 0, minutes: 0 }
|
||||
);
|
||||
|
||||
const nowTime = { hours: now.getHours(), minutes: now.getMinutes() };
|
||||
|
||||
return (
|
||||
compareTime(nowTime, startTime) >= 0 && compareTime(nowTime, endTime) <= 0
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user