Skip to content

Commit

Permalink
Fix lint and format
Browse files Browse the repository at this point in the history
  • Loading branch information
qvd808 committed Jul 16, 2024
1 parent 4a72d9b commit c504fe9
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 178 deletions.
65 changes: 32 additions & 33 deletions src/app/(ui)/(volunteer)/checkin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,27 @@
import FormInput from "@/components/FormInput";
import VolunteerCard from "./components/VolunteerCard";
import ShiftSelect from "./components/ShiftSelect";
import { useEffect, useState } from "react";
// import Post from "../../../api/checkin/route"

export default function Checkin() {
async function findVolunteer(formData: FormData) {
const userName = formData.get("Username");

const [checkInUser, setCheckInUser] = useState([])
const [volunteers, setVolunteers] = useState([])
const [inputText, setInputText] = useState("TEXT")

async function findVolunteer(formData: FormData) {
const userName = formData.get('Username');

try {
const response = await fetch("/api/checkin", {
method: "POST",
body: JSON.stringify({
userName: userName
})
})
if (response.ok) {
const result = await response.json()
console.log(result)
}
} catch (error) {
console.log(error);
}

}
try {
const response = await fetch("/api/checkin", {
method: "POST",
body: JSON.stringify({
userName: userName
})
});
if (response.ok) {
const result = await response.json();
console.log(result);
}
} catch (error) {
console.log(error);
}
}

const mockInfo = [
{
Expand All @@ -48,26 +41,32 @@ export default function Checkin() {
];
return (
<div className="flex flex-col">
<form className="flex justify-between gap-20 px-20 py-10" action = {findVolunteer} >
<form
className="flex justify-between gap-20 px-20 py-10"
action={findVolunteer}
>
<FormInput label="Username" type="text" placeholder="TEXT" />
<ShiftSelect />
<button type="submit" className="min-w-[200px]" >
<button type="submit" className="min-w-[200px]">
Check In
</button>
</form>
{mockInfo.map(
(item: {
firstName: string;
lastName: string;
timeIn: string;
shift: string;
}, idx) => (
(
item: {
firstName: string;
lastName: string;
timeIn: string;
shift: string;
},
idx
) => (
<VolunteerCard
firstName={item.firstName}
lastName={item.lastName}
timeIn={item.timeIn}
shift={item.shift}
key = {idx}
key={idx}
/>
)
)}
Expand Down
12 changes: 6 additions & 6 deletions src/app/api/change-access-code/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { NextResponse, NextRequest } from "next/server";
import { createClient } from "@supabase/supabase-js";

export const POST = async (request: NextRequest) => {
export default async function POST(request: NextRequest) {
const supabaseUrl = process.env.NEXT_APP_SUPABASE_URL as string;
const key = process.env.SUPABASE_KEY as string;

const { new_code } = await request.json();
const { newCode } = await request.json();

if (!new_code) {
if (!newCode) {
return NextResponse.json({
message: "Please provided an access code"
});
Expand All @@ -19,11 +19,11 @@ export const POST = async (request: NextRequest) => {
.from("access_codes")
.update({
created_at: new Date().toISOString(),
access_code: new_code
access_code: newCode
})
.eq("id", 1);

if (error) {
if (error || !data) {
return NextResponse.json({ message: error }, { status: 500 });
}

Expand All @@ -36,4 +36,4 @@ export const POST = async (request: NextRequest) => {
} catch (error) {
return NextResponse.json({ message: error }, { status: 500 });
}
};
}
6 changes: 3 additions & 3 deletions src/app/api/checkin/route.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMocks } from "node-mocks-http";
import { NextApiRequest } from "next/types";
import POST from "./route";
import { POST } from "./route";

jest.mock("@supabase/supabase-js", () => ({
createClient: jest.fn(() => ({
Expand All @@ -22,7 +22,7 @@ describe("Check-in API Route", () => {
req = mockReq as unknown as NextApiRequest;
});

it("should return 400 if email or shiftId is missing", async () => {
it("should return 400 if userName or shiftId is missing", async () => {
const mockReq = {
...req,
json: async () => ({})
Expand All @@ -32,7 +32,7 @@ describe("Check-in API Route", () => {

expect(response.status).toBe(400);
expect(await response.json()).toEqual({
error: "Email and Shift ID are required"
message: "Please provide a username and a shiftID"
});
});
});
Loading

0 comments on commit c504fe9

Please sign in to comment.