import React, { useState, useEffect } from 'react'; import { Link, useParams, useHistory } from 'react-router-dom'; import './light.css'; import { MembersDropdown } from './Members.js'; import { statusColor, isAdmin, BasicTable, requester, useIsMobile } from './utils.js'; import { Button, Checkbox, Container, Form, Grid, Header, Icon, Input, Message, Segment, Table } from 'semantic-ui-react'; export function StorageEditor(props) { const { token, input, setInput, error } = props; const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleChange = (e) => handleValues(e, e.currentTarget); const makeProps = (name) => ({ name: name, onChange: handleChange, value: input[name] || '', error: error[name], }); return (
); }; function EditStorage(props) { const { storage, setStorage, token, refreshUser } = props; const [input, setInput] = useState(storage); const [error, setError] = useState(false); const [loading, setLoading] = useState(false); const [success, setSuccess] = useState(false); const { id } = useParams(); const handleSubmit = (e) => { if (loading) return; setLoading(true); setSuccess(false); const data = { ...input }; return requester('/storage/'+id+'/', 'PUT', token, data) .then(res => { setLoading(false); setSuccess(true); setError(false); setInput(res); setStorage(res); }) .catch(err => { setLoading(false); console.log(err); setError(err.data); }); }; return (
Edit Storage {storage.shelf_id}
Save {success &&
Success!
}
); }; function StorageTable(props) { const { storage, user } = props; const locations = { member_shelves: 'Member Shelves', lockers: 'Lockers', large_project_storage: 'Large Project Storage', }; return ( Shelf ID: {storage.shelf_id} Owner: {storage.member_id ? {storage.member_name} : None } Location: {locations[storage.location]}

Aisle {storage.shelf_id[0]}
Column {storage.shelf_id[1]}
Row {storage.shelf_id[2]}

Memo: {storage.memo || 'None'}
); } export function StorageDetail(props) { const { token, user } = props; const [storage, setStorage] = useState(false); const [error, setError] = useState(false); const { id } = useParams(); useEffect(() => { requester('/storage/' + id + '/', 'GET', token) .then(res => { setStorage(res); setError(false); }) .catch(err => { console.log(err); setError(true); }); }, [id]); return ( {!error ? storage ?
Storage Location

View the list of all storage locations.

{isAdmin(user) ? :
Report Storage

If there's anything wrong with this storage location please email the Protospace Directors:

directors@protospace.ca

Please include a link to this storage location and any relevant details.

}
:

Loading...

:

Error loading.

}
); }; export function StorageButton(props) { const { storage } = props; const history = useHistory(); const buttonColors = { member_shelves: 'grey', lockers: 'blue', large_project_storage: 'brown', }; const handleStorageButton = (e, id) => { e.preventDefault(); history.push('/storage/' + id); }; return ( ); }; let storageSearchCache = ''; export function StorageSearch(props) { const { setSearch } = props; const [input, setInput] = useState(storageSearchCache); const handleChange = (event) => { const q = event.target.value.toUpperCase(); setInput(q); setSearch(q); storageSearchCache = q; }; return (
{input.length ?
); }; let storageListCache = false; let showEmptyCache = false; let showMemodCache = false; let showServedCache = false; let showExpiredCache = false; export function StorageList(props) { const { token } = props; const [storageList, setStorageList] = useState(storageListCache); const [search, setSearch] = useState(storageSearchCache); const [showEmpty, setShowEmpty] = useState(showEmptyCache); const [showMemod, setShowMemod] = useState(showMemodCache); const [showServed, setShowServed] = useState(showServedCache); const [showExpired, setShowExpired] = useState(showExpiredCache); const [error, setError] = useState(false); const isMobile = useIsMobile(); useEffect(() => { requester('/storage/', 'GET', token) .then(res => { setStorageList(res.results); storageListCache = res.results; setError(false); }) .catch(err => { console.log(err); setError(true); }); }, []); const filterStorage = (x) => { if (search.length && !x.shelf_id.startsWith(search)) { return false; } else if (showEmpty && x.member_name) { return false; } else if (showMemod && !x.memo) { return false; } else if (showServed && !x.memo.toLowerCase().includes('served')) { return false; } else if (showExpired && !x.member_paused) { return false; } else { return true; } }; const sortStorage = (a, b) => { if (showExpired) { return a.member_paused !== b.member_paused ? a.member_paused < b.member_paused ? -1 : 1 : 0; } else { return a.shelf_id !== b.shelf_id ? a.shelf_id < b.shelf_id ? -1 : 1 : 0; } }; const handleShowEmpty = (e, v) => { setShowEmpty(v.checked); showEmptyCache = v.checked; }; const handleShowMemod = (e, v) => { setShowMemod(v.checked); showMemodCache = v.checked; }; const handleShowServed = (e, v) => { setShowServed(v.checked); showServedCache = v.checked; }; const handleShowExpired = (e, v) => { setShowExpired(v.checked); showExpiredCache = v.checked; }; const numResults = storageList ? storageList.filter(filterStorage).length : 0; return (

Member shelf
Locker
Large project storage

{!error ? storageList ? <>

{numResults} result{numResults === 1 ? '' : 's'}{showExpired && ', ordered by expiry'}:

{!isMobile && Shelf ID Owner Expired Memo } {storageList.filter(filterStorage).sort(sortStorage).map(x => {isMobile && 'Owner: '} {x.member_name && } {x.member_name} {isMobile && 'Expired: '}{x.member_paused} {isMobile && 'Memo: '}{x.memo} )}
:

Loading...

:

Error loading.

}
); }; export function Storage(props) { const { token, user } = props; return (
Storage Locations
); }; export function ClaimShelfForm(props) { const { token, user, refreshUser } = props; const member = user.member; const [input, setInput] = useState({}); const [error, setError] = useState({}); const [loading, setLoading] = useState(false); const history = useHistory(); const handleValues = (e, v) => setInput({ ...input, [v.name]: v.value }); const handleChange = (e) => handleValues(e, e.currentTarget); const handleSubmit = (e) => { if (loading) return; setLoading(true); requester('/storage/claim/', 'POST', token, input) .then(res => { setError({}); refreshUser(); history.push('/'); }) .catch(err => { setLoading(false); console.log(err); setError(err.data); }); }; const makeProps = (name) => ({ name: name, onChange: handleChange, value: input[name] || '', error: error[name], }); return (

{user.username}

Submit ); }; export function ClaimShelf(props) { const { token, user } = props; return (
Claim Member Shelf

Use this form to claim a member shelf.

Please make sure your name and contact info are visible on the shelf.

Use the Shelf ID visible on the corner label (A1A, A2B, etc.)

); };