2021-03-20 14:00:42 +00:00
|
|
|
import { GetStaticProps } from 'next';
|
2021-03-25 05:29:33 +00:00
|
|
|
import {
|
|
|
|
createClient,
|
|
|
|
Profession,
|
|
|
|
Qualification,
|
|
|
|
Query,
|
|
|
|
QueryProfessionsArgs,
|
|
|
|
} from 'libs/graphql';
|
|
|
|
import { QUERY_PROFESSIONS } from './queries';
|
2021-03-17 05:22:49 +00:00
|
|
|
|
2021-03-20 14:00:42 +00:00
|
|
|
import Layout from 'common/Layout/Layout';
|
2021-03-20 11:42:17 +00:00
|
|
|
import Header from './components/Header/Header';
|
|
|
|
|
2021-03-25 05:29:33 +00:00
|
|
|
interface IndexPageProps {
|
|
|
|
professions: Profession[];
|
|
|
|
qualifications: Qualification[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const IndexPage = ({ qualifications }: IndexPageProps) => {
|
2021-03-20 11:42:17 +00:00
|
|
|
return (
|
|
|
|
<Layout transparentTopBar absoluteTopBar padding={false}>
|
2021-03-25 05:29:33 +00:00
|
|
|
<Header qualifications={qualifications} />
|
2021-03-20 11:42:17 +00:00
|
|
|
</Layout>
|
|
|
|
);
|
2021-03-17 04:04:50 +00:00
|
|
|
};
|
|
|
|
|
2021-03-25 05:29:33 +00:00
|
|
|
const getQualificationsFromProfessions = (
|
|
|
|
professions: Profession[]
|
|
|
|
): Qualification[] => {
|
|
|
|
const map = new Map<number, Qualification>();
|
|
|
|
professions.forEach(profession => {
|
|
|
|
profession.qualifications.forEach(qualification => {
|
|
|
|
map.set(qualification.id, qualification);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return Array.from(map.values());
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getStaticProps: GetStaticProps = async () => {
|
|
|
|
const pageProps: IndexPageProps = { professions: [], qualifications: [] };
|
2021-03-20 14:00:42 +00:00
|
|
|
const client = createClient();
|
|
|
|
|
2021-03-25 05:29:33 +00:00
|
|
|
try {
|
|
|
|
const resp = await client.request<
|
|
|
|
Pick<Query, 'professions'>,
|
|
|
|
QueryProfessionsArgs
|
|
|
|
>(QUERY_PROFESSIONS, { sort: ['name ASC'] });
|
|
|
|
if (Array.isArray(resp.professions?.items)) {
|
|
|
|
pageProps.professions = resp.professions.items;
|
|
|
|
pageProps.qualifications = getQualificationsFromProfessions(
|
|
|
|
resp.professions.items
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
2021-03-20 14:00:42 +00:00
|
|
|
return {
|
|
|
|
props: pageProps,
|
|
|
|
revalidate: 60,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-03-17 04:04:50 +00:00
|
|
|
export default IndexPage;
|