Standardise semicolons
This commit is contained in:
parent
1db4973aee
commit
ddd7ccfb01
11 changed files with 64 additions and 115 deletions
|
@ -1,14 +1,14 @@
|
|||
import { PrismaClient } from '@prisma/client'
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
let prisma: PrismaClient
|
||||
let prisma: PrismaClient;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
prisma = new PrismaClient()
|
||||
prisma = new PrismaClient();
|
||||
} else {
|
||||
if (!global.prisma) {
|
||||
global.prisma = new PrismaClient()
|
||||
global.prisma = new PrismaClient();
|
||||
}
|
||||
prisma = global.prisma
|
||||
prisma = global.prisma;
|
||||
}
|
||||
|
||||
export default prisma
|
||||
export default prisma;
|
|
@ -1,6 +1,6 @@
|
|||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import prisma from '../lib/prisma'
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
import prisma from '../lib/prisma';
|
||||
|
||||
export default function User(props) {
|
||||
const eventTypes = props.user.eventTypes.map(type =>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import {useEffect, useState} from 'react'
|
||||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import prisma from '../../lib/prisma'
|
||||
import { useRouter } from 'next/router'
|
||||
const dayjs = require('dayjs')
|
||||
const isSameOrBefore = require('dayjs/plugin/isSameOrBefore')
|
||||
dayjs.extend(isSameOrBefore)
|
||||
import {useEffect, useState} from 'react';
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
import prisma from '../../lib/prisma';
|
||||
import { useRouter } from 'next/router';
|
||||
const dayjs = require('dayjs');
|
||||
const isSameOrBefore = require('dayjs/plugin/isSameOrBefore');
|
||||
dayjs.extend(isSameOrBefore);
|
||||
|
||||
export default function Type(props) {
|
||||
// Initialise state
|
||||
|
@ -15,23 +15,23 @@ export default function Type(props) {
|
|||
const [busy, setBusy] = useState([]);
|
||||
|
||||
// Get router variables
|
||||
const router = useRouter()
|
||||
const { user } = router.query
|
||||
const router = useRouter();
|
||||
const { user } = router.query;
|
||||
|
||||
// Handle month changes
|
||||
const incrementMonth = () => {
|
||||
setSelectedMonth(selectedMonth + 1)
|
||||
setSelectedMonth(selectedMonth + 1);
|
||||
}
|
||||
|
||||
const decrementMonth = () => {
|
||||
setSelectedMonth(selectedMonth - 1)
|
||||
setSelectedMonth(selectedMonth - 1);
|
||||
}
|
||||
|
||||
// Set up calendar
|
||||
var daysInMonth = dayjs().month(selectedMonth).daysInMonth()
|
||||
var days = []
|
||||
var daysInMonth = dayjs().month(selectedMonth).daysInMonth();
|
||||
var days = [];
|
||||
for (let i = 1; i <= daysInMonth; i++) {
|
||||
days.push(i)
|
||||
days.push(i);
|
||||
}
|
||||
|
||||
const calendar = days.map((day) =>
|
||||
|
@ -43,14 +43,14 @@ export default function Type(props) {
|
|||
// Handle date change
|
||||
useEffect(async () => {
|
||||
setLoading(true);
|
||||
const res = await fetch('/api/availability/' + user + '?date=' + dayjs(selectedDate).format("YYYY-MM-DD"))
|
||||
const data = await res.json()
|
||||
setBusy(data.primary.busy)
|
||||
setLoading(false)
|
||||
const res = await fetch('/api/availability/' + user + '?date=' + dayjs(selectedDate).format("YYYY-MM-DD"));
|
||||
const data = await res.json();
|
||||
setBusy(data.primary.busy);
|
||||
setLoading(false);
|
||||
}, [selectedDate]);
|
||||
|
||||
// Set up timeslots
|
||||
let times = []
|
||||
let times = [];
|
||||
|
||||
// If we're looking at availability throughout the current date, work out the current number of minutes elapsed throughout the day
|
||||
if (selectedDate == dayjs().format("YYYY-MM-DD")) {
|
||||
|
@ -61,14 +61,14 @@ export default function Type(props) {
|
|||
|
||||
// Until day end, push new times every x minutes
|
||||
for (;i < 1440; i += parseInt(props.eventType.length)) {
|
||||
times.push(dayjs(selectedDate).hour(Math.floor(i / 60)).minute(i % 60).startOf(props.eventType.length, 'minute').add(props.eventType.length, 'minute').format("YYYY-MM-DD HH:mm:ss"))
|
||||
times.push(dayjs(selectedDate).hour(Math.floor(i / 60)).minute(i % 60).startOf(props.eventType.length, 'minute').add(props.eventType.length, 'minute').format("YYYY-MM-DD HH:mm:ss"));
|
||||
}
|
||||
|
||||
// Check for conflicts
|
||||
times.forEach(time => {
|
||||
busy.forEach(busyTime => {
|
||||
let startTime = dayjs(busyTime.start)
|
||||
let endTime = dayjs(busyTime.end)
|
||||
let startTime = dayjs(busyTime.start);
|
||||
let endTime = dayjs(busyTime.end);
|
||||
|
||||
// Check if start times are the same
|
||||
if (dayjs(time).format('HH:mm') == startTime.format('HH:mm')) {
|
||||
|
@ -143,7 +143,7 @@ export default function Type(props) {
|
|||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export async function getServerSideProps(context) {
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import { useRouter } from 'next/router'
|
||||
import prisma from '../../lib/prisma'
|
||||
const dayjs = require('dayjs')
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
import { useRouter } from 'next/router';
|
||||
import prisma from '../../lib/prisma';
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
export default function Book(props) {
|
||||
const router = useRouter()
|
||||
const { date, user } = router.query
|
||||
const router = useRouter();
|
||||
const { date, user } = router.query;
|
||||
|
||||
const bookingHandler = event => {
|
||||
event.preventDefault()
|
||||
event.preventDefault();
|
||||
const res = fetch(
|
||||
'/api/book/' + user,
|
||||
{
|
||||
|
@ -25,8 +25,8 @@ export default function Book(props) {
|
|||
},
|
||||
method: 'POST'
|
||||
}
|
||||
)
|
||||
router.push("/success?date=" + date + "&type=" + props.eventType.id + "&user=" + props.user.username)
|
||||
);
|
||||
router.push("/success?date=" + date + "&type=" + props.eventType.id + "&user=" + props.user.username);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import '../styles/globals.css'
|
||||
import { Provider } from 'next-auth/client'
|
||||
import '../styles/globals.css';
|
||||
import { Provider } from 'next-auth/client';
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return (
|
||||
<Provider session={pageProps.session}>
|
||||
<Component {...pageProps} />
|
||||
</Provider>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default MyApp
|
||||
export default MyApp;
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import prisma from '../../../lib/prisma'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import prisma from '../../../lib/prisma';
|
||||
const {google} = require('googleapis');
|
||||
|
||||
const credentials = process.env.GOOGLE_API_CREDENTIALS;
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { user } = req.query
|
||||
const { user } = req.query;
|
||||
|
||||
const currentUser = await prisma.user.findFirst({
|
||||
where: {
|
||||
|
@ -16,14 +16,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
|||
}
|
||||
});
|
||||
|
||||
authorise(bookEvent)
|
||||
authorise(bookEvent);
|
||||
|
||||
// Set up Google API credentials
|
||||
function authorise(callback) {
|
||||
const {client_secret, client_id, redirect_uris} = JSON.parse(credentials).web;
|
||||
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
|
||||
oAuth2Client.setCredentials(currentUser.credentials[0].key);
|
||||
callback(oAuth2Client)
|
||||
callback(oAuth2Client);
|
||||
}
|
||||
|
||||
function bookEvent(auth) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import prisma from '../../../../lib/prisma';
|
||||
const {google} = require('googleapis');
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { getSession } from 'next-auth/client';
|
||||
import prisma from '../../../../lib/prisma';
|
||||
const {google} = require('googleapis');
|
||||
|
@ -6,7 +6,7 @@ const {google} = require('googleapis');
|
|||
const credentials = process.env.GOOGLE_API_CREDENTIALS;
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { code } = req.query
|
||||
const { code } = req.query;
|
||||
|
||||
// Check that user is authenticated
|
||||
const session = await getSession({req: req});
|
||||
|
|
|
@ -3,8 +3,8 @@ import Head from 'next/head';
|
|||
import Link from 'next/link';
|
||||
|
||||
export default function Error() {
|
||||
const router = useRouter()
|
||||
const { error } = router.query
|
||||
const router = useRouter();
|
||||
const { error } = router.query;
|
||||
|
||||
return (
|
||||
<div className="fixed z-10 inset-0 overflow-y-auto" aria-labelledby="modal-title" role="dialog" aria-modal="true">
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import Head from 'next/head'
|
||||
import Link from 'next/link'
|
||||
import prisma from '../lib/prisma'
|
||||
import { useRouter } from 'next/router'
|
||||
const dayjs = require('dayjs')
|
||||
import Head from 'next/head';
|
||||
import Link from 'next/link';
|
||||
import prisma from '../lib/prisma';
|
||||
import { useRouter } from 'next/router';
|
||||
const dayjs = require('dayjs');
|
||||
|
||||
export default function Success(props) {
|
||||
const router = useRouter()
|
||||
const { date } = router.query
|
||||
const router = useRouter();
|
||||
const { date } = router.query;
|
||||
|
||||
return(
|
||||
<div>
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
import { useRef } from 'react';
|
||||
|
||||
export default function add() {
|
||||
const usernameInputRef = useRef();
|
||||
const emailInputRef = useRef();
|
||||
const passwordInputRef = useRef();
|
||||
|
||||
async function createUser(username, email, password) {
|
||||
const response = await fetch('/api/auth/signup', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({username, email, password}),
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.message || 'Something went wrong.');
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
async function submitHandler(event) {
|
||||
event.preventDefault();
|
||||
|
||||
const enteredUsername = usernameInputRef.current.value;
|
||||
const enteredEmail = emailInputRef.current.value;
|
||||
const enteredPassword = passwordInputRef.current.value;
|
||||
|
||||
// TODO: Add validation
|
||||
|
||||
try {
|
||||
const result = await createUser(enteredUsername, enteredEmail, enteredPassword);
|
||||
console.log(result);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={submitHandler}>
|
||||
<input type="text" id="username" name="username" placeholder="Username" ref={usernameInputRef} />
|
||||
<input type="text" id="email" name="email" placeholder="Email Address" ref={emailInputRef}/>
|
||||
<input type="text" id="password" name="password" placeholder="Password" ref={passwordInputRef}/>
|
||||
<input type="submit" value="Sign up"/>
|
||||
</form>
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue