Skip to content

Commit

Permalink
Update/countries to show only if have role (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisfp0 authored Sep 25, 2024
1 parent 8876cf0 commit d4a0158
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
34 changes: 17 additions & 17 deletions apps/web/app/(roles)/vagas/RolesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use client'

import { FocusBanner } from 'app/landing-page/FocusBanner'
import { ChevronDown, X } from 'lucide-react'
import { useEffect, useMemo, useState } from 'react'
Expand Down Expand Up @@ -31,20 +32,12 @@ const experienceLevels = [
},
]

const flags = [
{
value: 'Brasil',
label: '🇧🇷 Brasil',
},
{
value: 'EstadosUnidos',
label: '🇺🇸 Estados Unidos',
},
{
value: 'ReinoUnido',
label: '🇬🇧 Reino Unido',
},
]
const countryFlags = {
Brasil: '🇧🇷',
EUA: '🇺🇸',
Global: '🇺🇳',
International: '🇺🇳',
}

const orderOptions = [
{
Expand All @@ -63,7 +56,7 @@ const orderOptions = [

const order = orderOptions.map((or) => or.label)

export const RolesPage = ({ jobsFromServer, skillsFromServer }) => {
export const RolesPage = ({ jobsFromServer, skillsFromServer, countries }) => {
const router = useRouter()
const [jobs, setJobs] = useState(jobsFromServer)
const [filters, setFilters] = useState<Filter[]>([])
Expand All @@ -86,6 +79,13 @@ export const RolesPage = ({ jobsFromServer, skillsFromServer }) => {
}
})

const countriesOptions = countries
.filter((country) => country.country !== 'International')
.map((country) => ({
value: country.country,
label: `${countryFlags[country.country] || '🇺🇳'} ${country.country}`,
}))

const getLabel = (key, val) => {
if (key === 'skill') {
const filtered = technologies.find(
Expand All @@ -94,7 +94,7 @@ export const RolesPage = ({ jobsFromServer, skillsFromServer }) => {
return filtered ? `${filtered.emoji} ${filtered.label}` : val
}
if (key === 'country') {
const filtered = flags.find((flag) => flag.value === val)
const filtered = countriesOptions.find((flag) => flag.value === val)
return filtered ? filtered.label : val
}
if (key === 'level') {
Expand Down Expand Up @@ -312,7 +312,7 @@ export const RolesPage = ({ jobsFromServer, skillsFromServer }) => {
/>
<SelectInput
placeholder="🌎 Local"
options={flags}
options={countriesOptions}
setFilters={setFilters}
filterType="country"
filters={filters}
Expand Down
8 changes: 7 additions & 1 deletion apps/web/app/(roles)/vagas/action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use server'

import { createClient } from '@supabase/supabase-js'
import { Filter, Job, SelectOption } from 'app/components/SelectInput'

Expand Down Expand Up @@ -55,8 +56,13 @@ export const fetchJobs = async (

if (countryOptionsFormatted.length > 0) {
const countryValues = countryOptionsFormatted.map(
(country: ItemExtracted) => country.option.value
(country: Filter) => country.option.value
)

if (countryValues.includes('Global')) {
countryValues.push('International')
}

query = query.in('country', countryValues)
}

Expand Down
19 changes: 17 additions & 2 deletions apps/web/app/(roles)/vagas/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ async function getJobs() {
const jobsFromCache = await client.get('web_jobs')

if (jobsFromCache) {
console.log('Cache')
return JSON.parse(jobsFromCache)
}

Expand Down Expand Up @@ -59,10 +58,26 @@ async function getSkills() {
return skills
}

async function getCountries() {
const { data: countries } = await supabase
.from('vw_countries_in_roles')
.select('*')
.order('country')

return countries
}

export default async function Page() {
const skills = await getSkills()
const jobs = await getJobs()
const countries = await getCountries()
const jobsReady = jobs.filter((job) => job.ready === true)

return <RolesPage jobsFromServer={jobsReady} skillsFromServer={skills} />
return (
<RolesPage
jobsFromServer={jobsReady}
skillsFromServer={skills}
countries={countries}
/>
)
}
4 changes: 4 additions & 0 deletions packages/db/supabase/views/create_view_countrie_in_roles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE OR REPLACE VIEW vw_countries_in_roles AS
SELECT DISTINCT r.country
FROM "Roles" r
WHERE r.country IS NOT NULL AND LENGTH(r.country) > 0 AND r.ready = true;
9 changes: 9 additions & 0 deletions packages/db/supabase/views/create_view_skills_in_roles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE OR REPLACE VIEW VW_SKILLS_IN_ROLES AS
SELECT *
FROM "Skills"
WHERE id IN (
SELECT DISTINCT CAST(UNNEST("skillsId") AS INTEGER) AS skillId
FROM "Roles"
WHERE ready = true
)
ORDER BY name;

0 comments on commit d4a0158

Please sign in to comment.