mirror of
https://github.com/System-End/site.git
synced 2026-04-20 00:25:19 +00:00
Delete api
This commit is contained in:
parent
6aea94a519
commit
e7bd3efbd7
4 changed files with 61 additions and 4 deletions
|
|
@ -6,7 +6,18 @@ import { Button } from 'theme-ui'
|
|||
|
||||
const CohortCard = ({ id, title = "Title Not Found", desc = "Description Not Found", slack = "Slack Not Found", scrapbook = "", playLink = "", images = [], githubProf, githubLink = "", draggable = false, personal = false}) => {
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
|
||||
|
||||
const handleDelete = async () => {
|
||||
const { status, formProps, useField, data } = useForm(
|
||||
`/api/arcade/showcase/projects/${project.id}/edit`,
|
||||
publishedChanges,
|
||||
{
|
||||
method: 'PATCH',
|
||||
initData: { ...project, recordId: project.id },
|
||||
bearer: window.localStorage.getItem('arcade.authToken')
|
||||
}
|
||||
)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +36,7 @@ const CohortCard = ({ id, title = "Title Not Found", desc = "Description Not Fou
|
|||
)}
|
||||
<a href={`/arcade/showcase/project/${id}`} className={styles.linkWrapper} target="_blank" rel="noopener noreferrer">
|
||||
<img
|
||||
src={firstImage}
|
||||
src={images[0] || "https://picsum.photos/200"}
|
||||
alt="Project Image"
|
||||
className={styles.card_img}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import styles from './project-view.module.css'
|
||||
import { Button } from 'theme-ui'
|
||||
|
||||
const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Found", slack = "Slack Not Found", scrapbook = "", playLink = "", images = [], githubProf, codeLink = ""}) => {
|
||||
const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Found", slack = "Slack Not Found", scrapbook = "", playLink, images = [], githubProf, codeLink = ""}) => {
|
||||
const codeHost = codeLink.includes('github') ? 'View on GitHub' : 'View code link'
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
|
|
@ -16,6 +16,7 @@ const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Fo
|
|||
<p className={styles.description}>{desc}</p>
|
||||
|
||||
<div className={styles.buttonGroup}>
|
||||
{playLink && (
|
||||
<Button
|
||||
as="a"
|
||||
sx={{ backgroundColor: '#1d571d', color: '#ebebeb', textSizeAdjust: "16px" }}
|
||||
|
|
@ -24,7 +25,9 @@ const ProjectView = ({ id, title = "Title Not Found", desc = "Description Not Fo
|
|||
rel="noopener"
|
||||
>
|
||||
Play Game
|
||||
</Button>
|
||||
</Button>)}
|
||||
|
||||
|
||||
<Button
|
||||
as="a"
|
||||
sx={{ backgroundColor: '#0f0f0f', color: '#ebebeb', textSizeAdjust: "16px" }}
|
||||
|
|
|
|||
43
pages/api/arcade/showcase/projects/[projectID]/delete.js
Normal file
43
pages/api/arcade/showcase/projects/[projectID]/delete.js
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import AirtablePlus from "airtable-plus";
|
||||
import { ensureAuthed } from "../../login/test";
|
||||
import { DefaultLegendContent } from "recharts";
|
||||
|
||||
export default async function handler(req, res) {
|
||||
const user = await ensureAuthed(req)
|
||||
if (user.error) {
|
||||
return res.status(401).json(user)
|
||||
}
|
||||
|
||||
const body = req.body
|
||||
if (!body) {
|
||||
return res.status(400).json({ error: "No body provided" })
|
||||
}
|
||||
|
||||
const updatedFields = {}
|
||||
updatedFields['deleted'] = true;
|
||||
|
||||
const airtable = new AirtablePlus({
|
||||
apiKey: process.env.AIRTABLE_API_KEY,
|
||||
baseID: 'app4kCWulfB02bV8Q',
|
||||
tableName: "Showcase"
|
||||
})
|
||||
|
||||
const { projectID } = req.query
|
||||
|
||||
const project = await airtable.update(projectID, updatedFields )
|
||||
|
||||
const results = {
|
||||
id: project.id,
|
||||
title: project.fields['Name'] || '',
|
||||
desc: project.fields['Description'] || '',
|
||||
slackLink: project.fields['Slack Link'] || '',
|
||||
codeLink: project.fields['Code Link'] || '',
|
||||
slackLink: project.fields['Slack Link'] || '',
|
||||
playLink: project.fields['Play Link'] || '',
|
||||
images: (project.fields['Screenshot'] || []).map(i => i.url),
|
||||
githubProf: project.fields['Github Profile'] || '',
|
||||
deleted: project.fields['deleted'] || ''
|
||||
}
|
||||
|
||||
return res.status(200).json({ project: results })
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@ export default async function handler(req, res) {
|
|||
})
|
||||
|
||||
const projects = await airtable.read({
|
||||
filterByFormula: `{User} = '${user.fields['Name']}'`
|
||||
filterByFormula: `AND({User} = '${user.fields['Name']}', NOT({deleted}))`
|
||||
})
|
||||
|
||||
const results = projects.map(p => ({
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue