From c4337b13cbbb5673dc6b5e580007636f7159bec5 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Thu, 23 Apr 2020 08:39:07 +0200 Subject: [PATCH] Added contact link --- .../Amicale/Clubs/ClubDisplayScreen.js | 144 +++++++++++------- src/screens/Amicale/Clubs/ClubListScreen.js | 2 +- translations/en.json | 2 + translations/fr.json | 2 + 4 files changed, 95 insertions(+), 55 deletions(-) diff --git a/src/screens/Amicale/Clubs/ClubDisplayScreen.js b/src/screens/Amicale/Clubs/ClubDisplayScreen.js index f7a667f..f04ff68 100644 --- a/src/screens/Amicale/Clubs/ClubDisplayScreen.js +++ b/src/screens/Amicale/Clubs/ClubDisplayScreen.js @@ -2,22 +2,35 @@ import * as React from 'react'; import {ScrollView, View} from 'react-native'; -import {Avatar, Card, Chip, Paragraph, withTheme} from 'react-native-paper'; +import {Avatar, Button, Card, Chip, Paragraph, withTheme} from 'react-native-paper'; import ImageModal from 'react-native-image-modal'; import i18n from "i18n-js"; import AuthenticatedScreen from "../../../components/Amicale/AuthenticatedScreen"; import CustomHTML from "../../../components/Overrides/CustomHTML"; import CustomTabBar from "../../../components/Tabbar/CustomTabBar"; +import type {category, club} from "./ClubListScreen"; +import type {CustomTheme} from "../../../managers/ThemeManager"; +import {StackNavigationProp} from "@react-navigation/stack"; +import {Linking} from "expo"; type Props = { - navigation: Object, - route: Object + navigation: StackNavigationProp, + route: { + params?: { + data?: club, + categories?: Array, + clubId?: number, + }, ... + }, + theme: CustomTheme }; type State = { imageModalVisible: boolean, }; +const AMICALE_MAIL = "clubs@amicale-insat.fr"; + /** * Class defining a club event information page. * If called with data and categories navigation parameters, will use those to display the data. @@ -25,32 +38,30 @@ type State = { */ class ClubDisplayScreen extends React.Component { - displayData: Object; - categories: Object | null; + displayData: club | null; + categories: Array | null; clubId: number; shouldFetchData: boolean; - colors: Object; - state = { imageModalVisible: false, }; constructor(props) { super(props); - this.colors = props.theme.colors; - - if (this.props.route.params.data !== undefined && this.props.route.params.categories !== undefined) { - this.displayData = this.props.route.params.data; - this.categories = this.props.route.params.categories; - this.clubId = this.props.route.params.data.id; - this.shouldFetchData = false; - } else { - this.displayData = null; - this.categories = null; - this.clubId = this.props.route.params.clubId; - this.shouldFetchData = true; + if (this.props.route.params != null) { + if (this.props.route.params.data != null && this.props.route.params.categories != null) { + this.displayData = this.props.route.params.data; + this.categories = this.props.route.params.categories; + this.clubId = this.props.route.params.data.id; + this.shouldFetchData = false; + } else if (this.props.route.params.clubId != null) { + this.displayData = null; + this.categories = null; + this.clubId = this.props.route.params.clubId; + this.shouldFetchData = true; + } } } @@ -64,7 +75,7 @@ class ClubDisplayScreen extends React.Component { return ""; } - getCategoriesRender(categories: Array) { + getCategoriesRender(categories: [number, number]) { if (this.categories === null) return null; @@ -84,7 +95,7 @@ class ClubDisplayScreen extends React.Component { return {final}; } - getManagersRender(resp: Array) { + getManagersRender(resp: Array, email: string | null) { let final = []; for (let i = 0; i < resp.length; i++) { final.push({resp[i]}) @@ -98,56 +109,81 @@ class ClubDisplayScreen extends React.Component { left={(props) => } /> {final} + {this.getEmailButton(email, hasManagers)} ); } + getEmailButton(email: string | null, hasManagers: boolean) { + const destinationEmail = email != null && hasManagers + ? email + : AMICALE_MAIL; + const text = email != null && hasManagers + ? i18n.t("clubs.clubContact") + : i18n.t("clubs.amicaleContact"); + return ( + + + + ); + } + updateHeaderTitle(data: Object) { this.props.navigation.setOptions({title: data.name}) } getScreen = (response: Array) => { - let data = response[0]; + let data: club = response[0]; this.updateHeaderTitle(data); + if (data != null) { + return ( + + {this.getCategoriesRender(data.category)} + {data.logo !== null ? + + + : } - return ( - - {this.getCategoriesRender(data.category)} - {data.logo !== null ? - - - : } + {data.description !== null ? + // Surround description with div to allow text styling if the description is not html + + + + : } + {this.getManagersRender(data.responsibles, data.email)} + + ); + } else + return null; - {data.description !== null ? - // Surround description with div to allow text styling if the description is not html - - - - : } - {this.getManagersRender(data.responsibles)} - - ); }; render() { diff --git a/src/screens/Amicale/Clubs/ClubListScreen.js b/src/screens/Amicale/Clubs/ClubListScreen.js index be3146a..c62f03e 100644 --- a/src/screens/Amicale/Clubs/ClubListScreen.js +++ b/src/screens/Amicale/Clubs/ClubListScreen.js @@ -24,7 +24,7 @@ export type club = { name: string, description: string, logo: string, - email:string, + email: string | null, category: [number, number], responsibles: Array, }; diff --git a/translations/en.json b/translations/en.json index aa19f44..8f3c6cd 100644 --- a/translations/en.json +++ b/translations/en.json @@ -261,6 +261,8 @@ "managersUnavailable": "This club has no one :(", "categories": "Categories", "categoriesFilterMessage": "Click on a category to filter the list", + "clubContact": "Contact the club", + "amicaleContact": "Contact the Amicale", "about": { "text": "The clubs, making the campus live, with more than sixty clubs offering various activities! From the philosophy club to the PABI (Production Artisanale de Bière Insaienne), without forgetting the multiple music and dance clubs, you will surely find an activity that suits you!", "title": "A question ?", diff --git a/translations/fr.json b/translations/fr.json index c082137..8fd9430 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -261,6 +261,8 @@ "managersUnavailable": "Ce club est tout seul :(", "categories": "Catégories", "categoriesFilterMessage": "Cliquez sur une catégorie pour filtrer la liste", + "clubContact": "Contacter le club", + "amicaleContact": "Contacter l'Amicale", "about": { "text": "Les clubs, c'est ce qui fait vivre le campus au quotidien, plus d'une soixantaine de clubs qui proposent des activités diverses et variées ! Du club Philosophie au PABI (Production Artisanale de Bière Insaienne), en passant par les multiples clubs de musique et de danse, vous trouverez forcément une activité qui vous permettra de vous épanouir sur le campus !", "title": "Une question ?",