Last active
January 30, 2025 03:34
-
-
Save mennwebs/0c7e7df8dfbf86500c57a7c88aad9483 to your computer and use it in GitHub Desktop.
Grist API with Next.js for Salary & Team Data
This file contains hidden or 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
// Please check https://github.com/gristlabs/grist-api | |
import { GristDocAPI } from 'grist-api' | |
export default async function Page() { | |
const DOC_URL = process.env.GRIST_DOC_URL | |
const API_KEY = process.env.GRIST_API_KEY | |
const api = new GristDocAPI(DOC_URL, { apiKey: API_KEY }) | |
const salary_data = await api.fetchTable('Salary') | |
const team_data = await api.fetchTable('Team') | |
const team = salary_data.map((person) => { | |
const team = team_data.find((t) => t.id === person.Team) | |
return { ...person, ...team } | |
}) | |
// console.log(team) | |
if (!team) { | |
return { | |
notFound: true, | |
} | |
} | |
return ( | |
<> | |
{/* TEAM DATA */} | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment