2022-07-13 06:37:12 +00:00
|
|
|
import React, { useState } from 'react';
|
2020-01-09 22:11:56 +00:00
|
|
|
import './light.css';
|
2021-11-14 03:49:18 +00:00
|
|
|
import moment from 'moment-timezone';
|
2022-07-13 06:37:12 +00:00
|
|
|
import { Button, Container, Header, Table } from 'semantic-ui-react';
|
|
|
|
import { BasicTable, staticUrl } from './utils.js';
|
2020-01-09 22:11:56 +00:00
|
|
|
|
|
|
|
export function Cards(props) {
|
2020-04-23 04:19:46 +00:00
|
|
|
const { user, token } = props;
|
|
|
|
const [open, setOpen] = useState(false);
|
2020-01-09 22:11:56 +00:00
|
|
|
|
|
|
|
const cardStatus = (c) => c.active_status === 'card_active' ? 'Yes' : 'No';
|
|
|
|
const card = user.cards[0];
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Container>
|
2020-03-08 01:12:12 +00:00
|
|
|
<Header size='large'>Cards / Access</Header>
|
|
|
|
|
2021-12-22 05:59:34 +00:00
|
|
|
<Header size='medium'>Your Cards</Header>
|
2020-01-09 22:11:56 +00:00
|
|
|
|
2020-07-13 20:26:30 +00:00
|
|
|
{user.member.card_photo ?
|
|
|
|
<p>
|
|
|
|
<a href={staticUrl + '/' + user.member.card_photo} target='_blank'>
|
|
|
|
Click here
|
|
|
|
</a> to view your card image.
|
|
|
|
</p>
|
|
|
|
:
|
|
|
|
<p>Upload a photo to generate a card image.</p>
|
|
|
|
}
|
|
|
|
|
2020-01-09 22:11:56 +00:00
|
|
|
{user.cards.length ?
|
|
|
|
user.cards.length > 1 ?
|
|
|
|
<Table basic='very'>
|
|
|
|
<Table.Header>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.HeaderCell>Number</Table.HeaderCell>
|
|
|
|
<Table.HeaderCell>Notes</Table.HeaderCell>
|
2022-01-14 00:32:21 +00:00
|
|
|
<Table.HeaderCell>Last Scan</Table.HeaderCell>
|
2020-01-09 22:11:56 +00:00
|
|
|
<Table.HeaderCell>Active</Table.HeaderCell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Header>
|
|
|
|
|
|
|
|
<Table.Body>
|
2020-01-18 01:36:53 +00:00
|
|
|
{user.cards.map(x =>
|
|
|
|
<Table.Row key={x.id}>
|
2020-01-09 22:11:56 +00:00
|
|
|
<Table.Cell>{x.card_number}</Table.Cell>
|
|
|
|
<Table.Cell>{x.notes}</Table.Cell>
|
2021-11-14 03:49:18 +00:00
|
|
|
<Table.Cell>
|
|
|
|
{x.last_seen ?
|
|
|
|
x.last_seen > '2021-11-14T02:01:35.415685Z' ?
|
|
|
|
moment.utc(x.last_seen).tz('America/Edmonton').format('lll')
|
|
|
|
:
|
|
|
|
moment.utc(x.last_seen).tz('America/Edmonton').format('ll')
|
|
|
|
:
|
|
|
|
'Unknown'
|
|
|
|
}
|
|
|
|
</Table.Cell>
|
2020-01-09 22:11:56 +00:00
|
|
|
<Table.Cell>{cardStatus(x)}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
)}
|
|
|
|
</Table.Body>
|
|
|
|
</Table>
|
|
|
|
:
|
2020-01-11 23:53:42 +00:00
|
|
|
<BasicTable>
|
2020-01-09 22:11:56 +00:00
|
|
|
<Table.Body>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Number:</Table.Cell>
|
|
|
|
<Table.Cell>{card.card_number}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Notes:</Table.Cell>
|
|
|
|
<Table.Cell>{card.notes}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Last Seen:</Table.Cell>
|
2021-11-14 03:49:18 +00:00
|
|
|
<Table.Cell>
|
|
|
|
{card.last_seen ?
|
|
|
|
card.last_seen > '2021-11-14T02:01:35.415685Z' ?
|
|
|
|
moment.utc(card.last_seen).tz('America/Edmonton').format('lll')
|
|
|
|
:
|
|
|
|
moment.utc(card.last_seen).tz('America/Edmonton').format('ll')
|
|
|
|
:
|
|
|
|
'Unknown'
|
|
|
|
}
|
|
|
|
</Table.Cell>
|
2020-01-09 22:11:56 +00:00
|
|
|
</Table.Row>
|
|
|
|
<Table.Row>
|
|
|
|
<Table.Cell>Active:</Table.Cell>
|
|
|
|
<Table.Cell>{cardStatus(card)}</Table.Cell>
|
|
|
|
</Table.Row>
|
|
|
|
</Table.Body>
|
2020-01-11 23:53:42 +00:00
|
|
|
</BasicTable>
|
2020-01-09 22:11:56 +00:00
|
|
|
:
|
|
|
|
<p>No cards yet! Ask a director for one after you are vetted.</p>
|
|
|
|
}
|
|
|
|
|
2020-04-23 04:19:46 +00:00
|
|
|
{!!user.door_code && <React.Fragment>
|
2020-03-08 01:12:12 +00:00
|
|
|
<Header size='medium'>Door Alarm Code</Header>
|
|
|
|
|
|
|
|
<p>Only share this with vetted Protospace members:</p>
|
|
|
|
|
|
|
|
<p>{user.door_code}</p>
|
2020-04-23 04:19:46 +00:00
|
|
|
</React.Fragment>}
|
2020-03-08 01:12:12 +00:00
|
|
|
|
2020-04-23 04:19:46 +00:00
|
|
|
{!!user.wifi_pass && <React.Fragment>
|
2020-03-08 01:12:12 +00:00
|
|
|
<Header size='medium'>Wi-Fi Password</Header>
|
|
|
|
|
|
|
|
<p>Only share this with Protospace members and guests:</p>
|
|
|
|
|
|
|
|
<p>{user.wifi_pass}</p>
|
2020-04-23 04:19:46 +00:00
|
|
|
</React.Fragment>}
|
|
|
|
|
|
|
|
<Header size='medium'>API Key</Header>
|
|
|
|
|
|
|
|
<p>Don't share this with anyone! Treat it like your password:</p>
|
|
|
|
|
|
|
|
{open ?
|
|
|
|
<React.Fragment>
|
|
|
|
<p>{token}</p>
|
|
|
|
|
|
|
|
<Header size='small'>API Docs</Header>
|
|
|
|
|
|
|
|
<p>
|
|
|
|
To learn how to use this, refer to the API docs:
|
|
|
|
<br />
|
|
|
|
<a href='https://docs.my.protospace.ca/api.html' target='_blank' rel='noopener noreferrer' aria-label='link to our API docs'>
|
|
|
|
https://docs.my.protospace.ca/api.html
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<Header size='small'>API Examples</Header>
|
|
|
|
|
|
|
|
<p>Get your user info with Bash (curl):</p>
|
|
|
|
|
|
|
|
<p><code>$ curl -H "Authorization: Token {token}" https://api.my.protospace.ca/user/</code></p>
|
|
|
|
|
|
|
|
<p>Get your user info with Python 3 (and requests):</p>
|
|
|
|
|
|
|
|
<code>
|
|
|
|
import json, requests<br/>
|
|
|
|
<br />
|
|
|
|
SECRET_API_KEY = '{token}'<br />
|
|
|
|
<br />
|
|
|
|
headers = {'{'}'Authorization': 'Token '+SECRET_API_KEY{'}'}<br />
|
|
|
|
r = requests.get('https://api.my.protospace.ca/user/', headers=headers)<br />
|
|
|
|
<br />
|
|
|
|
print(json.dumps(r.json(), indent=4))<br />
|
|
|
|
</code>
|
|
|
|
</React.Fragment>
|
|
|
|
:
|
|
|
|
<p>
|
|
|
|
<Button onClick={() => setOpen(true)}>
|
|
|
|
Show Secret
|
|
|
|
</Button>
|
|
|
|
</p>
|
|
|
|
}
|
2020-01-09 22:11:56 +00:00
|
|
|
</Container>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|