Add hidden event types
This commit is contained in:
parent
b32a4c75c0
commit
c320b0f20d
5 changed files with 72 additions and 8 deletions
|
@ -3,7 +3,7 @@ import Link from 'next/link';
|
||||||
import prisma from '../lib/prisma';
|
import prisma from '../lib/prisma';
|
||||||
|
|
||||||
export default function User(props) {
|
export default function User(props) {
|
||||||
const eventTypes = props.user.eventTypes.map(type =>
|
const eventTypes = props.eventTypes.map(type =>
|
||||||
<li key={type.id}>
|
<li key={type.id}>
|
||||||
<Link href={'/' + props.user.username + '/' + type.id.toString()}>
|
<Link href={'/' + props.user.username + '/' + type.id.toString()}>
|
||||||
<a className="block px-6 py-4">
|
<a className="block px-6 py-4">
|
||||||
|
@ -46,9 +46,10 @@ export default function User(props) {
|
||||||
export async function getServerSideProps(context) {
|
export async function getServerSideProps(context) {
|
||||||
const user = await prisma.user.findFirst({
|
const user = await prisma.user.findFirst({
|
||||||
where: {
|
where: {
|
||||||
username: context.query.user,
|
username: context.query.user,
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
id: true,
|
||||||
username: true,
|
username: true,
|
||||||
name: true,
|
name: true,
|
||||||
bio: true,
|
bio: true,
|
||||||
|
@ -63,9 +64,17 @@ export async function getServerSideProps(context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const eventTypes = await prisma.eventType.findMany({
|
||||||
|
where: {
|
||||||
|
userId: user.id,
|
||||||
|
hidden: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
user
|
user,
|
||||||
|
eventTypes
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,12 +26,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const title = req.body.title;
|
const title = req.body.title;
|
||||||
const description = req.body.description;
|
const description = req.body.description;
|
||||||
const length = parseInt(req.body.length);
|
const length = parseInt(req.body.length);
|
||||||
|
const hidden = req.body.hidden;
|
||||||
|
|
||||||
const createEventType = await prisma.eventType.create({
|
const createEventType = await prisma.eventType.create({
|
||||||
data: {
|
data: {
|
||||||
title: title,
|
title: title,
|
||||||
description: description,
|
description: description,
|
||||||
length: length,
|
length: length,
|
||||||
|
hidden: hidden,
|
||||||
userId: user.id,
|
userId: user.id,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -56,6 +58,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
const title = req.body.title;
|
const title = req.body.title;
|
||||||
const description = req.body.description;
|
const description = req.body.description;
|
||||||
const length = parseInt(req.body.length);
|
const length = parseInt(req.body.length);
|
||||||
|
const hidden = req.body.hidden;
|
||||||
|
|
||||||
const updateEventType = await prisma.eventType.update({
|
const updateEventType = await prisma.eventType.update({
|
||||||
where: {
|
where: {
|
||||||
|
@ -64,7 +67,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
data: {
|
data: {
|
||||||
title: title,
|
title: title,
|
||||||
description: description,
|
description: description,
|
||||||
length: length
|
length: length,
|
||||||
|
hidden: hidden
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ export default function EventType(props) {
|
||||||
const titleRef = useRef();
|
const titleRef = useRef();
|
||||||
const descriptionRef = useRef();
|
const descriptionRef = useRef();
|
||||||
const lengthRef = useRef();
|
const lengthRef = useRef();
|
||||||
|
const isHiddenRef = useRef();
|
||||||
|
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return <p className="text-gray-400">Loading...</p>;
|
return <p className="text-gray-400">Loading...</p>;
|
||||||
|
@ -27,12 +28,13 @@ export default function EventType(props) {
|
||||||
const enteredTitle = titleRef.current.value;
|
const enteredTitle = titleRef.current.value;
|
||||||
const enteredDescription = descriptionRef.current.value;
|
const enteredDescription = descriptionRef.current.value;
|
||||||
const enteredLength = lengthRef.current.value;
|
const enteredLength = lengthRef.current.value;
|
||||||
|
const enteredIsHidden = isHiddenRef.current.checked;
|
||||||
|
|
||||||
// TODO: Add validation
|
// TODO: Add validation
|
||||||
|
|
||||||
const response = await fetch('/api/availability/eventtype', {
|
const response = await fetch('/api/availability/eventtype', {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: JSON.stringify({id: props.eventType.id, title: enteredTitle, description: enteredDescription, length: enteredLength}),
|
body: JSON.stringify({id: props.eventType.id, title: enteredTitle, description: enteredDescription, length: enteredLength, hidden: enteredIsHidden}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
@ -88,6 +90,26 @@ export default function EventType(props) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="my-8">
|
||||||
|
<div className="relative flex items-start">
|
||||||
|
<div className="flex items-center h-5">
|
||||||
|
<input
|
||||||
|
ref={isHiddenRef}
|
||||||
|
id="ishidden"
|
||||||
|
name="ishidden"
|
||||||
|
type="checkbox"
|
||||||
|
className="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded"
|
||||||
|
defaultChecked={props.eventType.hidden}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="ml-3 text-sm">
|
||||||
|
<label htmlFor="ishidden" className="font-medium text-gray-700">
|
||||||
|
Hide this event type
|
||||||
|
</label>
|
||||||
|
<p className="text-gray-500">Hide the event type from your page, so it can only be booked through it's URL.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<button type="submit" className="btn btn-primary">Update</button>
|
<button type="submit" className="btn btn-primary">Update</button>
|
||||||
<Link href="/availability"><a className="ml-2 btn btn-white">Cancel</a></Link>
|
<Link href="/availability"><a className="ml-2 btn btn-white">Cancel</a></Link>
|
||||||
</form>
|
</form>
|
||||||
|
@ -129,7 +151,8 @@ export async function getServerSideProps(context) {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
description: true,
|
description: true,
|
||||||
length: true
|
length: true,
|
||||||
|
hidden: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ export default function Availability(props) {
|
||||||
const titleRef = useRef();
|
const titleRef = useRef();
|
||||||
const descriptionRef = useRef();
|
const descriptionRef = useRef();
|
||||||
const lengthRef = useRef();
|
const lengthRef = useRef();
|
||||||
|
const isHiddenRef = useRef();
|
||||||
|
|
||||||
const startHoursRef = useRef();
|
const startHoursRef = useRef();
|
||||||
const startMinsRef = useRef();
|
const startMinsRef = useRef();
|
||||||
|
@ -55,12 +56,13 @@ export default function Availability(props) {
|
||||||
const enteredTitle = titleRef.current.value;
|
const enteredTitle = titleRef.current.value;
|
||||||
const enteredDescription = descriptionRef.current.value;
|
const enteredDescription = descriptionRef.current.value;
|
||||||
const enteredLength = lengthRef.current.value;
|
const enteredLength = lengthRef.current.value;
|
||||||
|
const enteredIsHidden = isHiddenRef.current.checked;
|
||||||
|
|
||||||
// TODO: Add validation
|
// TODO: Add validation
|
||||||
|
|
||||||
const response = await fetch('/api/availability/eventtype', {
|
const response = await fetch('/api/availability/eventtype', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({title: enteredTitle, description: enteredDescription, length: enteredLength}),
|
body: JSON.stringify({title: enteredTitle, description: enteredDescription, length: enteredLength, hidden: enteredIsHidden}),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
}
|
}
|
||||||
|
@ -139,6 +141,11 @@ export default function Availability(props) {
|
||||||
<tr>
|
<tr>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
<td className="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
{eventType.title}
|
{eventType.title}
|
||||||
|
{eventType.hidden &&
|
||||||
|
<span className="ml-2 inline-flex items-center px-2 py-0.5 rounded text-xs font-medium bg-gray-100 text-gray-800">
|
||||||
|
Hidden
|
||||||
|
</span>
|
||||||
|
}
|
||||||
</td>
|
</td>
|
||||||
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
<td className="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
{eventType.description}
|
{eventType.description}
|
||||||
|
@ -221,6 +228,25 @@ export default function Availability(props) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="my-8">
|
||||||
|
<div className="relative flex items-start">
|
||||||
|
<div className="flex items-center h-5">
|
||||||
|
<input
|
||||||
|
ref={isHiddenRef}
|
||||||
|
id="ishidden"
|
||||||
|
name="ishidden"
|
||||||
|
type="checkbox"
|
||||||
|
className="focus:ring-blue-500 h-4 w-4 text-blue-600 border-gray-300 rounded"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="ml-3 text-sm">
|
||||||
|
<label htmlFor="ishidden" className="font-medium text-gray-700">
|
||||||
|
Hide this event type
|
||||||
|
</label>
|
||||||
|
<p className="text-gray-500">Hide the event type from your page, so it can only be booked through it's URL.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
{/* TODO: Add an error message when required input fields empty*/}
|
{/* TODO: Add an error message when required input fields empty*/}
|
||||||
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
<div className="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
|
||||||
<button type="submit" className="btn btn-primary">
|
<button type="submit" className="btn btn-primary">
|
||||||
|
@ -324,7 +350,8 @@ export async function getServerSideProps(context) {
|
||||||
id: true,
|
id: true,
|
||||||
title: true,
|
title: true,
|
||||||
description: true,
|
description: true,
|
||||||
length: true
|
length: true,
|
||||||
|
hidden: true
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -15,6 +15,7 @@ model EventType {
|
||||||
title String
|
title String
|
||||||
description String?
|
description String?
|
||||||
length Int
|
length Int
|
||||||
|
hidden Boolean @default(false)
|
||||||
user User? @relation(fields: [userId], references: [id])
|
user User? @relation(fields: [userId], references: [id])
|
||||||
userId Int?
|
userId Int?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue