From db757ca16957fcd12c3c01ff8680c3771777b82d Mon Sep 17 00:00:00 2001 From: AldemirLucas Date: Fri, 15 Sep 2023 14:44:15 -0300 Subject: [PATCH] finish struture for Quem somos page --- next/pages/api/team/getAllPeople.js | 8 +- next/pages/api/team/getAllTeams.js | 24 ++++- next/pages/api/team/getCareerPeople.js | 4 +- next/pages/api/team/index.js | 4 +- next/pages/quem-somos.js | 139 ++++--------------------- 5 files changed, 50 insertions(+), 129 deletions(-) diff --git a/next/pages/api/team/getAllPeople.js b/next/pages/api/team/getAllPeople.js index 10b322f4..037792ea 100644 --- a/next/pages/api/team/getAllPeople.js +++ b/next/pages/api/team/getAllPeople.js @@ -10,7 +10,7 @@ export default async function getAllPeople() { data: { query: ` query { - allAccount (profile: A_1){ + allAccount { edges { node { firstName @@ -22,7 +22,8 @@ export default async function getAllPeople() { linkedin github picture - careerSet { + isActiveStaff + careers { edges { node { _id @@ -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) diff --git a/next/pages/api/team/getAllTeams.js b/next/pages/api/team/getAllTeams.js index c5da275b..7c18d74a 100644 --- a/next/pages/api/team/getAllTeams.js +++ b/next/pages/api/team/getAllTeams.js @@ -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) diff --git a/next/pages/api/team/getCareerPeople.js b/next/pages/api/team/getCareerPeople.js index 5ff9d829..1301e309 100644 --- a/next/pages/api/team/getCareerPeople.js +++ b/next/pages/api/team/getCareerPeople.js @@ -10,7 +10,7 @@ export default async function getCareerPeople(team) { data: { query: ` query { - allAccount (career_Team: "${team}"){ + allAccount (careers_Team: "${team}"){ edges { node { firstName @@ -22,7 +22,7 @@ export default async function getCareerPeople(team) { linkedin github picture - careerSet { + careers { edges { node { _id diff --git a/next/pages/api/team/index.js b/next/pages/api/team/index.js index 07b4e8f1..3089fe07 100644 --- a/next/pages/api/team/index.js +++ b/next/pages/api/team/index.js @@ -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 } \ No newline at end of file diff --git a/next/pages/quem-somos.js b/next/pages/quem-somos.js index 547709f9..56d0b09c 100755 --- a/next/pages/quem-somos.js +++ b/next/pages/quem-somos.js @@ -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"; @@ -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 }, } } @@ -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 = "" @@ -215,8 +219,7 @@ const TeamBox = ({ letterSpacing="0.2px" color="#6F6F6F" > - {/* {data?.role.join(", ")} */} - {role} + {role()} { - 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", @@ -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) } } @@ -756,7 +659,7 @@ export default function QuemSomos({ data }) { top={isMobileMod()? "0" : "120px"} z-index="20" > - {schemasTeam?.map((elm) => ( + {teams?.map((elm) => ( ))} @@ -825,9 +728,7 @@ export default function QuemSomos({ data }) { - - ) } \ No newline at end of file