diff --git a/src/models/Contacts.ts b/src/models/Contacts.ts deleted file mode 100644 index b8ad902..0000000 --- a/src/models/Contacts.ts +++ /dev/null @@ -1,53 +0,0 @@ -import axios from "axios"; - -const url = `${process.env.NEXT_PUBLIC_API_URL}/contacts`; -const committeeUrl = `${process.env.NEXT_PUBLIC_API_URL}/committees`; - -export interface Committee { - name_fi: string; - name_en: string; -} - -export interface Role { - name_fi: string; - name_en: string; - description_fi: string; - description_en: string; - committee: Committee; - is_board: boolean; -} - -export interface Contact { - first_name: string; - last_name: string; - phone_number: number; - email: string; - image: string; -} - -export interface Occupation { - role: Role; - start_date: string; - end_date: string; - officials: Contact[]; -} - -export async function getContacts(year: number = new Date().getFullYear()): Promise { - try { - const resp = await axios.get(`${url}?year=${year}`); - return resp.data["results"]; - } catch (err) { - console.error(err); - throw err; - } -} - -export async function getCommittees(): Promise { - try { - const resp = await axios.get(`${committeeUrl}`); - return resp.data["results"]; - } catch (err) { - console.error(err); - throw err; - } -} diff --git a/src/pages/yhteystiedot.tsx b/src/pages/yhteystiedot.tsx index 50f7ee5..0581f9b 100644 --- a/src/pages/yhteystiedot.tsx +++ b/src/pages/yhteystiedot.tsx @@ -1,86 +1,18 @@ import React from "react"; -import { Helmet } from "react-helmet"; -import { StaticContext } from "@server/StaticContext"; -import { getContacts, Occupation, Committee, getCommittees } from "@models/Contacts"; +import { NextPage } from "next"; +import Head from "next/head"; import ContactsPageView from "@views/ContactsPage/ContactsPageView"; +import PageWrapper from "@views/common/PageWrapper"; -interface ContactsPageProps { - staticContext: StaticContext; -} - -interface ContactsPageState { - contacts: Occupation[]; - committees: Committee[]; -} - -class ContactsPage extends React.Component { - constructor(props: ContactsPageProps) { - super(props); - const { staticContext } = props; - - if (staticContext) { - /* The static context is an object that manages promises when - rendering on the server. If staticContext exists, that means - we have to store all promises in it. Otherwise, operate - normally. See server/index.ts. */ - if (staticContext.resolutions.getContacts) { - const contacts = staticContext.resolutions.getContacts as Occupation[]; - const committees = staticContext.resolutions.getCommittees as Committee[]; - this.state = { - contacts, - committees, - }; - } else { - this.state = { - contacts: [], - committees: [], - }; - const promiseContacts = this.fetchContacts(); - const promiseCommittees = this.fetchCommittees(); - staticContext.promises.getContacts = promiseContacts; - staticContext.promises.getCommittees = promiseCommittees; - } - } else { - this.state = { - contacts: [], - committees: [], - }; - this.fetchContacts(); - this.fetchCommittees(); - } - } - - fetchContacts = () => { - const getContactsPromise = getContacts(); - getContactsPromise.then(contacts => { - this.setState({ - contacts, - }); - }); - return getContactsPromise; - } - - fetchCommittees = () => { - const getCommitteesPromise = getCommittees(); - getCommitteesPromise.then(committees => { - this.setState({ - committees, - }); - }); - return getCommitteesPromise; - } - - render() { - const { contacts, committees } = this.state; - return ( - <> - - - - - - ); - } -} +const ContactsPage: NextPage = () => ( + <> + + + + + + + +); export default ContactsPage;