Skip to content

Commit

Permalink
Merge pull request #22 from cherylli/dev
Browse files Browse the repository at this point in the history
merge dev into main
  • Loading branch information
cherylli authored Mar 11, 2024
2 parents 3e802fa + 1b880de commit 7581889
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 228 deletions.
10 changes: 9 additions & 1 deletion src/app/solo-project/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import {getSoloProjectById, setEvaluatorOnDb, updateSoloProjectById} from "@/services/soloProjects";
import {
getAllSoloProjectsByUser,
getSoloProjectById,
setEvaluatorOnDb,
updateSoloProjectById
} from "@/services/soloProjects";
import ProjectSubmissionDetail from "@/components/soloprojects/Details";
import {ActionResponse} from "@/types";
import Comments from "@/components/comments";
import FeedbackContainer from "@/components/feedback/FeedbackContainer";
import CompactList from "@/components/soloprojects/CompactList";

const SoloProjectPage = async ({params}: { params: { id: string } }) => {
const record = await getSoloProjectById(params.id)
const projects = await getAllSoloProjectsByUser(record.fields["Discord ID"], record.fields.Email)
const handleSave = async (evalFeedback: string, evalStatus: string): Promise<ActionResponse> => {
'use server'
return await updateSoloProjectById(params.id, {
Expand All @@ -20,6 +27,7 @@ const SoloProjectPage = async ({params}: { params: { id: string } }) => {
return(
<div className="flex flex-col lg:flex-row-reverse justify-between h-screen">
<div className="lg:w-1/2 lg:overflow-y-auto">
{projects.length>1 && <CompactList records={projects}/>}
<ProjectSubmissionDetail
record={record}
handleSave={handleSave}
Expand Down
22 changes: 22 additions & 0 deletions src/components/soloprojects/CompactList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {Submission} from "@/types/SoloProjectTypes";
import {Table, TableBody, TableCell, TableRow} from "@/components/ui/table";
import Link from "next/link";

const CompactList = ({records}:{records:Submission[]}) => {
return(
<Table className="w-[90%] mx-auto border-2 border-amber-950">
<TableBody>
{records.map(record=>(
<TableRow key={record.id}>
<Link href={`/solo-project/${record.id}`} target="_blank" rel="noopener noreferrer">
<TableCell>{record.fields.Timestamp.toString()}</TableCell>
<TableCell>{record.fields["Evaluation Status"]}</TableCell>
</Link>
</TableRow>
))}
</TableBody>
</Table>
)
}

export default CompactList
5 changes: 3 additions & 2 deletions src/components/soloprojects/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ActionResponse} from "@/types";
import {CopyToClipboard} from "react-copy-to-clipboard";
import {toast} from "react-hot-toast";
import {getRandomPassMessage} from "@/lib/getRandomPassMessage";
import {parseRole} from "@/lib/parseRole";

interface ProjectDetailProps {
record: Submission,
Expand Down Expand Up @@ -119,8 +120,8 @@ const ProjectSubmissionDetail = (

{record.fields["Voyage Role (from Applications link)"] ?
<div
className={`text-center ${roleColors[record.fields["Voyage Role (from Applications link)"]].bg} py-1 mt-3`}>
{record.fields["Voyage Role (from Applications link)"]}
className={`text-center ${roleColors[parseRole(record.fields["Voyage Role (from Applications link)"])]?.bg} py-1 mt-3`}>
{parseRole(record.fields["Voyage Role (from Applications link)"])}
</div>:
<div className="text-center text-gray-800 bg-gray-300 py-1 mt-3">No Role Selected</div>
}
Expand Down
141 changes: 63 additions & 78 deletions src/lib/airtable.ts
Original file line number Diff line number Diff line change
@@ -1,79 +1,64 @@
import Airtable, {FieldSet, Record, Records} from "airtable";
import {EvaluationStatus, Submission, VoyageRole} from "@/types/SoloProjectTypes";

const base = new Airtable({apiKey: process.env.AIRTABLE_PAT})
.base(process.env.AIRTABLE_BASEID as string)

const table = base(process.env.AIRTABLE_TABLEID as string)
const userTable = base(process.env.AIRTABLE_USERS_TABLEID as string)

const fields = [
"Discord Name",
"GitHub ID",
"Timestamp",
"Tier",
"GitHub Repo URL",
"Deployed App URL",
"Evaluation Status",
"Evaluator",
"Evaluation Feedback",
"Instructions",
"Addl. Comments",
"Voyage Role (from Applications link)",
"Discord ID"
]

const transformData = (records:Records<FieldSet>): Submission[] => {
return records.map((record: Record<FieldSet>)=>{
return {
id: record.id,
commentCount: record.commentCount as number,
fields: {
"Discord Name": record.fields["Discord Name"] as string,
"GitHub ID": record.fields["GitHub ID"] as string,
"Timestamp": record.fields["Timestamp"] as string,
"Tier": record.fields["Tier"] as string,
"GitHub Repo URL": record.fields["GitHub Repo URL"] as string,
"Deployed App URL": record.fields["Deployed App URL"] as string,
"Evaluation Status": record.fields["Evaluation Status"] as EvaluationStatus,
"Evaluator": record.fields["Evaluator"] as string,
"Evaluation Feedback": record.fields["Evaluation Feedback"] as string,
"Instructions": record.fields["Instructions"] as string,
"Addl. Comments": record.fields["Addl. Comments"] as string,
"Voyage Role (from Applications link)": record.fields["Voyage Role (from Applications link)"] as VoyageRole,
"Discord ID": record.fields["Discord ID"] as string
}
}
})
}

// TODO: might be able to refactor the following duplicated code
const transformDataSingleRecord = (record:Record<FieldSet>) => {
return {
id: record.id,
commentCount: record.commentCount as number,
fields: {
"Discord Name": record.fields["Discord Name"] as string,
"GitHub ID": record.fields["GitHub ID"] as string,
"Timestamp": record.fields["Timestamp"] as string,
"Tier": record.fields["Tier"] as string,
"GitHub Repo URL": record.fields["GitHub Repo URL"] as string,
"Deployed App URL": record.fields["Deployed App URL"] as string,
"Evaluation Status": record.fields["Evaluation Status"] as EvaluationStatus,
"Evaluator": record.fields["Evaluator"] as string,
"Evaluation Feedback": record.fields["Evaluation Feedback"] as string,
"Instructions": record.fields["Instructions"] as string,
"Addl. Comments": record.fields["Addl. Comments"] as string,
"Voyage Role (from Applications link)": record.fields["Voyage Role (from Applications link)"] as VoyageRole,
"Discord ID": record.fields["Discord ID"] as string
}
}
}

export {
table,
userTable,
fields,
transformData,
transformDataSingleRecord
import Airtable, {FieldSet, Record, Records} from "airtable";
import {EvaluationStatus, Submission, VoyageRole} from "@/types/SoloProjectTypes";

const base = new Airtable({apiKey: process.env.AIRTABLE_PAT})
.base(process.env.AIRTABLE_BASEID as string)

const table = base(process.env.AIRTABLE_TABLEID as string)
const userTable = base(process.env.AIRTABLE_USERS_TABLEID as string)

const fields = [
"Email",
"Discord Name",
"GitHub ID",
"Timestamp",
"Tier",
"GitHub Repo URL",
"Deployed App URL",
"Evaluation Status",
"Evaluator",
"Evaluation Feedback",
"Instructions",
"Addl. Comments",
"Voyage Role (from Applications link)",
"Discord ID"
]

const transformRecord = (record: Record<FieldSet>) => {
return {
id: record.id,
commentCount: record.commentCount as number,
fields: {
"Email": record.fields["Email"] as string,
"Discord Name": record.fields["Discord Name"] as string,
"GitHub ID": record.fields["GitHub ID"] as string,
"Timestamp": record.fields["Timestamp"] as string,
"Tier": record.fields["Tier"] as string,
"GitHub Repo URL": record.fields["GitHub Repo URL"] as string,
"Deployed App URL": record.fields["Deployed App URL"] as string,
"Evaluation Status": record.fields["Evaluation Status"] as EvaluationStatus,
"Evaluator": record.fields["Evaluator"] as string,
"Evaluation Feedback": record.fields["Evaluation Feedback"] as string,
"Instructions": record.fields["Instructions"] as string,
"Addl. Comments": record.fields["Addl. Comments"] as string,
"Voyage Role (from Applications link)": record.fields["Voyage Role (from Applications link)"] as VoyageRole,
"Discord ID": record.fields["Discord ID"] as string
}
}
}

const transformData = (records:Records<FieldSet>): Submission[] => {
return records.map((record: Record<FieldSet>)=>transformRecord(record))
}

const transformDataSingleRecord = (record:Record<FieldSet>) => {
return transformRecord(record)
}

export {
table,
userTable,
fields,
transformData,
transformDataSingleRecord
}
11 changes: 11 additions & 0 deletions src/lib/parseRole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Sometimes on airtable, VoyageRole would be something like ["Software Developer", "Software Developer"]
// due to members having multiple applications
// IF the roles are the same, it will just return one - for `roleColors`
// Otherwise, it will return "unknown"
import {VoyageRole} from "@/types/SoloProjectTypes";

export const parseRole = (role: VoyageRole): VoyageRole => {
const set = new Set(role)
if (set.size === 1) return [...set].toString() as VoyageRole
return "unknown"
}
Loading

0 comments on commit 7581889

Please # to comment.