1 import { Component, linkEvent } from 'inferno';
2 import { Site, SiteForm as SiteFormI } from '../interfaces';
3 import { WebSocketService } from '../services';
4 import * as autosize from 'autosize';
6 interface SiteFormProps {
7 site?: Site; // If a site is given, that means this is an edit
11 interface SiteFormState {
16 export class SiteForm extends Component<SiteFormProps, SiteFormState> {
17 private emptyState: SiteFormState ={
24 constructor(props: any, context: any) {
25 super(props, context);
26 this.state = this.emptyState;
30 autosize(document.querySelectorAll('textarea'));
35 <form onSubmit={linkEvent(this, this.handleCreateSiteSubmit)}>
36 <h5>{`${this.props.site ? 'Edit' : 'Name'} your Site`}</h5>
37 <div class="form-group row">
38 <label class="col-12 col-form-label">Name</label>
40 <input type="text" class="form-control" value={this.state.siteForm.name} onInput={linkEvent(this, this.handleSiteNameChange)} required minLength={3} maxLength={20} />
43 <div class="form-group row">
44 <label class="col-12 col-form-label">Sidebar</label>
46 <textarea value={this.state.siteForm.description} onInput={linkEvent(this, this.handleSiteDescriptionChange)} class="form-control" rows={3} />
49 <div class="form-group row">
51 <button type="submit" class="btn btn-secondary mr-2">
53 <svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg> :
54 this.props.site ? 'Save' : 'Create'}</button>
55 {this.props.site && <button type="button" class="btn btn-secondary" onClick={linkEvent(this, this.handleCancel)}>Cancel</button>}
62 handleCreateSiteSubmit(i: SiteForm, event: any) {
63 event.preventDefault();
64 i.state.loading = true;
66 WebSocketService.Instance.editSite(i.state.siteForm);
68 WebSocketService.Instance.createSite(i.state.siteForm);
73 handleSiteNameChange(i: SiteForm, event: any) {
74 i.state.siteForm.name = event.target.value;
78 handleSiteDescriptionChange(i: SiteForm, event: any) {
79 i.state.siteForm.description = event.target.value;
83 handleCancel(i: SiteForm) {