Skip to content

Commit

Permalink
feat: 참석여부 리스트 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
Gukhee Jo committed Jul 22, 2024
1 parent ed9ee80 commit 12c8218
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"use client";

import { useQuery } from "@tanstack/react-query";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "~/components/ui/card";
import type { InvitationResponse } from "~/lib/db/schema/invitation_response";
import { getAllInvitationResponses } from "~/lib/db/schema/invitation_response.query";

export default function InvitationResponseList() {
const { data, isLoading, error } = useQuery<InvitationResponse[]>({
queryKey: ["invitationResponses"],
queryFn: () => getAllInvitationResponses(),
});

if (isLoading) return <div>로딩중...</div>;
if (error) return <div>에러가 발생했습니다: {error.message}</div>;
if (!data || data.length === 0) return <div>데이터를 찾을 수 없습니다.</div>;

return (
<div className="grid grid-cols-3 gap-2">
{data.map((response) => (
<Card key={response.id}>
<CardHeader>
<CardTitle>{response.participant_name}</CardTitle>
<CardDescription>
{response.attendance ? "참석" : "불참"}
</CardDescription>
</CardHeader>
<CardContent>
<CardDescription>ID: {response.id}</CardDescription>
<CardDescription>사유: {response.reason || "없음"}</CardDescription>
<CardDescription>
생성일: {new Date(response.created_at).toLocaleString()}
</CardDescription>
</CardContent>
</Card>
))}
</div>
);
}
29 changes: 29 additions & 0 deletions src/app/(playground)/playground/invitation-response/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {
dehydrate,
HydrationBoundary,
QueryClient,
} from "@tanstack/react-query";
import { cache } from "react";
import { ALink, AMain } from "~/app/(playground)/playground/inner-tools";
import InvitationResponseList from "~/app/(playground)/playground/invitation-response/invitation-response-list";
import { getAllInvitationResponses } from "~/lib/db/schema/invitation_response.query";

const getQueryClient = cache(() => new QueryClient());

export default async function Page() {
const queryClient = getQueryClient();

await queryClient.prefetchQuery({
queryKey: ["invitationResponses"],
queryFn: getAllInvitationResponses,
});

return (
<HydrationBoundary state={dehydrate(queryClient)}>
<AMain>
<ALink href="/playground">playground</ALink>
<InvitationResponseList />
</AMain>
</HydrationBoundary>
);
}
8 changes: 8 additions & 0 deletions src/lib/db/schema/invitation_response.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"use server";

import { db } from "~/lib/db";
import { invitationResponses } from "~/lib/db/schema/invitation_response";

export async function getAllInvitationResponses() {
return db.select().from(invitationResponses);
}

0 comments on commit 12c8218

Please sign in to comment.