Commit e542732b authored by Nikolai R Kristiansen's avatar Nikolai R Kristiansen

馃帹 Fix linter errors and refactor abit

parent 148ea8e7
Pipeline #707 failed with stage
in 1 minute and 47 seconds
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
"no-underscore-dangle": 0, "no-underscore-dangle": 0,
"no-param-reassign": 0, "no-param-reassign": 0,
"react/prefer-stateless-function": 1, "react/prefer-stateless-function": 1,
"react/prop-types": 1, // FIXME: refactor
"class-methods-use-this": 1, // FIXME: refactor
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react/sort-comp": 0, "react/sort-comp": 0,
"max-len": 0, "max-len": 0,
......
import React, { Component } from 'react'; import React from 'react';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { PersistGate } from 'redux-persist/es/integration/react'; import { PersistGate } from 'redux-persist/es/integration/react';
import Config from 'react-native-config'; import Config from 'react-native-config';
...@@ -15,16 +15,14 @@ const apolloClient = new ApolloClient({ ...@@ -15,16 +15,14 @@ const apolloClient = new ApolloClient({
cache: new InMemoryCache(), cache: new InMemoryCache(),
}); });
export default class App extends Component { export default function App() {
render() { return (
return ( <Provider store={store}>
<Provider store={store}> <PersistGate loading={null} persistor={persistor}>
<PersistGate loading={null} persistor={persistor}> <ApolloProvider client={apolloClient}>
<ApolloProvider client={apolloClient}> <Dusken />
<Dusken /> </ApolloProvider>
</ApolloProvider> </PersistGate>
</PersistGate> </Provider>
</Provider> );
);
}
} }
import React, { Component } from 'react'; import React from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Root } from 'native-base'; import { Root } from 'native-base';
import DuskenNavigation from './navigation'; import DuskenNavigation from './navigation';
class DuskenContainer extends Component { const DuskenContainer = () => (
render() { <Root>
return ( <DuskenNavigation />
<Root> </Root>
<DuskenNavigation /> );
</Root>
);
}
}
export default connect()(DuskenContainer); export default connect()(DuskenContainer);
...@@ -51,7 +51,7 @@ export function requestLogin(username, password) { ...@@ -51,7 +51,7 @@ export function requestLogin(username, password) {
}; };
} }
export function requestUserData(auth_token) { export function requestUserData(authToken) {
return (dispatch) => { return (dispatch) => {
// We are now fetching user data // We are now fetching user data
dispatch(userDataRequest()); dispatch(userDataRequest());
...@@ -61,7 +61,7 @@ export function requestUserData(auth_token) { ...@@ -61,7 +61,7 @@ export function requestUserData(auth_token) {
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Token ${auth_token}`, Authorization: `Token ${authToken}`,
}, },
}) })
.then((response) => response.json().then((json) => ({ json, response }))) .then((response) => response.json().then((json) => ({ json, response })))
...@@ -118,7 +118,7 @@ export function requestRegisterUser(firstName, lastName, email, phoneNumber, pas ...@@ -118,7 +118,7 @@ export function requestRegisterUser(firstName, lastName, email, phoneNumber, pas
}; };
} }
export function requestMembershipCharge(auth_token, stripe_token, membership_type) { export function requestMembershipCharge(authToken, stripeToken, membershipType) {
return (dispatch) => { return (dispatch) => {
dispatch(membershipChargeRequest()); dispatch(membershipChargeRequest());
...@@ -127,11 +127,11 @@ export function requestMembershipCharge(auth_token, stripe_token, membership_typ ...@@ -127,11 +127,11 @@ export function requestMembershipCharge(auth_token, stripe_token, membership_typ
headers: { headers: {
Accept: 'application/json', Accept: 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: `Token ${auth_token}`, Authorization: `Token ${authToken}`,
}, },
body: JSON.stringify({ body: JSON.stringify({
stripe_token, stripe_token: stripeToken,
membership_type, membership_type: membershipType,
payment_method: 'app', payment_method: 'app',
}), }),
}) })
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Text, ScrollView, View, Platform, StyleSheet, Image, Linking, TouchableOpacity } from 'react-native'; import { Text, View, Platform, StyleSheet, Image, Linking, TouchableOpacity } from 'react-native';
// import HTMLView from 'react-native-htmlview'; import { ScrollView } from 'react-navigation';
import { Button, Text as NBText, Icon } from 'native-base'; import { Button, Text as NBText, Icon } from 'native-base';
import theme from '../../theme'; import theme from '../../theme';
...@@ -140,8 +140,6 @@ export default class About extends Component { ...@@ -140,8 +140,6 @@ export default class About extends Component {
Alle studentforeninger i Oslo kan arrangere gratis p氓 Chateau Neuf. Skal du arrangere en fest, sette en Alle studentforeninger i Oslo kan arrangere gratis p氓 Chateau Neuf. Skal du arrangere en fest, sette en
konsert, holde et foredrag eller gjennomf酶re et m酶te, har vi lokaler som kan brukes til dette. konsert, holde et foredrag eller gjennomf酶re et m酶te, har vi lokaler som kan brukes til dette.
</Text> </Text>
{/* <HTMLView style={styles.content} stylesheet={HTMLStyles} value={this.props.openingHours}/> */}
</View> </View>
</ScrollView> </ScrollView>
); );
......
import { connect } from 'react-redux'; import React from 'react';
import React, { Component } from 'react';
import About from './About'; import About from './About';
class AboutContainer extends Component { const AboutContainer = () => <About />;
render() {
return <About {...this.state} />;
}
}
export default connect()(AboutContainer); export default AboutContainer;
...@@ -3,6 +3,7 @@ import { Linking, StyleSheet, ScrollView, Text, Platform, View, Image, Touchable ...@@ -3,6 +3,7 @@ import { Linking, StyleSheet, ScrollView, Text, Platform, View, Image, Touchable
import HTMLView from 'react-native-htmlview'; import HTMLView from 'react-native-htmlview';
import moment from 'moment'; import moment from 'moment';
import { Icon } from 'native-base'; import { Icon } from 'native-base';
import theme from '../../theme'; import theme from '../../theme';
moment.locale('nb'); moment.locale('nb');
...@@ -44,8 +45,8 @@ export default class EventDetail extends Component { ...@@ -44,8 +45,8 @@ export default class EventDetail extends Component {
_formatTicketText() { _formatTicketText() {
/* FIXME: This should be handled by API */ /* FIXME: This should be handled by API */
const { item } = this.props; const { item } = this.props;
let reg_kr = ''; let regularPrice = '';
let mem_kr = ''; let memberPrice = '';
if (item.price_regular === '0') { if (item.price_regular === '0') {
item.price_regular = 'Gratis'; item.price_regular = 'Gratis';
} }
...@@ -53,19 +54,19 @@ export default class EventDetail extends Component { ...@@ -53,19 +54,19 @@ export default class EventDetail extends Component {
item.price_member = 'Gratis'; item.price_member = 'Gratis';
} }
if (item.price_regular !== 'Gratis') { if (item.price_regular !== 'Gratis') {
reg_kr = ' kr'; regularPrice = ' kr';
} }
if (item.price_member !== 'Gratis') { if (item.price_member !== 'Gratis') {
mem_kr = ' kr'; memberPrice = ' kr';
} }
let text = ''; let text = '';
if (item.price_regular && item.price_member) { if (item.price_regular && item.price_member) {
text = `Pris: ${item.price_regular}${reg_kr} / Medlemmer: ${item.price_member}${mem_kr}`; text = `Pris: ${item.price_regular}${regularPrice} / Medlemmer: ${item.price_member}${memberPrice}`;
} else if (item.price_regular) { } else if (item.price_regular) {
text = `Pris: ${item.price_regular}${reg_kr}`; text = `Pris: ${item.price_regular}${regularPrice}`;
} else if (item.price_member) { } else if (item.price_member) {
text = `Pris (Medlemmer): ${item.price_member}${mem_kr}`; text = `Pris (Medlemmer): ${item.price_member}${memberPrice}`;
} else { } else {
return ''; return '';
} }
...@@ -108,7 +109,7 @@ export default class EventDetail extends Component { ...@@ -108,7 +109,7 @@ export default class EventDetail extends Component {
const text = this._formatTicketText(); const text = this._formatTicketText();
if (text === '') { if (text === '') {
return; return null;
} }
if (item.ticket_url) { if (item.ticket_url) {
...@@ -141,7 +142,7 @@ export default class EventDetail extends Component { ...@@ -141,7 +142,7 @@ export default class EventDetail extends Component {
showFacebutton() { showFacebutton() {
const { item } = this.props; const { item } = this.props;
if (!item.facebook_url) { if (!item.facebook_url) {
return; return null;
} }
return ( return (
...@@ -162,6 +163,8 @@ export default class EventDetail extends Component { ...@@ -162,6 +163,8 @@ export default class EventDetail extends Component {
if (item.thumbnail.medium_large) { if (item.thumbnail.medium_large) {
return <Image source={{ uri: item.thumbnail.medium_large }} style={styles.image} />; return <Image source={{ uri: item.thumbnail.medium_large }} style={styles.image} />;
} }
return null;
} }
showYear() { showYear() {
...@@ -170,6 +173,8 @@ export default class EventDetail extends Component { ...@@ -170,6 +173,8 @@ export default class EventDetail extends Component {
if (moment().year() !== moment(item.start_time).year()) { if (moment().year() !== moment(item.start_time).year()) {
return <Text style={styles.year}>{this._formatYear(item.start_time)}</Text>; return <Text style={styles.year}>{this._formatYear(item.start_time)}</Text>;
} }
return null;
} }
render() { render() {
......
import { StyleSheet, View, Platform } from 'react-native'; import { StyleSheet, View, Platform } from 'react-native';
import { SectionList } from 'react-navigation'; import { SectionList } from 'react-navigation';
import { Card, ListItem, CardItem, Body, Text, Left, Right, Icon, Button, Content, Spinner } from 'native-base'; import { Card, ListItem, CardItem, Body, Text, Right, Icon, Button, Content, Spinner } from 'native-base';
import React, { Component } from 'react'; import React, { Component } from 'react';
import moment from 'moment'; import moment from 'moment';
import 'moment/locale/nb'; import 'moment/locale/nb';
...@@ -64,11 +64,7 @@ export default class EventList extends Component { ...@@ -64,11 +64,7 @@ export default class EventList extends Component {
return ( return (
<Content> <Content>
<Card style={{ margin: 4 }}> <Card style={{ margin: 4 }}>
<CardItem <CardItem>
onPress={() => {
this._onPressItem(item);
}}
>
<Text style={styles.loadingText}>Kunne ikke hente programmet...</Text> <Text style={styles.loadingText}>Kunne ikke hente programmet...</Text>
</CardItem> </CardItem>
<CardItem> <CardItem>
......
...@@ -6,6 +6,7 @@ import moment from 'moment'; ...@@ -6,6 +6,7 @@ import moment from 'moment';
import 'moment/locale/nb'; import 'moment/locale/nb';
import EventList from './EventList'; import EventList from './EventList';
import { fetchWithTimeout } from '../../utils';
moment.locale('nb'); moment.locale('nb');
...@@ -35,7 +36,7 @@ class EventListContainer extends Component { ...@@ -35,7 +36,7 @@ class EventListContainer extends Component {
_toSectionFormat(events) { _toSectionFormat(events) {
const sectioned = {}; const sectioned = {};
events.map((event) => { events.forEach((event) => {
const title = this._formatDate(event.start_time); const title = this._formatDate(event.start_time);
if (title in sectioned) { if (title in sectioned) {
sectioned[title].push(event); sectioned[title].push(event);
...@@ -84,9 +85,9 @@ class EventListContainer extends Component { ...@@ -84,9 +85,9 @@ class EventListContainer extends Component {
const url = `${Config.EVENT_API_URL}/wp-json/wp/v2/events?page=${page}&future=1`; const url = `${Config.EVENT_API_URL}/wp-json/wp/v2/events?page=${page}&future=1`;
this.setState({ loading: true }); this.setState({ loading: true });
fetch(url) fetchWithTimeout(url)
.then((res) => { .then((res) => {
this.setState({ totalPages: parseInt(res.headers.get('x-wp-totalpages')) }); this.setState({ totalPages: parseInt(res.headers.get('x-wp-totalpages'), 10) });
return res.json(); return res.json();
}) })
.then((res) => { .then((res) => {
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Linking, StyleSheet, View, Platform } from 'react-native'; import { Linking, StyleSheet, View } from 'react-native';
import { Container, Header, Content, Form, Item, Input, Label, Spinner, Button, Text, Icon } from 'native-base'; import { Container, Content, Form, Item, Input, Label, Spinner, Button, Text } from 'native-base';
import Config from 'react-native-config'; import Config from 'react-native-config';
import theme from '../../theme'; import theme from '../../theme';
...@@ -26,7 +26,7 @@ export default class Login extends Component { ...@@ -26,7 +26,7 @@ export default class Login extends Component {
returnKeyType="next" returnKeyType="next"
onChangeText={this.handleEmail} onChangeText={this.handleEmail}
onSubmitEditing={() => { onSubmitEditing={() => {
this.refs.passwordInput._root.focus(); this.passwordInputRef._root.focus();
}} }}
/> />
</Item> </Item>
...@@ -44,7 +44,7 @@ export default class Login extends Component { ...@@ -44,7 +44,7 @@ export default class Login extends Component {
returnKeyType="next" returnKeyType="next"
onChangeText={this.handleEmail} onChangeText={this.handleEmail}
onSubmitEditing={() => { onSubmitEditing={() => {
this.refs.passwordInput._root.focus(); this.passwordInputRef._root.focus();
}} }}
/> />
</Item> </Item>
...@@ -57,7 +57,9 @@ export default class Login extends Component { ...@@ -57,7 +57,9 @@ export default class Login extends Component {
<Item stackedLabel last error> <Item stackedLabel last error>
<Label>Passord</Label> <Label>Passord</Label>
<Input <Input
ref="passwordInput" ref={(ref) => {
this.passwordInputRef = ref;
}}
secureTextEntry={true} secureTextEntry={true}
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
...@@ -71,7 +73,9 @@ export default class Login extends Component { ...@@ -71,7 +73,9 @@ export default class Login extends Component {
<Item stackedLabel last> <Item stackedLabel last>
<Label>Passord</Label> <Label>Passord</Label>
<Input <Input
ref="passwordInput" ref={(ref) => {
this.passwordInputRef = ref;
}}
secureTextEntry={true} secureTextEntry={true}
autoCapitalize="none" autoCapitalize="none"
autoCorrect={false} autoCorrect={false}
...@@ -125,11 +129,7 @@ export default class Login extends Component { ...@@ -125,11 +129,7 @@ export default class Login extends Component {
return <View style={styles.errorBox} />; return <View style={styles.errorBox} />;
}; };
showSpinner = () => { showSpinner = () => (this.props.isLoggingIn ? <Spinner color="#f58220" /> : null);
if (this.props.isLoggingIn) {
return <Spinner color="#f58220" />;
}
};
handleEmail = (text) => { handleEmail = (text) => {
this.setState({ email: text }); this.setState({ email: text });
......
...@@ -44,7 +44,7 @@ export default class Proof extends Component { ...@@ -44,7 +44,7 @@ export default class Proof extends Component {
membershipValidTo() { membershipValidTo() {
if (!this.props.user.last_membership) { if (!this.props.user.last_membership) {
return; return null;
} }
let validTo = this.props.user.last_membership.end_date; let validTo = this.props.user.last_membership.end_date;
...@@ -63,7 +63,7 @@ export default class Proof extends Component { ...@@ -63,7 +63,7 @@ export default class Proof extends Component {
membershipStatus() { membershipStatus() {
if (!this.props.user.is_member) { if (!this.props.user.is_member) {
if (!this.props.user.last_membership) { if (!this.props.user.last_membership) {
return; return null;
} }
return ( return (
...@@ -86,7 +86,7 @@ export default class Proof extends Component { ...@@ -86,7 +86,7 @@ export default class Proof extends Component {
purchaseButton() { purchaseButton() {
if (this.props.user.is_member) { if (this.props.user.is_member) {
return; return null;
} }
return ( return (
...@@ -108,15 +108,24 @@ export default class Proof extends Component { ...@@ -108,15 +108,24 @@ export default class Proof extends Component {
} }
confetti() { confetti() {
if (this.props.user.is_member) { if (!this.props.user.is_member) {
// Confetti!!!! return null;
return <Confetti ref={(node) => (this._confettiView = node)} confettiCount={Number.MAX_SAFE_INTEGER} />;
} }
// Confetti!!!!
return (
<Confetti
ref={(node) => {
this._confettiView = node;
}}
confettiCount={Number.MAX_SAFE_INTEGER}
/>
);
} }
logo() { logo() {
if (!this.props.user.is_member) { if (!this.props.user.is_member) {
return; return null;
} }
// FIXME: URL to config // FIXME: URL to config
...@@ -133,7 +142,7 @@ export default class Proof extends Component { ...@@ -133,7 +142,7 @@ export default class Proof extends Component {
chargeError() { chargeError() {
if (!this.props.chargeError) { if (!this.props.chargeError) {
return; return null;
} }
return ( return (
......
...@@ -62,7 +62,7 @@ class ProofContainer extends Component { ...@@ -62,7 +62,7 @@ class ProofContainer extends Component {
membershipTypeSlug membershipTypeSlug
); );
}, },
(error) => { () => {
/* FIXME: Happens only if card dialog is canceled? */ /* FIXME: Happens only if card dialog is canceled? */
} }
); );
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Container, Header, Content, Form, Item, Input, Label, Spinner, Button, Text, Icon, Toast } from 'native-base'; import { Container, Content, Form, Item, Input, Label, Spinner, Button, Text, Icon, Toast } from 'native-base';
import { StyleSheet, View } from 'react-native'; import { StyleSheet, View } from 'react-native';
import EmailValidator from 'email-validator'; import * as EmailValidator from 'email-validator';
import theme from '../../theme'; import theme from '../../theme';
...@@ -27,7 +27,7 @@ export default class UserRegister extends Component { ...@@ -27,7 +27,7 @@ export default class UserRegister extends Component {
const touched = new Set(this.state.touched).add(triggeredBy); const touched = new Set(this.state.touched).add(triggeredBy);
/* No empty fields */ /* No empty fields */
for (const key of fieldNames) { fieldNames.forEach((key) => {
const value = this.state[key]; const value = this.state[key];
if (value === '') { if (value === '') {
errors[key] = 'kan ikke v忙re tomt';