From 5506ac80a9c9ceaa147a970f44e4301787764a0d Mon Sep 17 00:00:00 2001 From: AldemirLucas Date: Wed, 13 Sep 2023 19:59:17 -0300 Subject: [PATCH 1/2] wip page Quem somos --- next/pages/api/team/getAllPeople.js | 48 +++++++++++ next/pages/api/team/getAllTeams.js | 23 ++++++ next/pages/api/team/getCareerPeople.js | 48 +++++++++++ next/pages/api/team/index.js | 10 ++- next/pages/quem-somos.js | 107 ++++++++++++++++++------- 5 files changed, 205 insertions(+), 31 deletions(-) create mode 100644 next/pages/api/team/getAllPeople.js create mode 100644 next/pages/api/team/getAllTeams.js create mode 100644 next/pages/api/team/getCareerPeople.js diff --git a/next/pages/api/team/getAllPeople.js b/next/pages/api/team/getAllPeople.js new file mode 100644 index 00000000..10b322f4 --- /dev/null +++ b/next/pages/api/team/getAllPeople.js @@ -0,0 +1,48 @@ +import axios from "axios"; + +const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql` + +export default async function getAllPeople() { + try { + const res = await axios({ + url: API_URL, + method: "POST", + data: { + query: ` + query { + allAccount (profile: A_1){ + edges { + node { + firstName + lastName + description + website + email + twitter + linkedin + github + picture + careerSet { + edges { + node { + _id + team + role + startAt + endAt + } + } + } + } + } + } + } + ` + } + }) + const data = res?.data?.data?.allAccount?.edges + return data + } catch (error) { + console.error(error) + } +} diff --git a/next/pages/api/team/getAllTeams.js b/next/pages/api/team/getAllTeams.js new file mode 100644 index 00000000..c5da275b --- /dev/null +++ b/next/pages/api/team/getAllTeams.js @@ -0,0 +1,23 @@ +import axios from "axios"; + +const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql` + +export default async function getAllTeams() { + try { + const res = await axios({ + url: API_URL, + method: "POST", + data: { + query: ` + query { + + } + ` + } + }) + const data = res?.data?.data?.allBdgroup?.edges + return data + } catch (error) { + console.error(error) + } +} diff --git a/next/pages/api/team/getCareerPeople.js b/next/pages/api/team/getCareerPeople.js new file mode 100644 index 00000000..5ff9d829 --- /dev/null +++ b/next/pages/api/team/getCareerPeople.js @@ -0,0 +1,48 @@ +import axios from "axios"; + +const API_URL= `${process.env.NEXT_PUBLIC_API_URL}/api/v1/graphql` + +export default async function getCareerPeople(team) { + try { + const res = await axios({ + url: API_URL, + method: "POST", + data: { + query: ` + query { + allAccount (career_Team: "${team}"){ + edges { + node { + firstName + lastName + description + website + email + twitter + linkedin + github + picture + careerSet { + edges { + node { + _id + team + role + startAt + endAt + } + } + } + } + } + } + } + ` + } + }) + const data = res?.data?.data?.allAccount?.edges + return data + } catch (error) { + console.error(error) + } +} diff --git a/next/pages/api/team/index.js b/next/pages/api/team/index.js index ceb5ff38..07b4e8f1 100644 --- a/next/pages/api/team/index.js +++ b/next/pages/api/team/index.js @@ -1,7 +1,11 @@ -import getTeams from "./getTeams" -import getPeople from "./getPeople" +import getTeams from "./getTeams"; +import getPeople from "./getPeople"; +import getAllPeople from "./getAllPeople"; +import getCareerPeople from "./getCareerPeople"; export { getTeams, - getPeople + getPeople, + getAllPeople, + getCareerPeople } \ No newline at end of file diff --git a/next/pages/quem-somos.js b/next/pages/quem-somos.js index a491bd16..547709f9 100755 --- a/next/pages/quem-somos.js +++ b/next/pages/quem-somos.js @@ -16,8 +16,10 @@ import { MainPageTemplate } from "../components/templates/main"; import { isMobileMod } from "../hooks/useCheckMobile.hook"; import { - getTeams, - getPeople + // getTeams, + // getPeople, + getAllPeople, + getCareerPeople } from "./api/team"; import Display from "../components/atoms/Display"; @@ -36,6 +38,16 @@ import DiscordIcon from "../public/img/icons/discordIcon"; import RedirectIcon from "../public/img/icons/redirectIcon"; import styles from "../styles/quemSomos.module.css"; +export async function getServerSideProps() { + const data = await getAllPeople() + + return { + props: { + data, + }, + } +} + const HistoryBox = ({ children, title, date, image }) => { const { isOpen, onOpen, onClose } = useDisclosure() @@ -99,9 +111,24 @@ const HistoryBox = ({ children, title, date, image }) => { ) } -const TeamBox = ({ index, data }) => { +const TeamBox = ({ + index, + data, + name, + picture, + description, + website, + email, + twitter, + linkedin, + github, + career +}) => { const hasLeftSpacing = (index % 2 == 0) ? false : true + const role = career[0]?.node.role + console.log(career) + const iconTeamBox = (ref) => { let href = "" @@ -134,14 +161,14 @@ const TeamBox = ({ index, data }) => { } } - const iconLinks = () => { + const IconLinks = () => { return ( - {data.website ? : null} - {data.email ? : null} - {data.twitter ? : null} - {data.linkedin ? : null} - {data.github ? : null} + {website ? : null} + {email ? : null} + {twitter ? : null} + {linkedin ? : null} + {github ? : null} ) } @@ -164,8 +191,8 @@ const TeamBox = ({ index, data }) => { overflow="hidden" > {data?.name @@ -176,10 +203,11 @@ const TeamBox = ({ index, data }) => { fontSize="18px" marginRight="16px" > - {data?.name} + {name} - {!isMobileMod() && iconLinks()} + {!isMobileMod() && } + { letterSpacing="0.2px" color="#6F6F6F" > - {data?.role.join(", ")} + {/* {data?.role.join(", ")} */} + {role} + + + + {description} - {data?.description} {isMobileMod() && iconLinks()} ) } -export default function QuemSomos() { - const [allPeople, setAllPeople] = useState([]) - const [people, setPeople] = useState([]) +export default function QuemSomos({ data }) { + const [allPeople, setAllPeople] = useState(data) + const [people, setPeople] = useState(data) const [filterTeam, setFilterTeam] = useState("") const schemasTeam = [ @@ -251,13 +288,14 @@ export default function QuemSomos() { return newArraySorting } - useEffect(() => { - setPeople(sortingTeam(allPeople)) - },[allPeople]) + // useEffect(() => { + // setPeople(sortingTeam(allPeople)) + // },[allPeople]) - useEffect(() => { - setAllPeople(groupingTeamAndRole(Object.values(getPeople)).filter(Boolean)) - },[]) + // useEffect(() => { + // // setAllPeople(groupingTeamAndRole(Object.values(getPeople)).filter(Boolean)) + // setAllPeople([]) + // },[]) const groupingTeamAndRole = (array) => array.map((elm) => { const person = elm @@ -266,7 +304,8 @@ export default function QuemSomos() { const level = [] const endDate = [] - const getById = getTeams.filter((elm) => elm.person_id === person.id) + // const getById = getTeams.filter((elm) => elm.person_id === person.id) + const getById= [] if(getById) getById.map((res) => { team.push(res.team) @@ -298,14 +337,16 @@ export default function QuemSomos() { },[filterTeam]) const filterPeopleByTeam = (team) => { - const teamPeople = getTeams.filter((elm) => elm.team === 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 = () => personIdList.map((personId) => getPeople[personId]) + const filterPeople = [] + const newGroupPerson = groupingTeamAndRole(filterPeople()).filter(Boolean) setPeople(sortingTeam(newGroupPerson, [team])) @@ -737,8 +778,18 @@ export default function QuemSomos() { > {people?.map((elm, index) => ( ))} From db757ca16957fcd12c3c01ff8680c3771777b82d Mon Sep 17 00:00:00 2001 From: AldemirLucas Date: Fri, 15 Sep 2023 14:44:15 -0300 Subject: [PATCH 2/2] 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