-
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
Gukhee Jo
committed
Jul 22, 2024
1 parent
ed9ee80
commit 12c8218
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
src/app/(playground)/playground/invitation-response/invitation-response-list.tsx
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 |
---|---|---|
@@ -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
29
src/app/(playground)/playground/invitation-response/page.tsx
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 |
---|---|---|
@@ -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> | ||
); | ||
} |
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 |
---|---|---|
@@ -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); | ||
} |