From b9f7704a857048e0b5af02b1e38d0abe028365e7 Mon Sep 17 00:00:00 2001 From: Leo Kivikunnas Date: Mon, 11 Mar 2019 20:29:23 +0200 Subject: [PATCH] Created contactpage --- src/components/ContactCard/ContactCard.scss | 92 +++++++++++++++++++++ src/components/ContactCard/ContactCard.tsx | 26 ++++++ src/components/ContactCard/index.ts | 2 + src/models/Contacts.ts | 22 +++++ src/pages/ContactsPage/ContactsPage.scss | 7 ++ src/pages/ContactsPage/ContactsPage.tsx | 92 +++++++++++++++++++++ src/pages/ContactsPage/index.ts | 2 + src/routes.tsx | 2 + 8 files changed, 245 insertions(+) create mode 100644 src/components/ContactCard/ContactCard.scss create mode 100644 src/components/ContactCard/ContactCard.tsx create mode 100644 src/components/ContactCard/index.ts create mode 100644 src/models/Contacts.ts create mode 100644 src/pages/ContactsPage/ContactsPage.scss create mode 100644 src/pages/ContactsPage/ContactsPage.tsx create mode 100644 src/pages/ContactsPage/index.ts diff --git a/src/components/ContactCard/ContactCard.scss b/src/components/ContactCard/ContactCard.scss new file mode 100644 index 0000000..3f77076 --- /dev/null +++ b/src/components/ContactCard/ContactCard.scss @@ -0,0 +1,92 @@ +@import "../../assets/scss/globals"; + +.contact-card { + background-color: $white; + color: $dark-blue; + white-space: wrap; + margin: 1rem 1rem; + display: flex; + flex-flow: column nowrap; + justify-content: flex-start; + width: calc(25% - 2rem); + + @media screen and (min-width: 1000px) and (max-width: 1200px - 1px) { + width: calc(50% - 2rem); + margin-bottom: 2rem; + } + + @media screen and (max-width: 1000px - 1px) { + width: 100%; + margin-bottom: 3rem; + margin-left: 0; + margin-right: 0; + } + + &__title { + padding: 0.5rem; + margin-bottom: 0.5rem; + display: flex; + justify-content: center; + font-size: 1.5rem; + text-align: center; + font-weight: 300; + color: $black; + } + + &__image { + width: 100%; + height: 300px; + background-repeat: no-repeat; + background-size: cover; + background-position: center center; + margin-bottom: 1rem; + + @media screen and (min-width: 1200px) { + height: 15vw; + } + + @media screen and (max-width: 1200px - 1px) { + height: 35vh; + } + } + + &__button { + display: flex; + justify-content: center; + + button { + height: 100%; + } + } + + &__text { + display: flex; + justify-content: center; + text-align: center; + text-overflow: ellipsis; + font-size: 16px; + margin: 0 0 0.5rem; + font-weight: 200; + line-height: 22px; + color: $black; + + @media screen and (max-width: 1200px - 1px) { + margin: 0.5rem 0; + font-size: 16px; + } + } + + &__datetime { + color: $orange1; + display: flex; + justify-content: center; + text-align: center; + font-size: 0.9rem; + font-weight: bold; + + @media screen and (max-width: 1200px - 1px) { + margin: 0.5rem 0; + font-size: 16px; + } + } +} diff --git a/src/components/ContactCard/ContactCard.tsx b/src/components/ContactCard/ContactCard.tsx new file mode 100644 index 0000000..8d3e16c --- /dev/null +++ b/src/components/ContactCard/ContactCard.tsx @@ -0,0 +1,26 @@ +import * as React from "react"; +import "./ContactCard.scss"; + +export interface ContactCardProps { + first_name: String; + last_name: String; + phone: Number; + email: String; +} +export interface ContactCardState {} + +class ContactCard extends React.Component { + render() { + const { first_name, last_name, phone, email } = this.props; + return ( +
+
{first_name}
+
{last_name}
+
{phone}
+
{email}
+
+ ); + } +} + +export default ContactCard; diff --git a/src/components/ContactCard/index.ts b/src/components/ContactCard/index.ts new file mode 100644 index 0000000..a5b2f63 --- /dev/null +++ b/src/components/ContactCard/index.ts @@ -0,0 +1,2 @@ +import ContactCard from "./ContactCard"; +export default ContactCard; diff --git a/src/models/Contacts.ts b/src/models/Contacts.ts new file mode 100644 index 0000000..13b78b3 --- /dev/null +++ b/src/models/Contacts.ts @@ -0,0 +1,22 @@ +import axios from "axios"; + +const url = `${process.env.API_URL}/contacts`; + +export interface Contact { + id: number; + first_name: string; + last_name: string; + phone_number: number; + email: string; + role: string; +} + +export async function getContacts(): Promise { + try { + const resp = await axios.get(url); + return resp.data["results"]; + } catch (err) { + console.error(err); + throw err; + } +} diff --git a/src/pages/ContactsPage/ContactsPage.scss b/src/pages/ContactsPage/ContactsPage.scss new file mode 100644 index 0000000..3c8525d --- /dev/null +++ b/src/pages/ContactsPage/ContactsPage.scss @@ -0,0 +1,7 @@ +@import "../../assets/scss/globals"; + +.contacts-page { + display: flex; + flex-flow: column wrap; + justify-content: flex-start; +} diff --git a/src/pages/ContactsPage/ContactsPage.tsx b/src/pages/ContactsPage/ContactsPage.tsx new file mode 100644 index 0000000..5c0a1a1 --- /dev/null +++ b/src/pages/ContactsPage/ContactsPage.tsx @@ -0,0 +1,92 @@ +import * as React from "react"; +import Helmet from "react-helmet"; +import "./ContactsPage.scss"; + +import { StaticContext } from "../../server/StaticContext"; +import PageLink from "../../components/PageLink/PageLink"; +import Card from "../../components/Card"; +import { BackgroundColor as PageSectionColor } from "../../components/PageSection/PageSection"; +import PageSection from "../../components/PageSection"; +import HeroMainSection from "../../components/HeroMainSection"; +import ContactCard from "../../components/ContactCard"; +import { Contact, getContacts } from "../../models/Contacts"; + +interface ContactsPageProps { + staticContext: StaticContext; +} + +interface ContactsPageState { + contacts: Contact[]; +} + +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 Contact[]; + this.state = { + contacts, + }; + } else { + this.state = { + contacts: [], + }; + const promiseContacts = this.fetchContacts(); + staticContext.promises.getContacts = promiseContacts; + } + } else { + this.state = { + contacts: [], + }; + this.fetchContacts(); + } + } + + fetchContacts = () => { + const getContactsPromise = getContacts(); + getContactsPromise.then(contacts => { + this.setState({ + contacts, + }); + }); + return getContactsPromise; + } + + render() { + const { contacts } = this.state; + return ( +
+ + + + Contacts Page + +

Aalto-yliopiston Sähköinsinöörikilta

+

+ lorem ipsum dolor est +

+
+ + {contacts.map(contact => ( + + ))} + +
+ ); + } +} + +export default ContactsPage; diff --git a/src/pages/ContactsPage/index.ts b/src/pages/ContactsPage/index.ts new file mode 100644 index 0000000..4c674dc --- /dev/null +++ b/src/pages/ContactsPage/index.ts @@ -0,0 +1,2 @@ +import ContactsPage from "./ContactsPage"; +export default ContactsPage; diff --git a/src/routes.tsx b/src/routes.tsx index 149d6f2..387524e 100644 --- a/src/routes.tsx +++ b/src/routes.tsx @@ -16,6 +16,7 @@ import AdminLoginPage from "./pages/AdminLoginPage"; import { getTokenCookie } from "./auth"; import AdminLogoutPage from "./pages/AdminLogoutPage"; import EventCreatePage from "./pages/EventCreatePage"; +import ContactsPage from "./pages/ContactsPage"; const renderPage = (Page) => (props): JSX.Element => { return ; @@ -32,6 +33,7 @@ const renderAdminPage = (Page) => (props): JSX.Element => { const commonRoutes = [ { path: "/", page: FrontPage }, { path: "/kilta", page: GuildPage }, + { path: "/yhteystiedot", page: ContactsPage} ]; const adminLoginRoutes = [