Fix project show api endpoint

This commit is contained in:
Max Wofford 2024-08-16 14:08:35 -04:00
parent dbb6cc80b7
commit 33ec07c40d
2 changed files with 26 additions and 14 deletions

View file

@ -2,21 +2,23 @@ import AirtablePlus from "airtable-plus";
import { ensureAuthed } from "../login/test";
export default async function handler(req, res) {
const { ID } = req.query
const user = await ensureAuthed(req)
const user = await ensureAuthed(req)
if (user.error) {
return res.status(401).json(user)
}
const airtable = new AirtablePlus({
apiKey: process.env.AIRTABLE_API_KEY,
baseID: 'app4kCWulfB02bV8Q',
apiKey: process.env.AIRTABLE_API_KEY,
baseID: 'app4kCWulfB02bV8Q',
tableName: "Showcase"
})
const { projectID } = req.query
const project = await airtable.read({
filterByFormula: `AND({User} = '${user.fields['Name']}', {ID} = '${ID}')`
})
filterByFormula: `AND({User} = '${user.fields['Name']}', RECORD_ID() = '${projectID}')`,
maxRecords: 1
})
const results = project.map(p => ({
id: p.id,

View file

@ -1,19 +1,16 @@
import React from 'react'
import { useEffect, useState } from 'react'
import { useRouter } from 'next/router';
import CohortCard from '../../../../../components/arcade/showcase/cohort-card'
const Page = ({ projectID }) => {
const Page = () => {
const router = useRouter();
const { id } = router.query;
console.log({ projectID })
const [project, setProject] = useState([])
const [status, setStatus] = useState('loading')
const [errorMsg, setError] = useState(null)
useEffect(async () => {
const token = window.localStorage.getItem('arcade.authToken')
const response = await fetch(`/api/arcade/showcase/projects/${id}`, {
const response = await fetch(`/api/arcade/showcase/projects/${projectID}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${token}`
@ -28,7 +25,7 @@ const Page = () => {
setStatus('error')
return
} else {
setProjects(data.projects)
setProject(data.projects)
setStatus('success')
}
}, [])
@ -50,4 +47,17 @@ const Page = () => {
)
}
export default Page
export default Page
export async function getStaticPaths() {
return {
paths: [],
fallback: 'blocking'
}
}
export async function getStaticProps({params}) {
const { projectID } = params
console.log({ params })
return { props: { projectID } }
}