-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
94 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import { deleteEvent } from '../../../../database/events'; | ||
// import { NextRequest, NextResponse } from 'next/server'; | ||
// import { deleteEvent } from '../../../../database/events'; | ||
|
||
type DeleteEventResponseBody = | ||
| { message: string; event?: any } | ||
| { message: string; error?: string }; | ||
// type DeleteEventResponseBody = | ||
// | { message: string; event?: any } | ||
// | { message: string; error?: string }; | ||
|
||
export async function DELETE( | ||
request: NextRequest, | ||
): Promise<NextResponse<DeleteEventResponseBody>> { | ||
const { searchParams } = new URL(request.url); | ||
const eventId = searchParams.get('eventId'); | ||
const { sessionToken } = await request.json(); | ||
// export async function DELETE( | ||
// request: NextRequest, | ||
// ): Promise<NextResponse<DeleteEventResponseBody>> { | ||
// const { searchParams } = new URL(request.url); | ||
// const eventId = searchParams.get('eventId'); | ||
// const { sessionToken } = await request.json(); | ||
|
||
if (!sessionToken || !eventId) { | ||
return NextResponse.json( | ||
{ | ||
message: 'Invalid request', | ||
error: 'Session token or eventId is missing', | ||
}, | ||
{ status: 400 }, | ||
); | ||
} | ||
// if (!sessionToken || !eventId) { | ||
// return NextResponse.json( | ||
// { | ||
// message: 'Invalid request', | ||
// error: 'Session token or eventId is missing', | ||
// }, | ||
// { status: 400 }, | ||
// ); | ||
// } | ||
|
||
try { | ||
const event = await deleteEvent(sessionToken, parseInt(eventId, 10)); | ||
if (event) { | ||
return NextResponse.json( | ||
{ message: 'Event deleted successfully', event }, | ||
{ status: 200 }, | ||
); | ||
} else { | ||
return NextResponse.json( | ||
{ message: 'Event not found or session expired' }, | ||
{ status: 404 }, | ||
); | ||
} | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ message: 'Internal server error', error: (error as Error).message }, | ||
{ status: 500 }, | ||
); | ||
} | ||
} | ||
// try { | ||
// const event = await deleteEvent(sessionToken, parseInt(eventId, 10)); | ||
// if (event) { | ||
// return NextResponse.json( | ||
// { message: 'Event deleted successfully', event }, | ||
// { status: 200 }, | ||
// ); | ||
// } else { | ||
// return NextResponse.json( | ||
// { message: 'Event not found or session expired' }, | ||
// { status: 404 }, | ||
// ); | ||
// } | ||
// } catch (error) { | ||
// return NextResponse.json( | ||
// { message: 'Internal server error', error: (error as Error).message }, | ||
// { status: 500 }, | ||
// ); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
'use client'; | ||
// 'use client'; | ||
|
||
import { useRouter } from 'next/navigation'; | ||
import { FormEvent, useState } from 'react'; | ||
import { ImageUploadResponsePost } from '../api/imageUpload/route'; | ||
import ErrorMessage from '../ErrorMessage'; | ||
import { SubmitButton } from './SubmitButton'; | ||
// import { useRouter } from 'next/navigation'; | ||
// import { FormEvent, useState } from 'react'; | ||
// import { ImageUploadResponsePost } from '../api/imageUpload/route'; | ||
// import ErrorMessage from '../ErrorMessage'; | ||
// import { SubmitButton } from './SubmitButton'; | ||
|
||
interface ErrorResponse { | ||
error: string; | ||
} | ||
// interface ErrorResponse { | ||
// error: string; | ||
// } | ||
|
||
export default function ImageForm({ | ||
buttonTitle, | ||
formTitle, | ||
}: { | ||
buttonTitle: string; | ||
formTitle: string; | ||
}) { | ||
const [errorMessage, setErrorMessage] = useState(''); | ||
const [successMessage, setSuccessMessage] = useState(''); | ||
const router = useRouter(); | ||
// export default function ImageForm({ | ||
// buttonTitle, | ||
// formTitle, | ||
// }: { | ||
// buttonTitle: string; | ||
// formTitle: string; | ||
// }) { | ||
// const [errorMessage, setErrorMessage] = useState(''); | ||
// const [successMessage, setSuccessMessage] = useState(''); | ||
// const router = useRouter(); | ||
|
||
async function handleUpload(event: FormEvent<HTMLFormElement>) { | ||
event.preventDefault(); | ||
const formData = new FormData(event.currentTarget); | ||
// async function handleUpload(event: FormEvent<HTMLFormElement>) { | ||
// event.preventDefault(); | ||
// const formData = new FormData(event.currentTarget); | ||
|
||
const response = await fetch('/api/imageUpload', { | ||
method: 'POST', | ||
body: formData, | ||
}); | ||
// const response = await fetch('/api/imageUpload', { | ||
// method: 'POST', | ||
// body: formData, | ||
// }); | ||
|
||
if (!response.ok) { | ||
const errorData: ErrorResponse = await response.json(); | ||
setErrorMessage(errorData.error); | ||
return; | ||
} | ||
// if (!response.ok) { | ||
// const errorData: ErrorResponse = await response.json(); | ||
// setErrorMessage(errorData.error); | ||
// return; | ||
// } | ||
|
||
const data: ImageUploadResponsePost | ErrorResponse = await response.json(); | ||
// const data: ImageUploadResponsePost | ErrorResponse = await response.json(); | ||
|
||
if ('error' in data) { | ||
setErrorMessage(data.error); | ||
return; | ||
} | ||
// if ('error' in data) { | ||
// setErrorMessage(data.error); | ||
// return; | ||
// } | ||
|
||
router.refresh(); | ||
// router.refresh(); | ||
|
||
setSuccessMessage('Image uploaded successfully'); | ||
} | ||
// setSuccessMessage('Image uploaded successfully'); | ||
// } | ||
|
||
return ( | ||
<div> | ||
{!!successMessage && <p>{successMessage}</p>} | ||
<strong>{formTitle}</strong> | ||
<form onSubmit={handleUpload}> | ||
<label> | ||
Select Image: | ||
<input type="file" name="image" accept="image/*" /> | ||
</label> | ||
<SubmitButton buttonTitle={buttonTitle} /> | ||
</form> | ||
{!!errorMessage && <ErrorMessage>{errorMessage}</ErrorMessage>} | ||
</div> | ||
); | ||
} | ||
// return ( | ||
// <div> | ||
// {!!successMessage && <p>{successMessage}</p>} | ||
// <strong>{formTitle}</strong> | ||
// <form onSubmit={handleUpload}> | ||
// <label> | ||
// Select Image: | ||
// <input type="file" name="image" accept="image/*" /> | ||
// </label> | ||
// <SubmitButton buttonTitle={buttonTitle} /> | ||
// </form> | ||
// {!!errorMessage && <ErrorMessage>{errorMessage}</ErrorMessage>} | ||
// </div> | ||
// ); | ||
// } |