import Grid from '@material-ui/core/Grid'; import IconButton from '@material-ui/core/IconButton'; import Paper from '@material-ui/core/Paper'; import Table from '@material-ui/core/Table'; import TableBody from '@material-ui/core/TableBody'; import TableCell from '@material-ui/core/TableCell'; import TableHead from '@material-ui/core/TableHead'; import TableRow from '@material-ui/core/TableRow'; import Delete from '@material-ui/icons/Delete'; import Edit from '@material-ui/icons/Edit'; import CloudUpload from '@material-ui/icons/CloudUpload'; import React, {ChangeEvent, Component, SFC} from 'react'; import ConfirmDialog from '../common/ConfirmDialog'; import DefaultPage from '../common/DefaultPage'; import Button from '@material-ui/core/Button'; import CopyableSecret from '../common/CopyableSecret'; import AddApplicationDialog from './AddApplicationDialog'; import {observer} from 'mobx-react'; import {observable} from 'mobx'; import {inject, Stores} from '../inject'; import * as config from '../config'; import UpdateDialog from './UpdateApplicationDialog'; import {IApplication} from '../types'; import {LastUsedCell} from '../common/LastUsedCell'; @observer class Applications extends Component> { @observable private deleteId: number | false = false; @observable private updateId: number | false = false; @observable private createDialog = false; private uploadId = -1; private upload: HTMLInputElement | null = null; public componentDidMount = () => this.props.appStore.refresh(); public render() { const { createDialog, deleteId, updateId, props: {appStore}, } = this; const apps = appStore.getItems(); return ( (this.createDialog = true)}> Create Application } maxWidth={1000}> Name Token Description Priority Last Used {apps.map((app: IApplication) => ( this.uploadImage(app.id)} fDelete={() => (this.deleteId = app.id)} fEdit={() => (this.updateId = app.id)} noDelete={app.internal} /> ))}
(this.upload = upload)} type="file" style={{display: 'none'}} onChange={this.onUploadImage} />
{createDialog && ( (this.createDialog = false)} fOnSubmit={appStore.create} /> )} {updateId !== false && ( (this.updateId = false)} fOnSubmit={(name, description, defaultPriority) => appStore.update(updateId, name, description, defaultPriority) } initialDescription={appStore.getByID(updateId).description} initialName={appStore.getByID(updateId).name} initialDefaultPriority={appStore.getByID(updateId).defaultPriority} /> )} {deleteId !== false && ( (this.deleteId = false)} fOnSubmit={() => appStore.remove(deleteId)} /> )}
); } private uploadImage = (id: number) => { this.uploadId = id; if (this.upload) { this.upload.click(); } }; private onUploadImage = (e: ChangeEvent) => { const file = e.target.files?.[0]; if (!file) { return; } if (['image/png', 'image/jpeg', 'image/gif'].indexOf(file.type) !== -1) { this.props.appStore.uploadImage(this.uploadId, file); } else { alert('Uploaded file must be of type png, jpeg or gif.'); } }; } interface IRowProps { name: string; value: string; noDelete: boolean; description: string; defaultPriority: number; lastUsed: string | null; fUpload: VoidFunction; image: string; fDelete: VoidFunction; fEdit: VoidFunction; } const Row: SFC = observer( ({ name, value, noDelete, description, defaultPriority, lastUsed, fDelete, fUpload, image, fEdit, }) => (
app logo
{name} {description} {defaultPriority}
) ); export default inject('appStore')(Applications);