From 73ff905b3b206a440b07afc0d5d7edff6297bcd1 Mon Sep 17 00:00:00 2001
From: fairlight <31534717+fairlighteth@users.noreply.github.com>
Date: Tue, 3 Sep 2024 13:36:46 +0100
Subject: [PATCH] feat(cow-fi): change greenhouse to ashbyhq (#4849)
(cherry picked from commit 966b1dac52af08ea3c7239539e340c9b1f8cf09b)
---
apps/cow-fi/const/meta.ts | 4 +-
apps/cow-fi/pages/careers/index.tsx | 48 ++++++++++-----
apps/cow-fi/services/ashByHq/index.ts | 78 ++++++++++++++++++++++++
apps/cow-fi/services/greenhouse/index.ts | 19 ------
4 files changed, 111 insertions(+), 38 deletions(-)
create mode 100644 apps/cow-fi/services/ashByHq/index.ts
delete mode 100644 apps/cow-fi/services/greenhouse/index.ts
diff --git a/apps/cow-fi/const/meta.ts b/apps/cow-fi/const/meta.ts
index 21c35dfcb3..d30c77cf97 100644
--- a/apps/cow-fi/const/meta.ts
+++ b/apps/cow-fi/const/meta.ts
@@ -33,9 +33,7 @@ export const CONFIG = {
grants: 'https://grants.cow.fi',
mevBlocker: 'https://mevblocker.io/',
},
- greenhouse: {
- api: 'https://boards-api.greenhouse.io/v1/boards/cowswap/jobs?content=true',
- },
+ ashbyHqApi: 'https://jobs.ashbyhq.com/api/non-user-graphql',
social: {
twitter: { label: 'Twitter', account: '@CoWSwap', url: 'https://twitter.com/CoWSwap' },
discord: { label: 'Discord', url: 'https://discord.com/invite/cowprotocol' },
diff --git a/apps/cow-fi/pages/careers/index.tsx b/apps/cow-fi/pages/careers/index.tsx
index 38b04143c6..0f0f2ca79a 100644
--- a/apps/cow-fi/pages/careers/index.tsx
+++ b/apps/cow-fi/pages/careers/index.tsx
@@ -1,4 +1,4 @@
-import { getJobs } from 'services/greenhouse'
+import { getJobs } from 'services/ashByHq'
import { GetStaticProps } from 'next'
import { Font, Color, ProductLogo, ProductVariant } from '@cowprotocol/ui'
@@ -63,14 +63,18 @@ export default function Page({ siteConfigData, jobsData }: PageProps) {
- {jobsCount < 1 &&
There are currently no open positions.
}
+ {jobsCount < 1 && (
+
+ There are currently no open positions.
+
+ )}
{jobsCount > 0 &&
(department === 'All'
? Object.keys(jobsData).map((deptName: string) => (
<>
- {jobsData[deptName].map(({ absolute_url, title, location }: any, index: number) => (
+ {jobsData[deptName].map(({ id, title, locationName }: any, index: number) => (
{title}
- {location.name}
+ {locationName}
0 && (
<>
{department}
- {jobsData[department].map(({ absolute_url, title, location }: any, index: number) => (
+ {jobsData[department].map(({ id, title, locationName }: any, index: number) => (
{title}
- {location.name}
+ {locationName}
clickOnCareers(`click-job-${title}`)}
>
@@ -184,13 +188,25 @@ export default function Page({ siteConfigData, jobsData }: PageProps) {
export const getStaticProps: GetStaticProps = async () => {
const siteConfigData = CONFIG
- const jobsData = await getJobs()
-
- return {
- props: {
- siteConfigData,
- jobsData,
- },
- revalidate: DATA_CACHE_TIME_SECONDS,
+ console.log('Fetching jobs data...')
+ try {
+ const jobsData = (await getJobs()) || {}
+ console.log('Jobs data fetched:', jobsData)
+ return {
+ props: {
+ siteConfigData,
+ jobsData,
+ },
+ revalidate: DATA_CACHE_TIME_SECONDS,
+ }
+ } catch (error) {
+ console.error('Error fetching jobs data:', error)
+ return {
+ props: {
+ siteConfigData,
+ jobsData: {},
+ },
+ revalidate: DATA_CACHE_TIME_SECONDS,
+ }
}
}
diff --git a/apps/cow-fi/services/ashByHq/index.ts b/apps/cow-fi/services/ashByHq/index.ts
new file mode 100644
index 0000000000..140aae86fa
--- /dev/null
+++ b/apps/cow-fi/services/ashByHq/index.ts
@@ -0,0 +1,78 @@
+import { CONFIG } from '@/const/meta'
+
+interface AshbyResponse {
+ data: {
+ jobBoard: {
+ teams: { id: string; name: string; parentTeamId: string | null }[]
+ jobPostings: {
+ id: string
+ title: string
+ teamId: string
+ locationName: string
+ employmentType: string
+ }[]
+ }
+ }
+}
+
+export async function getJobs() {
+ console.log('getJobs function called')
+ const jobsData: any = {}
+ const { ashbyHqApi } = CONFIG
+
+ console.log('Ashby HQ API URL:', ashbyHqApi)
+
+ try {
+ console.log('Fetching data from Ashby HQ API...')
+ const response = await fetch(ashbyHqApi, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'apollographql-client-name': 'frontend_non_user',
+ 'apollographql-client-version': '0.1.0',
+ },
+ body: JSON.stringify({
+ operationName: 'ApiJobBoardWithTeams',
+ variables: { organizationHostedJobsPageName: 'cow-dao' },
+ query: `
+ query ApiJobBoardWithTeams($organizationHostedJobsPageName: String!) {
+ jobBoard: jobBoardWithTeams(
+ organizationHostedJobsPageName: $organizationHostedJobsPageName
+ ) {
+ teams {
+ id
+ name
+ parentTeamId
+ }
+ jobPostings {
+ id
+ title
+ teamId
+ locationName
+ employmentType
+ }
+ }
+ }
+ `,
+ }),
+ })
+ console.log('Response status:', response.status)
+ const data = (await response.json()) as AshbyResponse
+ console.log('Ashby HQ API response:', JSON.stringify(data, null, 2))
+
+ if (data.data?.jobBoard?.jobPostings) {
+ data.data.jobBoard.jobPostings.forEach((job) => {
+ const team = data.data.jobBoard.teams.find((t) => t.id === job.teamId)
+ const deptName = team ? team.name : 'Other'
+ jobsData[deptName] ? jobsData[deptName].push(job) : (jobsData[deptName] = [job])
+ })
+ } else {
+ console.error('Unexpected API response structure:', JSON.stringify(data, null, 2))
+ }
+ } catch (error) {
+ console.error('Error fetching jobs:', error)
+ }
+
+ console.log('Processed job data:', JSON.stringify(jobsData, null, 2))
+ return jobsData
+}
diff --git a/apps/cow-fi/services/greenhouse/index.ts b/apps/cow-fi/services/greenhouse/index.ts
deleted file mode 100644
index ace2813415..0000000000
--- a/apps/cow-fi/services/greenhouse/index.ts
+++ /dev/null
@@ -1,19 +0,0 @@
-import { CONFIG } from '@/const/meta'
-
-export async function getJobs() {
- const jobsData: any = {}
- const { api } = CONFIG.greenhouse
-
- try {
- const response = await fetch(api)
- const data = await response.json()
- data.jobs.forEach((job: any) => {
- const deptName = job.departments[0].name
- deptName && jobsData[deptName] ? jobsData[deptName].push(job) : (jobsData[deptName] = [job])
- })
- } catch (error) {
- console.log(error)
- }
-
- return jobsData
-}