FacilityStatus.tsx 1.13 KB
Newer Older
1
import * as React from 'react';
Andrew Hrdy's avatar
Andrew Hrdy committed
2
import * as classNames from 'classnames';
3
4
import FacilityUtils from '../utils/facilityUtils';
import { IFacility } from '../models/facility.model';
5
import { Typography } from '@material-ui/core';
6

7
8
9
interface FacilityStatusProps {
    facility: IFacility;
}
10

11
export default ({facility}: FacilityStatusProps) => {
12
    /**
13
14
15
16
     * Generates information about the facility's status.
     *
     * @returns {{label: string, isOpen: boolean}} Information about the facility.
     */
17
    const generateStatusInfo = () => {
18
19
20
        let label;
        let isOpen;

21
        if (FacilityUtils.isFacilityOpen(facility)) {
22
23
24
25
26
27
28
29
30
31
32
            label = 'OPEN';
            isOpen = true;
        } else {
            label = 'CLOSED';
            isOpen = false;
        }

        return {
            label: label,
            isOpen: isOpen
        };
33
    };
34

35
    const statusInfo = generateStatusInfo();
36

37
38
39
40
41
42
43
    return (
        <Typography variant={'caption'}
            className={classNames('facility-status-text', statusInfo.isOpen ? 'facility-status-open' : 'facility-status-closed')}>
            {statusInfo.label}
        </Typography>
    );
};