Skip to content

Commit 73d7fb3

Browse files
committedJun 23, 2023
feat: added helper for airtable Api
1 parent 4a2fd50 commit 73d7fb3

File tree

6 files changed

+1109
-3175
lines changed

6 files changed

+1109
-3175
lines changed
 

‎pnpm-lock.yaml

+1,058-3,156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/pages/api/airtableData.js

-12
This file was deleted.

‎src/pages/api/airtableData.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { FieldSet, Table } from 'airtable';
2+
import { AirtableBase } from 'airtable/lib/airtable_base';
3+
import { NextApiRequest, NextApiResponse } from 'next';
4+
import { getDatabase } from '../../util/getDatabase';
5+
export default async function handler(
6+
req: NextApiRequest,
7+
res: NextApiResponse
8+
) {
9+
10+
const data: any[] = [];
11+
const base: AirtableBase = getDatabase();
12+
const table: Table<FieldSet> = base("XP Summary");
13+
table.select({
14+
// Selecting the first 3 records in XP by skill:
15+
// maxRecords: 10,
16+
fields: ["Name", "Person Type", "Region", "Total XP", "XP (Project)", "XP (Indie)", "Ops XP", "CAB XP", "Bounty XP",],
17+
view: "XP by work type"
18+
}).eachPage(function page(records, fetchNextPage) {
19+
// This function (`page`) will get called for each page of records.
20+
let n = 0;
21+
records.forEach(function (record) {
22+
n++;
23+
// console.log('Retrieved', record.fields);
24+
data.push(record.fields);
25+
});
26+
console.log("Total number of contributers ", n)
27+
28+
// To fetch the next page of records, call `fetchNextPage`.
29+
// If there are more records, `page` will get called again.
30+
// If there are no more records, `done` will get called.
31+
fetchNextPage();
32+
res.json(data)
33+
34+
}, function done(err) {
35+
if (err) { console.error(err); return; }
36+
});
37+
38+
39+
}

‎src/pages/index.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,17 @@ import { Container } from '@chakra-ui/react';
22
import axios from 'axios';
33
import React from 'react';
44
import config from '../../config/general.config';
5-
import DashboardHeader from '../components/Dashboard/DashboardHeader';
65
import LeaderBoardWrapper from '../components/Dashboard/LeaderBoardWrapper';
76
import SEO from '../components/SEO/SEO';
8-
import { receivedXPFromAirtableType } from '../interfaces/airtableRecievedXP';
97
import { dashboardDataType } from '../interfaces/dashboardStore';
108
import { SortByXp } from '../util/sortingData';
119

1210
export default function Home(props: {
1311
dashboardData: dashboardDataType[];
1412
bountyDataJson: any;
15-
lastSevenDaysData: receivedXPFromAirtableType[];
13+
// lastSevenDaysData: receivedXPFromAirtableType[];
1614
}) {
17-
const { dashboardData, lastSevenDaysData } = props;
15+
const { dashboardData } = props;
1816
console.log('dash data - ', dashboardData.length);
1917
// console.log('last seven days data - ', lastSevenDaysData);
2018
// search functionality
@@ -50,9 +48,9 @@ export default function Home(props: {
5048
/>
5149
<main>
5250
<Container maxW="full" p="0">
53-
<DashboardHeader
51+
{/* <DashboardHeader
5452
lastSevenDaysData={lastSevenDaysData}
55-
/>
53+
/> */}
5654
<LeaderBoardWrapper
5755
searchResult={searchResult}
5856
dashboardData={data}

‎src/util/getDatabase.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Airtable from 'airtable';
2+
3+
export function getDatabase() {
4+
return new Airtable({ apiKey: process.env.AIRTABLE_API_KEY }).base(
5+
process.env.AIRTABLE_BASE_ID!
6+
);
7+
}

‎tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"next-env.d.ts",
2020
"**/*.ts",
2121
"**/*.tsx",
22-
"src/pages/api/airtableData.js"
22+
"src/pages/api/airtableData.ts"
2323
],
2424
"exclude": ["node_modules"]
2525
}

0 commit comments

Comments
 (0)
Please sign in to comment.