import React, { useState, useEffect, useReducer } from 'react'; import { Link, useParams, useHistory } from 'react-router-dom'; import moment from 'moment-timezone'; import QRCode from 'react-qr-code'; import './light.css'; import { Button, Container, Divider, Grid, Header, Icon, Image, Message, Popup, Segment, Table } from 'semantic-ui-react'; import { statusColor, BasicTable, siteUrl, staticUrl, requester, isAdmin } from './utils.js'; import { LoginForm, SignupForm } from './LoginSignup.js'; import { AccountForm } from './Account.js'; import { SignForm } from './Sign.js'; import { StorageButton } from './Storage.js'; import { PayPalSubscribeDeal } from './PayPal.js'; function MemberInfo(props) { const user = props.user; const member = user.member; const history = useHistory(); const lastTrans = user.transactions?.slice(0,3); const lastTrain = user.training?.sort((a, b) => a.session.datetime < b.session.datetime ? 1 : -1).slice(0,3); const lastCard = user.cards?.sort((a, b) => a.last_seen < b.last_seen)[0]; const unpaidTraining = user.training?.filter(x => x.attendance_status === 'Waiting for payment'); return (
{member.protocoin < 0 && Your Protocoin balance is negative!

Visit the Paymaster page or pay a Director to buy Protocoin.

}
{member.preferred_name} {member.last_name}
{member.is_allowed_entry ? <> :

You are not allowed entry into Protospace ❌

} Status: {member.status || 'Unknown'} Protocoin: ₱ {member.protocoin.toFixed(2)} [buy] Shelf: {user.storage.length ? user.storage.sort((a, b) => a.location === 'member_shelves' ? -1 : 1).map((x, i) => ) : <>None [claim] } Expiry: {member.expire_date ? moment(member.expire_date).format('ll') : 'Unknown'}
{!lastTrans.length && Welcome, new member!

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:

Click "Checkout as Guest" if you don't have a PayPal account.

{x.session.course_data.name} to avoid losing your spot.

)}
Latest Training
{!member.orientation_date &&

⚠️ You need to attend a New Member Orientation to use any tool larger than a screwdriver.

} {lastTrain.length ? lastTrain.map(x => {moment(x.session.datetime).tz('America/Edmonton').format('ll')} {x.session.course_data.name} ) : None } {user.training.length > 3 && [more] }
Latest Transactions
{lastTrans.length ? lastTrans.map(x => {moment(x.date).format('ll')} {x.account_type} {x.protocoin !== '0.00' ? '₱ ' + x.protocoin : '$ ' + x.amount} ) : None } {user.transactions.length > 3 && [more] }
Details
Application: {member.application_date ? moment(member.application_date).format('ll') : 'Unknown'} Start: {member.current_start_date ? moment(member.current_start_date).format('ll') : 'Unknown'} Vetted: {member.vetted_date ? moment(member.vetted_date).format('ll') : 'Not vetted'} Monthly dues: ${member.monthly_fees || 'Unknown'}.00 Last scan: {lastCard && lastCard.last_seen ? lastCard.last_seen > '2021-11-14T02:01:35.415685Z' ? moment.utc(lastCard.last_seen).tz('America/Edmonton').format('lll') : moment.utc(lastCard.last_seen).tz('America/Edmonton').format('ll') : 'Unknown' } {user.cards.length > 1 && [more]} {!!lastTrans.length &&

View application forms

}
); }; 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); useEffect(() => { requester('/stats/', 'GET', token) .then(res => { setStats(res); localStorage.setItem('stats', JSON.stringify(res)); }) .catch(err => { console.log(err); setStats(false); }); }, [refreshCount, token]); const getStat = (x) => stats && stats[x] ? stats[x] : 'Unknown'; const getZeroStat = (x) => stats && stats[x] ? stats[x] : '0'; const getDateStat = (x) => stats && stats[x] ? moment.utc(stats[x]).tz('America/Edmonton').format('MMM Do @ LT') : 'Unknown'; const getNextStat = (x) => { if (stats && stats[x]) { const datetime = moment.utc(stats[x].datetime).tz('America/Edmonton'); if (datetime.isSame(moment().tz('America/Edmonton'), 'day') ) { return <>{datetime.format('LT')} | {stats[x].name}; } else { return <>{datetime.format('MMM Do')} | {stats[x].name}; } } else { return 'Unknown'; } }; 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' : 'Unknown'; 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]['first_name'] ? stats.track[x]['first_name'] : 'Unknown'; const alarmStat = () => stats && stats.alarm ? stats.alarm.toString() : 'Unknown'; // toString prevents crash from cached alarm Object const closedStat = (x) => stats && stats.closing ? moment().unix() > stats.closing['time'] ? 'Closed' : 'Open until ' + stats.closing['time_str'] + ' with ' + stats.closing['first_name'] : 'Unknown'; const printer3dStat = (x) => stats && stats.printer3d && stats.printer3d[x] ? stats.printer3d[x].state === 'Printing' ? 'Printing (' + stats.printer3d[x].progress + '%)' : stats.printer3d[x].state : 'Unknown'; const show_signup = stats?.at_protospace; return ( {user ? user.member.set_details ? : :
Or
}
{user?.member?.set_details !== false &&
Quick Links

Main Website

Protospace Wiki[register]

Forum (Spacebar)[register]

{!!user &&

Google Drive

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

Property Management Portal

} refreshStats()} />
Protospace Stats

Next meeting: {getDateStat('next_meeting')}

Next clean: {getDateStat('next_clean')}

Next class: {getNextStat('next_class')}

Last class: {getNextStat('prev_class')}

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

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]

{stats && stats.hasOwnProperty('mumble_users') &&

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]} />

Precix availability: {getTrackStat('CNC-PRECIX')}

Last use:
{getTrackLast('CNC-PRECIX')}
{getTrackAgo('CNC-PRECIX')}
by {getTrackName('CNC-PRECIX')}

} trigger={[more]} />

Media computer: {getTrackStat('PROTOGRAPH1')}

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

Last print:
{getTrackLast('LASTLARGEPRINT')}
{getTrackAgo('LASTLARGEPRINT')}
by {getTrackName('LASTLARGEPRINT')}

} trigger={[more]} />

ORD2 printer: {printer3dStat('ord2')}

ORD3 printer: {printer3dStat('ord3')}

{user ?

Alarm status: {alarmStat()}

:

Alarm status: Unauthorized

} {user &&

Hosting status: {closedStat()}

}

Protogarden:

}
); };