Skip to content

Commit

Permalink
[CIT-23] Uninterested Button (#44)
Browse files Browse the repository at this point in the history
* Trigger build

* CIT-23: add Uninterest button

* CIT-23: switch to status api route

* CIT-23: add Uninterest button

* Trigger build

---------

Co-authored-by: Ishaan <[email protected]>
  • Loading branch information
TheDannyG and ishaan-upadhyay authored Jul 21, 2023
1 parent f732a98 commit 485e64d
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ citrus/next-env.d.ts
.vercel

#data
cockroach-data/
cockroach-data/
node_modules/
5 changes: 2 additions & 3 deletions citrus/app/api/experiences/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export async function PUT(request: Request,
data: body
});

if (addUser !== null) {
if (addUser === "true") {
if (!session?.user) {
return NextResponse.json({ status: 400, "error": "User not logged in"});
}
Expand All @@ -171,8 +171,7 @@ export async function PUT(request: Request,
})
// Return the updated event and the created status
return NextResponse.json({ updatedEvent: updatedEvent, createdStatus: createdStatus });
}
else {
} else {
return NextResponse.json({ updatedEvent: updatedEvent });
}
} catch (e) {
Expand Down
51 changes: 51 additions & 0 deletions citrus/app/api/statuses/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,54 @@ export async function GET(request: Request) {
experiences,
});
}

/**
* @api {delete} /statuses/ Delete an event from a user's interested events
* @apiName DeleteInterestedEvent
* @apiGroup Events
*
* @apiParam {String} id The id of the event to delete
* @apiParam {String} [user_id] The id of the user to delete the event from
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* {
* "success": true
* }
*
* @apiErrorExample Error-Response:
* HTTP/1.1 400 Bad Request
* {
* "error": "You must provide either a user_id or be signed in to use this endpoint"
* }
*
**/
export async function DELETE(request: Request) {
const session = await getServerSession(authOptions);
const { searchParams } = new URL(request.url);
const event_id = searchParams.get('event_id');

if (!session) {
return NextResponse.json({ error: "You must be signed in to use this endpoint" }, { status: 400 });
}
if (!event_id) {
return NextResponse.json({ error: "You must provide an event_id" }, { status: 400 });
}

try {
await prisma.user_attending_status.delete({
where: {
username_event_id: {
username: session.user?.name,
event_id: event_id
}
}
}
);
}
catch (e) {
return db.handleError(e);
}

return NextResponse.json({ success: true});
}
4 changes: 2 additions & 2 deletions citrus/app/api/users/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ export async function PUT(request: Request) {
const email = body.email;
const premium = body.premium;
const phone_number = body.phone_number;
const socials = body.socials;
//const socials = body.socials;

if (password !== undefined) {
if (!schema.validate(password)) {
Expand All @@ -217,7 +217,7 @@ export async function PUT(request: Request) {
email: email,
premium: premium,
phone_number: phone_number,
socials: socials
//socials: socials
}

try {
Expand Down
8 changes: 7 additions & 1 deletion citrus/components/EventButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getServerSession } from 'next-auth/next'
import { authOptions } from '@/app/api/auth/[...nextauth]/route';
import InterestButton from '@/components/InterestButton'
import UninterestButton from './UninterestButton';


async function eventInfo(eventID: string) {
Expand All @@ -18,8 +19,13 @@ export default async function EventButton({eventID}: {eventID: string}){

const data = await eventInfo(eventID);

if (data.user_id === session.user?.name) {
return <div></div>
}

if(data.attendees.includes(session.user?.name)) {
return <p>You&apos;re already interested in this event.</p>
//return <p>You&apos;re already interested in this event.</p>
return <UninterestButton username={session.user?.name} eventID={eventID}/>
}

return (
Expand Down
37 changes: 37 additions & 0 deletions citrus/components/UninterestButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"use client";
import { useRouter } from "next/navigation";

async function onUninterestHandler(username: string | null | undefined, eventID: string){
const res = await fetch(`/api/experiences/${eventID}`);
console.log(res);
const data = await res.json();
const attendees = data.attendees;
const index = attendees.indexOf(username);
if (index > -1) {
attendees.splice(index, 1);
const res2 = await fetch(`/api/experiences/${eventID}?addUser=false`, {
method: 'PUT',
body: JSON.stringify({"attendees": attendees}),
});
console.log(res2);
}

const res3 = await fetch(`/api/statuses?event_id=${eventID}`, {
method: 'DELETE'
});
console.log(res3);

}

export default function UninterestButton({username, eventID}: {username: string | null | undefined, eventID: string}){
const router = useRouter();
return (
<div className="m-20 flex items-center justify-center">
<button className="text-center text-white font-semibold z-10 i h-16 w-64 bg-gradient-to-br from-yellow-400 to-yellow-600 items-center
rounded-full shadow-2xl cursor-pointer absolute overflow-hidden transform hover:scale-x-110
hover:scale-y-105 transition duration-300 ease-out"
onClick={async () => {await onUninterestHandler(username, eventID); router.refresh()}}>I&apos;m no longer interested</button>
</div>
)

}

1 comment on commit 485e64d

@vercel
Copy link

@vercel vercel bot commented on 485e64d Jul 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheDannyG is attempting to deploy a commit to a Personal Account on Vercel that is not owned by them.

In order for the commit to be deployed, @TheDannyG must be granted access to the connected Vercel project.

If you're the owner of the Personal Account, transfer the project to a Vercel Team and start collaborating, or learn more.

Please sign in to comment.