diff --git a/src/components/CommonPage.tsx b/src/components/CommonPage.tsx
index f21d845b..4db5ad45 100644
--- a/src/components/CommonPage.tsx
+++ b/src/components/CommonPage.tsx
@@ -43,16 +43,11 @@ const CommonPage = ({
context === "zenika"
? skill && category
? `/skills/zenika/${category}`
- : "/zenika"
+ : `/zenika/${agency || "World"}`
: "/"
}`
);
- if (agency) {
- backUrl.searchParams.append(
- "agency",
- typeof agency === "string" ? agency : agency.join("")
- );
- }
+
return (
diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx
index 7f8d6f95..5fc30c05 100644
--- a/src/components/Navbar.tsx
+++ b/src/components/Navbar.tsx
@@ -38,16 +38,16 @@ const Navbar = ({ path }: { path: string }) => {
-
+
- {path === "/zenika" ? (
+ {path.includes("/zenika") ? (
) : (
)}
-
+
{t("nav.zenikaSkills")}
- {context === "zenika" || path === "/zenika" ? (
+ {context === "zenika" || path.includes("/zenika") ? (
diff --git a/src/pages/zenika.tsx b/src/pages/zenika/[agency].tsx
similarity index 58%
rename from src/pages/zenika.tsx
rename to src/pages/zenika/[agency].tsx
index 6f0513d1..19cfab24 100644
--- a/src/pages/zenika.tsx
+++ b/src/pages/zenika/[agency].tsx
@@ -1,13 +1,11 @@
import { useAuth0 } from "@auth0/auth0-react";
-import HomePanel from "../components/HomePanel";
-import Loading from "../components/Loading";
-import { gql, useQuery } from "@apollo/client";
-import PageWithNavAndPanel from "../components/PageWithNavAndPanel";
+import HomePanel from "../../components/HomePanel";
+import Loading from "../../components/Loading";
+import PageWithNavAndPanel from "../../components/PageWithNavAndPanel";
import { useRouter } from "next/router";
-import FilterByPanel, { Filter } from "../components/FilterByPanel";
import { useEffect, useState } from "react";
-import { FilterData } from "../utils/types";
-import { useComputeFilterUrl } from "../utils/useComputeFilterUrl";
+import { FilterData } from "../../utils/types";
+import { GetStaticPaths, GetStaticProps } from "next";
type SkillsData = {
Category: {
@@ -31,7 +29,7 @@ type SkillsData = {
}[];
};
-const computeZenikaSkillsQuery = ({ agency }: { agency?: string }) => gql`
+const computeZenikaSkillsQuery = ({ agency }: { agency?: string }) => `
query getSkillsAndTechnicalAppetites${agency ? "($agency: String!)" : ""} {
Category(order_by: {index: asc}) {
label
@@ -50,7 +48,7 @@ const computeZenikaSkillsQuery = ({ agency }: { agency?: string }) => gql`
AverageCurrentSkillsAndDesires_aggregate: ${
agency ? "Agencies" : "Zenikas"
}AverageCurrentSkillsAndDesires_aggregate ${
- agency ? `(where: {agency: {_eq: $agency}})` : ""
+ agency ? `(where: {agency: {_ilike: $agency}})` : ""
} {
aggregate {
count(columns: skillId, distinct: true)
@@ -63,8 +61,7 @@ const computeZenikaSkillsQuery = ({ agency }: { agency?: string }) => gql`
}
`;
-const Zenika = ({ pathName }) => {
- const { user, isLoading } = useAuth0();
+const Zenika = ({ pathName, skillsData, error }) => {
const { query, push } = useRouter();
const { context, agency } = query;
@@ -72,19 +69,6 @@ const Zenika = ({ pathName }) => {
FilterData | undefined
>(undefined);
- const { data: skillsData, error } = useQuery(
- computeZenikaSkillsQuery({
- agency: filterByAgency?.selected
- ? filterByAgency?.selected === "World"
- ? undefined
- : filterByAgency?.selected
- : undefined,
- }),
- {
- variables: { email: user.email, agency: filterByAgency?.selected },
- fetchPolicy: "network-only",
- }
- );
useEffect(() => {
setFilterByAgency({
name: "Agency",
@@ -129,10 +113,7 @@ const Zenika = ({ pathName }) => {
selected: filterByAgency.selected,
callback: (value) =>
push(
- useComputeFilterUrl(
- `${window.location}`,
- value ? [{ name: "agency", value: `${value}` }] : []
- )
+ `${window.location.protocol}//${window.location.host}/zenika/${value}`
),
},
]
@@ -157,4 +138,84 @@ const Zenika = ({ pathName }) => {
);
};
+const NEXT_PUBLIC_GRAPHQL_URL = process.env.NEXT_PUBLIC_GRAPHQL_URL;
+if (!NEXT_PUBLIC_GRAPHQL_URL) {
+ throw new Error("NEXT_PUBLIC_GRAPHQL_URL env variable is not set");
+}
+
+const fetcher = async (
+ url: string,
+ key: string,
+ query: string,
+ variables: { [key: string]: number | boolean | string }
+) => {
+ const result = await fetch(url, {
+ headers: { "x-hasura-admin-secret": `${key}` },
+ method: "POST",
+ body: JSON.stringify({
+ query,
+ variables,
+ }),
+ });
+ if (!result.ok) {
+ return { error: await result.json() };
+ }
+ return { data: await result.json() };
+};
+
+export const getStaticProps: GetStaticProps = async (context) => {
+ const HASURA_ADMIN_SECRET = process.env.HASURA_ADMIN_SECRET;
+ if (!HASURA_ADMIN_SECRET) {
+ throw new Error("HASURA_ADMIN_SECRET env variable is not set");
+ }
+ const agency = context.params?.agency;
+ const computedAgency =
+ agency === "World" || typeof agency !== "string" ? undefined : agency;
+ const { data: skillsData, error } = await fetcher(
+ NEXT_PUBLIC_GRAPHQL_URL,
+ HASURA_ADMIN_SECRET,
+ computeZenikaSkillsQuery({
+ agency: computedAgency,
+ }),
+ { agency: computedAgency }
+ );
+
+ return {
+ props: {
+ skillsData: skillsData.data,
+ },
+ revalidate: 300,
+ };
+};
+
+export const getStaticPaths: GetStaticPaths = async () => {
+ const HASURA_ADMIN_SECRET = process.env.HASURA_ADMIN_SECRET;
+ if (!HASURA_ADMIN_SECRET) {
+ throw new Error("HASURA_ADMIN_SECRET env variable is not set");
+ }
+ const agencyQuery = `
+ {
+ Agency {
+ name
+ }
+ }
+ `;
+ const { data: agencies, error } = await fetcher(
+ NEXT_PUBLIC_GRAPHQL_URL,
+ HASURA_ADMIN_SECRET,
+ agencyQuery,
+ {}
+ );
+ const paths = ["en", "fr"]
+ .map((locale) => [
+ { params: { agency: "World" }, locale },
+ ...agencies?.data?.Agency?.map((agency) => ({
+ params: { agency: agency.name },
+ locale,
+ })),
+ ])
+ .reduce((previous, current) => [...previous, ...current]);
+ return { paths, fallback: true };
+};
+
export default Zenika;