From 72ca4e5139e18f4fe8bc0ce0aff07fc3210c02e4 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:51:46 -0400 Subject: [PATCH 01/23] chore: add swr and cors libs for fetching and middleware --- package-lock.json | 55 +++++++++++++++++++++++++++++++++++++++++++++-- package.json | 11 ++++++---- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 54b2ab0..57833ad 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,11 +8,14 @@ "name": "my-app", "version": "0.1.0", "dependencies": { + "cors": "^2.8.5", "next": "14.2.5", "react": "^18", - "react-dom": "^18" + "react-dom": "^18", + "swr": "^2.2.5" }, "devDependencies": { + "@types/cors": "^2.8.17", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", @@ -432,6 +435,15 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -1101,6 +1113,18 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", @@ -3238,7 +3262,6 @@ "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", - "dev": true, "engines": { "node": ">=0.10.0" } @@ -4387,6 +4410,18 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/swr": { + "version": "2.2.5", + "resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz", + "integrity": "sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==", + "dependencies": { + "client-only": "^0.0.1", + "use-sync-external-store": "^1.2.0" + }, + "peerDependencies": { + "react": "^16.11.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/tailwindcss": { "version": "3.4.6", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.6.tgz", @@ -4647,12 +4682,28 @@ "punycode": "^2.1.0" } }, + "node_modules/use-sync-external-store": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz", + "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", "dev": true }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 49255b4..2469f57 100644 --- a/package.json +++ b/package.json @@ -9,18 +9,21 @@ "lint": "next lint" }, "dependencies": { + "cors": "^2.8.5", + "next": "14.2.5", "react": "^18", "react-dom": "^18", - "next": "14.2.5" + "swr": "^2.2.5" }, "devDependencies": { - "typescript": "^5", + "@types/cors": "^2.8.17", "@types/node": "^20", "@types/react": "^18", "@types/react-dom": "^18", + "eslint": "^8", + "eslint-config-next": "14.2.5", "postcss": "^8", "tailwindcss": "^3.4.1", - "eslint": "^8", - "eslint-config-next": "14.2.5" + "typescript": "^5" } } From e1830e0d25e5a1dc02826b4fe3b219cfbf982909 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:52:12 -0400 Subject: [PATCH 02/23] feat: middleware to post req to workday --- src/pages/api/opportunities.ts | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/pages/api/opportunities.ts diff --git a/src/pages/api/opportunities.ts b/src/pages/api/opportunities.ts new file mode 100644 index 0000000..2632c93 --- /dev/null +++ b/src/pages/api/opportunities.ts @@ -0,0 +1,61 @@ +import type { NextApiRequest, NextApiResponse } from "next"; +import Cors from "cors"; + +// Initializing the cors middleware +// You can read more about the available options here: https://github.com/expressjs/cors#configuration-options +const cors = Cors({ + methods: ["POST", "GET", "HEAD"], +}); + +// Helper method to wait for a middleware to execute before continuing +// And to throw an error when an error happens in a middleware +function runMiddleware( + req: NextApiRequest, + res: NextApiResponse, + fn: Function, +) { + return new Promise((resolve, reject) => { + fn(req, res, (result: any) => { + if (result instanceof Error) { + return reject(result); + } + + return resolve(result); + }); + }); +} + +export default async function handler( + req: NextApiRequest, + res: NextApiResponse, +) { + // Run the middleware + await runMiddleware(req, res, cors); + const myHeaders = new Headers(); + myHeaders.append("Content-Type", "application/json"); + myHeaders.append( + "Cookie", + "PLAY_SESSION=9365d69619d226b22f74256e51894a0476197a1f-instance=vps-prod-tvvtdnej.prod-vps.pr501.cust.pdx.wd; __cf_bm=zYtKNPBpg6veqmLc2qdk_TeHEGdGWIcSRG9tdtkQNbQ-1721323439-1.0.1.1-TApbCV1fQKTtEauZKvZ5XnXrZQJL7dcML6ixA3AycoiBMROa.iAzMq_K.5E7iaZfCj9.WhQQlmYfAxW8wdwZgQ; __cflb=02DiuHJZe28xXz6hQKLf1exjNbMDM5uxekNnt7kFV7LUC; _cfuvid=hqIGrDcFihah5EiFO0c_HEM4gIPwkeWCOxjMxNqjR20-1721323439159-0.0.1.1-604800000; wd-browser-id=fc0f0b1d-4547-488d-b353-99c751c61dae; wday_vps_cookie=1122671626.53810.0000", + ); + + const raw = JSON.stringify({ + limit: 20, + offset: 0, + appliedFacets: {}, + searchText: "180 George Street", + }); + + const requestOptions = { + method: "POST", + headers: myHeaders, + body: raw, + redirect: "follow", + }; + + const response = await fetch( + "https://brown.wd5.myworkdayjobs.com/wday/cxs/brown/staff-careers-brown/jobs", + requestOptions, + ); + const json = await response.json(); + res.json(json); +} From 98b1a1852d57866796d9b75cfdde6ea36c0de629 Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Fri, 2 Aug 2024 15:52:30 -0400 Subject: [PATCH 03/23] feat: workday data on about page --- src/components/Card.tsx | 9 ++++ src/components/Opportunities.tsx | 81 ++++++++++++++++++++++++++++++++ src/pages/about.tsx | 10 +++- 3 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/components/Card.tsx create mode 100644 src/components/Opportunities.tsx diff --git a/src/components/Card.tsx b/src/components/Card.tsx new file mode 100644 index 0000000..75cd497 --- /dev/null +++ b/src/components/Card.tsx @@ -0,0 +1,9 @@ +import React from "react"; + +interface CardProps { + children?: React.ReactNode; +} + +export const Card: React.FC = ({ children }) => { + return
{children}
; +}; diff --git a/src/components/Opportunities.tsx b/src/components/Opportunities.tsx new file mode 100644 index 0000000..53e483b --- /dev/null +++ b/src/components/Opportunities.tsx @@ -0,0 +1,81 @@ +"use client"; +import React, { useState, useEffect } from "react"; +import { Card } from "@/components/Card"; + +interface OpportunityProps { + total: number; + jobPostings: PositionProps[]; + facets: Object[]; + userAuthenticated: boolean; +} + +interface PositionProps { + title: string; + externalPath: string; + locationsText: string; + postedOn: string; + bulletFields: string[]; +} + +export const Opportunities: React.FC = () => { + const initialData = { + total: 0, + jobPostings: [], + userAuthenticated: false, + facets: [], + }; + const [data, setData] = useState(initialData); + const [isLoading, setLoading] = useState(true); + + useEffect(() => { + fetch("/api/opportunities") + .then((res) => res.json()) + .then((data) => { + setData(data); + setLoading(false); + }); + }, []); + + if (isLoading) return

Loading...

; + if (!data) return

No profile data

; + + return ( +
+ {data.jobPostings.length > 0 && + data.jobPostings.map((position) => { + return ( +
+

+ Opportunities +

+ +
+
+ Providence, RI - United States +

{position.title}

+
+ +
+

+ Learn More + + + +

+
+
+
+
+
+ ); + })} +
+ ); +}; diff --git a/src/pages/about.tsx b/src/pages/about.tsx index ac51f1f..16d97f1 100644 --- a/src/pages/about.tsx +++ b/src/pages/about.tsx @@ -1,3 +1,9 @@ +import { Opportunities } from "@/components/Opportunities"; + export default function About() { - return
About
-} \ No newline at end of file + return ( +
+ +
+ ); +} From 4e897092b5bbbbf441d9bdc36be9be6690068b0d Mon Sep 17 00:00:00 2001 From: Heather Yu <35639529+hetd54@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:22:43 -0500 Subject: [PATCH 04/23] refactor: app routing --- {src/pages => app}/api/opportunities.ts | 0 app/layout.tsx | 6 +- {src/components => components}/Card.tsx | 0 .../Opportunities.tsx | 48 +- package-lock.json | 1208 ++++++++++++++++- package.json | 19 +- 6 files changed, 1226 insertions(+), 55 deletions(-) rename {src/pages => app}/api/opportunities.ts (100%) rename {src/components => components}/Card.tsx (100%) rename {src/components => components}/Opportunities.tsx (79%) diff --git a/src/pages/api/opportunities.ts b/app/api/opportunities.ts similarity index 100% rename from src/pages/api/opportunities.ts rename to app/api/opportunities.ts diff --git a/app/layout.tsx b/app/layout.tsx index cc14a44..8bc608b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -18,8 +18,10 @@ export default function RootLayout({ }>) { return ( - {children} -