-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.tsx
41 lines (33 loc) · 982 Bytes
/
page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"use client";
import { useTranslations } from "next-intl";
import { notFound } from "next/navigation";
import { Link } from "@/i18n/routing";
import { userService } from "@/modules/user/user.service";
import { routes } from "@/routes";
import { useQuery } from "@tanstack/react-query";
export default function UsersPage() {
const t = useTranslations();
const { data, isError, isLoading } = useQuery({
queryKey: [userService.key],
queryFn: () => userService.get(),
});
if (isError) return <div>{t("sentences.somethingWentWrong")}</div>;
if (isLoading) return <div>{t("words.loading")}...</div>;
if (!data) {
notFound();
}
return (
<div className="prose dark:prose-invert">
<h1>Users</h1>
<ul>
{data.map((user) => (
<li key={user.id}>
<button>
<Link href={routes.reactQuery.user(user.id)}>{user.name}</Link>
</button>
</li>
))}
</ul>
</div>
);
}