import React, { useState, useEffect, useReducer } from 'react'; import { BrowserRouter as Router, Switch, Route, Link, useParams, useLocation } from 'react-router-dom'; import moment from 'moment-timezone'; import './light.css'; import { Container, Divider, Dropdown, Form, Grid, Header, Icon, Image, Menu, Message, Popup, Segment, Table } from 'semantic-ui-react'; import { statusColor, BasicTable, staticUrl, requester, isAdmin } from './utils.js'; import { LoginForm, SignupForm } from './LoginSignup.js'; import { AccountForm } from './Account.js'; import { PayPalSubscribeDeal } from './PayPal.js'; function MemberInfo(props) { const user = props.user; const member = user.member; const lastTrans = user.transactions && user.transactions.slice(0,3); const lastCard = user.cards && user.cards.sort((a, b) => a.last_seen_at < b.last_seen_at)[0]; return (
{member.preferred_name} {member.last_name}
Status: {member.status || 'Unknown'} Expiry: {member.expire_date}
{!member.photo_medium && Welcome, new member!

Click here to view your application forms.

} {!!lastTrans.length && !member.photo_medium && Please set a member photo!

Visit the account settings page to set one.

} {!lastTrans.length &&
PayPal

Create a ${user.member.monthly_fees} / month subscription, get your first three months for the price of two:

}
Details
Application: {member.application_date || 'Unknown'} Start: {member.current_start_date || 'Unknown'} Vetted: {member.vetted_date || 'Not vetted'} Monthly: ${member.monthly_fees || 'Unknown'} Card Number: {lastCard && lastCard.card_number || 'None'} {user.cards.length > 1 && [more]} {member.photo_medium &&

View application forms

}
Latest Transactions
{lastTrans.length ? lastTrans.map(x => {x.date} {x.account_type} ${x.amount} ) : None }
); }; export function Home(props) { const { user, token } = props; const [stats, setStats] = useState(JSON.parse(localStorage.getItem('stats', 'false'))); const [refreshCount, refreshStats] = useReducer(x => x + 1, 0); const location = useLocation(); const bypass_code = location.hash.replace('#', ''); useEffect(() => { requester('/stats/', 'GET', token) .then(res => { setStats(res); localStorage.setItem('stats', JSON.stringify(res)); }) .catch(err => { console.log(err); setStats(false); }); }, [refreshCount]); const getStat = (x) => stats && stats[x] ? stats[x] : '?'; const getZeroStat = (x) => stats && stats[x] ? stats[x] : '0'; const getDateStat = (x) => stats && stats[x] ? moment.utc(stats[x]).tz('America/Edmonton').format('ll') : '?'; const mcPlayers = stats && stats['minecraft_players'] ? stats['minecraft_players'] : []; const mumbleUsers = stats && stats['mumble_users'] ? stats['mumble_users'] : []; const getTrackStat = (x) => stats && stats.track && stats.track[x] ? moment().unix() - stats.track[x]['time'] > 60 ? 'Free' : 'In Use' : '?'; const getTrackLast = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').format('llll') : 'Unknown'; const getTrackAgo = (x) => stats && stats.track && stats.track[x] ? moment.unix(stats.track[x]['time']).tz('America/Edmonton').fromNow() : ''; const getTrackName = (x) => stats && stats.track && stats.track[x] && stats.track[x]['username'] ? stats.track[x]['username'] : 'Unknown'; const alarmStat = () => stats && stats.alarm && moment().unix() - stats.alarm['time'] < 300 ? stats.alarm['data'] > 200 ? 'Armed' : 'Disarmed' : 'Unknown'; return ( {user ? user.member.set_details ? :
Please submit your member details

Press submit at the bottom if everything's correct.

:
{bypass_code ? Outside Registration

This page allows you to sign up from outside of Protospace.

: <> Or }
}
Home

Welcome to the Protospace member portal! Here you can view member info, join classes, and manage your membership.

Quick Links

Main Website

Protospace Wiki

Discussion Google Group

Admin Google Group

{!!user &&

Google Drive

} {!!user && isAdmin(user) &&

Property Management Portal

} refreshStats()} />
Protospace Stats

Next member meeting: {getDateStat('next_meeting')}

Next monthly clean: {getDateStat('next_clean')}

Member count: {getStat('member_count')} [more]

Green members: {getStat('green_count')}

Card scans today: {getZeroStat('card_scans')}

Minecraft players: {mcPlayers.length} {mcPlayers.length > 5 && '🔥'}

Server IP:
games.protospace.ca

Players:
{mcPlayers.length ? mcPlayers.map(x => {x}
) : 'None'}

} trigger={[more]} /> {' '}[map]

Mumble users: {mumbleUsers.length}

Server IP:
mumble.protospace.ca

Users:
{mumbleUsers.length ? mumbleUsers.map(x => {x}
) : 'None'}

} trigger={[more]} />

Trotec availability: {getTrackStat('TROTECS300')}

Last use:
{getTrackLast('TROTECS300')}
{getTrackAgo('TROTECS300')}
by {getTrackName('TROTECS300')}

} trigger={[more]} />

Rabbit availability: {getTrackStat('FRICKIN-LASER')}

Last use:
{getTrackLast('FRICKIN-LASER')}
{getTrackAgo('FRICKIN-LASER')}
by {getTrackName('FRICKIN-LASER')}

} trigger={[more]} />

{user && user.member.vetted_date &&

Alarm status: {alarmStat()}

}
); };