Skip to content

Commit

Permalink
feat: Init user page
Browse files Browse the repository at this point in the history
  • Loading branch information
rosethorn999 committed Oct 25, 2023
1 parent 2d2087b commit 51d5416
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
56 changes: 27 additions & 29 deletions src/app/[lng]/user/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
import { getUser, getUsers } from '@/app/apis/api';
import { getUsersSimple, getUserSimple } from '@/app/apis/api';
import { useTranslation } from '@/app/i18n';
import { Pagination, User } from '@/app/types/type';

export async function generateStaticParams() {
// FIXME: Need a super user role to access api or build will fail
const { results: users }: Pagination<User> = await getUsers();
const { results: users }: Pagination<User> = await getUsersSimple();
const ids = users.map((o) => {
return { id: o.id.toString() };
});
return ids;
}
export default async function Page({ params: { lng, id: userId } }: any) {
// TODO: TBD
// // eslint-disable-next-line react-hooks/rules-of-hooks
// const { t } = await useTranslation(lng, 'contracts');
// const user = await getUser(userId);
// const currency = 'NTD';
// const {
// email,
// is_active,
// is_superuser,
// is_verified,
// first_name,
// last_name,
// facebook_id,
// line_id,
// county,
// district,
// modify_time,
// birth_date,
// mobile,
// create_time,
// }: User = user;
return <h1>hello user {userId}</h1>;
// return (
// <h1>
// A user {first_name} come from {county}, joined {create_time}
// </h1>
// );
// eslint-disable-next-line react-hooks/rules-of-hooks
const { t } = await useTranslation(lng, 'contracts');
const user: User = await getUserSimple(userId);
const {
email,
first_name,
last_name,
mobile,
facebook_id,
line_id,
county,
district,
create_time,
last_login,
} = user;
return (
<>
<h1 className="text-2xl font-bold">{first_name}</h1>
<ul>
<li>who lived in {county}</li>
<li>joined since {create_time}</li>
<li>last login at {last_login}</li>
</ul>
</>
);
}
22 changes: 22 additions & 0 deletions src/app/apis/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,26 @@ async function getUser(id: string, abortController?: AbortController) {
.catch((error) => {});
return user;
}
async function getUsersSimple(abortController?: AbortController) {
const url = '/users-simple/';
const user = await basicRequest
.get<User[]>(url, { signal: abortController?.signal })
.then((response: any) => {
return response.data;
})
.catch((error) => {});
return user;
}
async function getUserSimple(id: string, abortController?: AbortController) {
const url = `/users-simple/${id}`;
const user = await basicRequest
.get<User>(url, { signal: abortController?.signal })
.then((response: any) => {
return response.data;
})
.catch((error) => {});
return user;
}
export {
host,
getContracts,
Expand All @@ -152,5 +172,7 @@ export {
getUserMe,
getUsers,
getUser,
getUsersSimple,
getUserSimple,
};
export default basicRequest;

0 comments on commit 51d5416

Please sign in to comment.