Skip to content

Ticket 116 - mockup for API call #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions template/{{app_name}}/src/api/MembersApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const baseUrl: string = 'https://63d006cc8a780ae6e681fea9.mockapi.io/api/members';

export interface Member {
firstName: any;
lastName: string;
description: string;
favoriteFruit: string;
}

export const MembersApi = {
getMembers: async (): Promise<Member[]> => {
const response = await fetch(baseUrl);
if (!response.ok) {
throw new Error('Failed to fetch members data');
}
return response.json();
},
};
36 changes: 35 additions & 1 deletion template/{{app_name}}/src/app/[locale]/health/page.tsx
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) The "health" page is often used to make sure the application is working, think we still use that on grants.gov https://github.com/HHS/simpler-grants-gov/blob/main/frontend/src/app/%5Blocale%5D/health/page.tsx . I would recommend keeping it as is and creating a separate page for this.

Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
'use client'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) This means the whole may be rendered in the client. Alternatively the members list could be a client component that the page uses so the page could still be rendered server side.


import { Member, MembersApi } from "src/api/MembersApi";
import React, { useEffect, useState } from "react";

export default function Page() {
return <>healthy</>;
const [members, setMembers] = useState<Member[]>([]);
Copy link
Member

@acouch acouch May 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have an error and loading states.


const getMembers = async () => {
try {
const members = await MembersApi.getMembers();
setMembers(members);
console.log(members);
} catch (error) {
console.error(error);
}
};

useEffect(() => {
getMembers();
}, []);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getMembers should be a dependency


return (
<React.Fragment>
<h1>Members</h1>
<ul>
{members.map((member, index) => (
<li key={index}>
<h2>{member.lastName}</h2>
<p>{member.description}</p>
<p>Favorite fruit: {member.favoriteFruit}</p>
</li>
))}
</ul>
</React.Fragment>
);
}