Skip to content

Commit

Permalink
fix more eslint errors temporarily
Browse files Browse the repository at this point in the history
  • Loading branch information
Draikth committed Jul 25, 2024
1 parent 8693191 commit fb346bd
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 94 deletions.
80 changes: 40 additions & 40 deletions app/api/postedEvents/deleteEvent/route.ts
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 },
// );
// }
// }
108 changes: 54 additions & 54 deletions app/imageUpload/ImageForm.tsx
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>
// );
// }

0 comments on commit fb346bd

Please sign in to comment.