Skip to content

Commit

Permalink
finish struture for Quem somos page
Browse files Browse the repository at this point in the history
  • Loading branch information
AldemirLucas committed Sep 15, 2023
1 parent 5506ac8 commit db757ca
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 129 deletions.
8 changes: 5 additions & 3 deletions next/pages/api/team/getAllPeople.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function getAllPeople() {
data: {
query: `
query {
allAccount (profile: A_1){
allAccount {
edges {
node {
firstName
Expand All @@ -22,7 +22,8 @@ export default async function getAllPeople() {
linkedin
github
picture
careerSet {
isActiveStaff
careers {
edges {
node {
_id
Expand All @@ -40,7 +41,8 @@ export default async function getAllPeople() {
`
}
})
const data = res?.data?.data?.allAccount?.edges
const result = res?.data?.data?.allAccount?.edges
const data = result.filter(item => item.node.isActiveStaff === 'true')
return data
} catch (error) {
console.error(error)
Expand Down
24 changes: 20 additions & 4 deletions next/pages/api/team/getAllTeams.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,29 @@ export default async function getAllTeams() {
method: "POST",
data: {
query: `
query {
}
query {
allCareer {
edges {
node {
team
}
}
}
}
`
}
})
const data = res?.data?.data?.allBdgroup?.edges
const result = res?.data?.data?.allCareer?.edges
const teamsSet = new Set()

result.forEach(item => {
const team = item.node.team.trim()
if (team !== "") {
teamsSet.add(team)
}
})

const data = Array.from(teamsSet)
return data
} catch (error) {
console.error(error)
Expand Down
4 changes: 2 additions & 2 deletions next/pages/api/team/getCareerPeople.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function getCareerPeople(team) {
data: {
query: `
query {
allAccount (career_Team: "${team}"){
allAccount (careers_Team: "${team}"){
edges {
node {
firstName
Expand All @@ -22,7 +22,7 @@ export default async function getCareerPeople(team) {
linkedin
github
picture
careerSet {
careers {
edges {
node {
_id
Expand Down
4 changes: 3 additions & 1 deletion next/pages/api/team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import getTeams from "./getTeams";
import getPeople from "./getPeople";
import getAllPeople from "./getAllPeople";
import getCareerPeople from "./getCareerPeople";
import getAllTeams from "./getAllTeams";

export {
getTeams,
getPeople,
getAllPeople,
getCareerPeople
getCareerPeople,
getAllTeams
}
139 changes: 20 additions & 119 deletions next/pages/quem-somos.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import { MainPageTemplate } from "../components/templates/main";
import { isMobileMod } from "../hooks/useCheckMobile.hook";

import {
// getTeams,
// getPeople,
getAllPeople,
getCareerPeople
getCareerPeople,
getAllTeams
} from "./api/team";

import Display from "../components/atoms/Display";
Expand All @@ -40,10 +39,12 @@ import styles from "../styles/quemSomos.module.css";

export async function getServerSideProps() {
const data = await getAllPeople()
const teams = await getAllTeams()

return {
props: {
data,
teams
},
}
}
Expand Down Expand Up @@ -126,8 +127,11 @@ const TeamBox = ({
}) => {
const hasLeftSpacing = (index % 2 == 0) ? false : true

const role = career[0]?.node.role
console.log(career)
const role = () => {
const roles = []
career.map((elm) => roles.push(elm.node.role))
return roles.filter((elm) => elm.length > 0).join(", ")
}

const iconTeamBox = (ref) => {
let href = ""
Expand Down Expand Up @@ -215,8 +219,7 @@ const TeamBox = ({
letterSpacing="0.2px"
color="#6F6F6F"
>
{/* {data?.role.join(", ")} */}
{role}
{role()}
</BodyText>

<BodyText
Expand All @@ -233,8 +236,8 @@ const TeamBox = ({
)
}

export default function QuemSomos({ data }) {
const [allPeople, setAllPeople] = useState(data)
export default function QuemSomos({ data, teams }) {
const [allPeople] = useState(data)
const [people, setPeople] = useState(data)
const [filterTeam, setFilterTeam] = useState("")

Expand All @@ -250,108 +253,6 @@ export default function QuemSomos({ data }) {
"Conselho Fiscal"
]

const sortingTeam = (array, team = schemasTeam) => {
let arraySorting = []

team.map((personTeam) => {
const newPeopleByTeam = array.filter((person) => {
const indexTeam = person.team.findIndex((res) => res === personTeam)
if(indexTeam > -1) return person.team[indexTeam]
})

const orderByName = newPeopleByTeam.sort((a, b) => {
const compareName = (firstPerson, secondPerson) => firstPerson.name.localeCompare(secondPerson.name)

if (compareName(a, b) < compareName(b, a)) return -1
if (compareName(a, b) > compareName(b, a)) return 1
return 0
})

const orderByLevel = orderByName.sort((a, b) => {
const valueLevel = (elm) => {{
const levelPerson = elm.level[0]
if(levelPerson === "Presidente") return -3
if(levelPerson === "Diretora Executiva") return -2
if(levelPerson === "Gerente") return -1
return 0
}}

return valueLevel(a) - valueLevel(b)
})

orderByLevel.map((res) => {
arraySorting.push(res)
})

})
const newArraySorting = [...new Set(arraySorting)]
return newArraySorting
}

// useEffect(() => {
// setPeople(sortingTeam(allPeople))
// },[allPeople])

// useEffect(() => {
// // setAllPeople(groupingTeamAndRole(Object.values(getPeople)).filter(Boolean))
// setAllPeople([])
// },[])

const groupingTeamAndRole = (array) => array.map((elm) => {
const person = elm
const team = []
const role = []
const level = []
const endDate = []

// const getById = getTeams.filter((elm) => elm.person_id === person.id)
const getById= []

if(getById) getById.map((res) => {
team.push(res.team)
role.push(res.role)
level.push(res.level)
endDate.push(res.end_date)
})

const filterArray = (array) => Array.from(new Set(array.filter(Boolean)))

const departureDate = filterArray(endDate)

if(departureDate.length > 0) {
const endDate = new Date(departureDate[0])
const dateNow = new Date()
if(endDate < dateNow) return ""
}

return {
...person,
team : filterArray(team),
role : filterArray(role),
level : filterArray(level),
}
})

useEffect(() => {
if(filterTeam) filterPeopleByTeam(filterTeam)
},[filterTeam])

const filterPeopleByTeam = (team) => {
// const teamPeople = getTeams.filter((elm) => elm.team === team)
const teamPeople = []

const mapId = () => teamPeople.map((elm) => elm.person_id)

const personIdList = Array.from(new Set(mapId()))

// const filterPeople = () => personIdList.map((personId) => getPeople[personId])
const filterPeople = []

const newGroupPerson = groupingTeamAndRole(filterPeople()).filter(Boolean)

setPeople(sortingTeam(newGroupPerson, [team]))
}

const keyIcon = (url) => {
return {
cursor:"pointer",
Expand All @@ -366,13 +267,15 @@ export default function QuemSomos({ data }) {
}
}

const handleSelect = (elm) => {
const handleSelect = async (elm) => {
window.open("#teams", "_self")
if(filterTeam === elm) {
setFilterTeam()
return setPeople(sortingTeam(allPeople))
setFilterTeam("")
return setPeople(allPeople)
} else {
return setFilterTeam(elm)
setFilterTeam(elm)
const result = await getCareerPeople(elm)
setPeople(result)
}
}

Expand Down Expand Up @@ -756,7 +659,7 @@ export default function QuemSomos({ data }) {
top={isMobileMod()? "0" : "120px"}
z-index="20"
>
{schemasTeam?.map((elm) => (
{teams?.map((elm) => (
<Text
fontSize="16px"
color={filterTeam === elm ? "#2B8C4D" :"#6F6F6F"}
Expand Down Expand Up @@ -789,7 +692,7 @@ export default function QuemSomos({ data }) {
twitter={elm.node.twitter}
linkedin={elm.node.linkedin}
github={elm.node.github}
career={elm.node.careerSet.edges}
career={elm.node.careers.edges}
/>
))}
</Stack>
Expand Down Expand Up @@ -825,9 +728,7 @@ export default function QuemSomos({ data }) {
</RoundedButton>
</Box>
</Stack>

</Stack>

</MainPageTemplate>
)
}

0 comments on commit db757ca

Please sign in to comment.