Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | 3x 3x 3x 3x 1x 1x 1x 1x 3x 19x 3x 1x 1x 3x 2x 3x 3x 3x 3x 3x 1x 3x 3x 3x 9x 3x 18x 9x | import React from 'react'; import {Activity} from "../generated/api"; import {Button} from 'primereact/button'; import {InputText} from "primereact/inputtext"; import isMatch from 'date-fns/isMatch' import classNames from "classnames"; import {Toast} from "primereact/toast"; import {InputMask} from "primereact/inputmask"; import {Calendar} from "primereact/calendar"; import {Dialog} from "primereact/dialog"; import {format} from "date-fns"; import {Accordion, AccordionTab} from "primereact/accordion"; /** * the {@link NewActivity} properties */ type Props = { /** * trigger a create activity action. used to send a new activity to the server * @param activity the activity to be added */ createActivity: (activity: Activity | any) => void, /** * the progress info, injected from the NewActivity container */ progress: boolean, /** * the error info, injected from the NewActivity container */ communicationError: any /** * the activities list, injected from the NewActivity container */ activities: Activity[], } /** * The internal component state. */ type NewActivityState = { date: string, description: string, showNewDialogue: boolean, error: boolean, showCal: boolean } export class NewActivity extends React.Component<Props, NewActivityState> { toastBL: any; /** * Lifecycle, used for rendering the errors. */ componentDidUpdate(prevProps: Readonly<Props>, prevState: Readonly<NewActivityState>, snapshot?: any) { if (this.props?.communicationError && (prevProps.communicationError !== this.props?.communicationError)) { let statusText = this.props?.communicationError.statusText; if (statusText) { this.toastBL.current.show({severity:'error', summary: 'Error', detail: statusText, life: 3000}); } else { this.toastBL.current.show({severity:'error', summary: 'Error', detail:'Some error occurs', life: 3000}); } } } constructor(props: Props) { super(props); this.toastBL = React.createRef(); this.state = { date: '', description: '', showNewDialogue: props.activities?.length === 0, error: false, showCal: false } } /** * Add a new activity */ addNewActivity = () => { const act: Activity = { description: this.state.description, date: this.covertToLong(this.state.date), done: false } this.props.createActivity(act); this.setDate(''); this.setDescription(''); } /** * Convert a string into a long */ covertToLong = (date: string) => { return Date.parse(date); } /** * Toggles the show new activity dialogue flag */ toggle = () => { let prevState: boolean = this.state.showNewDialogue; this.setState({ showNewDialogue: !prevState }); } /** * set a description * @param desc the activity description to be set into the internal state */ setDescription = (desc: string) => { this.setState({ description: desc }); } /** * set a date * @param desc the activity date to be set into the internal state */ public setDate = (desc: string | Date) => { let d: string; Iif (desc instanceof Date) { d = format(desc, 'yyyy-MM-dd'); } else { d = desc as string; } let err = false; if (desc !== '' && !isMatch(d , 'yyyy-MM-dd')) { err = true; } this.setState({date: d, error: err}); } /** * show/hide the calendar dialogue */ setCalendarVisibility = (v: boolean) => { this.setState({ showCal: v }); } /** * Render the footer of the calendar dialogue */ renderFooter = () => { return ( <div> <Button disabled={!this.state.date} label="Done" icon="pi pi-check" className={'p-button-sm p-button-outlined'} onClick={() => this.setCalendarVisibility(false)} autoFocus /> </div> ); } /** * render the calendar dialogue * @param touch true if the widget to be rendered must be optimized for the mobile */ renderCalendar = (touch: boolean) => { return ( <Calendar id="icon" value={new Date(this.covertToLong(this.state.date))} touchUI={touch} inline={!touch} dateFormat="yy-mm-dd" onChange={(e) => this.setDate(e.value as Date)} className={classNames({ 'w-full': true, 'md:hidden': touch }) }/> ); } render() { return ( <div className="flex flex-row justify-content-end flex-wrap mt-6"> <Accordion id={'open-new-activity-dialogue'} activeIndex={0} className="w-full"> <AccordionTab header="Add Task"> <div id={'newActivityDialogue'}> <div className="mt-4"> <label htmlFor="description">Description</label> <InputText className="w-full" id="description" value={this.state.description} onChange={(e) => this.setDescription(e.target.value)}/> </div> <div className="mt-4"> <label htmlFor="date">Date</label> {this.renderCalendar(true)} <div className={'flex flex-row flex-nowrap md:hide'}> <InputMask id="date" mask="9999-99-99" slotChar="yyyy-mm-dd" value={this.state.date} className={classNames({ 'w-full': true, 'p-invalid': this.state.error, 'no-round-border-right': true })} onChange={(e) => this.setDate(e.value)}/> <Button id={'calendar-btn'} className={'no-round-border-left'} icon="pi pi-calendar" onClick={() => this.setCalendarVisibility(true)}/> <Dialog visible={this.state.showCal} maximizable modal style={{width: '50vw'}} footer={this.renderFooter()} onHide={() => this.setCalendarVisibility(false)}> {this.renderCalendar(false)} </Dialog> </div> </div> <Button label="Save" id={'save-activity'} loading={this.props.progress} disabled={!(!!this.state.description && !!this.state.date && !this.state.error)} className="w-full p-button-sm mt-4 p-button-outlined p-button-primary" onClick={this.addNewActivity}/></div> </AccordionTab> </Accordion> <Toast ref={this.toastBL} position="bottom-left" /> </div>); } } |