Conditions | 6 |
Total Lines | 168 |
Code Lines | 141 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React from "react"; |
||
221 | |||
222 | public render(): React.ReactElement { |
||
223 | const { application, reviewStatusOptions, isSaving, intl } = this.props; |
||
224 | const l10nReviewStatusOptions = reviewStatusOptions.map(status => ({ |
||
225 | value: status.value, |
||
226 | label: intl.formatMessage(messages[status.label]), |
||
227 | })); |
||
228 | const { selectedStatusId } = this.state; |
||
229 | const reviewStatus = |
||
230 | application.application_review && |
||
231 | application.application_review.review_status |
||
232 | ? application.application_review.review_status.name |
||
233 | : null; |
||
234 | const statusIconClass = className("fas", { |
||
235 | "fa-ban": reviewStatus === "screened_out", |
||
236 | "fa-question-circle": reviewStatus === "still_thinking", |
||
237 | "fa-check-circle": reviewStatus === "still_in", |
||
238 | "fa-exclamation-circle": reviewStatus === null, |
||
239 | }); |
||
240 | |||
241 | /** |
||
242 | * Returns true only if selectedStatusId matches the review |
||
243 | * status of props.application |
||
244 | */ |
||
245 | const isUnchanged = (): boolean => { |
||
246 | if ( |
||
247 | application.application_review && |
||
248 | application.application_review.review_status_id |
||
249 | ) { |
||
250 | return ( |
||
251 | application.application_review.review_status_id === selectedStatusId |
||
252 | ); |
||
253 | } |
||
254 | return selectedStatusId === undefined; |
||
255 | }; |
||
256 | |||
257 | const getSaveButtonText = (): string => { |
||
258 | if (isSaving) { |
||
259 | return intl.formatMessage(messages.saving); |
||
260 | } |
||
261 | if (isUnchanged()) { |
||
262 | return intl.formatMessage(messages.saved); |
||
263 | } |
||
264 | return intl.formatMessage(messages.save); |
||
265 | }; |
||
266 | const saveButtonText = getSaveButtonText(); |
||
267 | const noteButtonText = |
||
268 | application.application_review && application.application_review.notes |
||
269 | ? intl.formatMessage(messages.editNote) |
||
270 | : intl.formatMessage(messages.addNote); |
||
271 | |||
272 | return ( |
||
273 | <form className="applicant-summary"> |
||
274 | <div className="flex-grid middle gutter"> |
||
275 | <div className="box lg-1of11 applicant-status"> |
||
276 | <i className={statusIconClass} /> |
||
277 | </div> |
||
278 | |||
279 | <div className="box lg-2of11 applicant-information"> |
||
280 | <span |
||
281 | className="name" |
||
282 | data-name={`${application.applicant.user.first_name} ${application.applicant.user.last_name}`} |
||
283 | > |
||
284 | {application.applicant.user.first_name}{" "} |
||
285 | {application.applicant.user.last_name} |
||
286 | </span> |
||
287 | <a |
||
288 | href={`mailto: ${application.applicant.user.email}`} |
||
289 | title={intl.formatMessage(messages.emailCandidate)} |
||
290 | data-email={`${application.applicant.user.email}`} |
||
291 | className="email" |
||
292 | > |
||
293 | {application.applicant.user.email} |
||
294 | </a> |
||
295 | {/* This span only shown for priority applicants */} |
||
296 | {application.applicant.user.is_priority && ( |
||
297 | <span className="priority-status"> |
||
298 | <i |
||
299 | aria-hidden="true" |
||
300 | className="fab fa-product-hunt" |
||
301 | title={intl.formatMessage(messages.priorityLogo)} |
||
302 | /> |
||
303 | <FormattedMessage |
||
304 | id="priorityStatus.priority" |
||
305 | defaultMessage="Priority" |
||
306 | description="Priority" |
||
307 | /> |
||
308 | </span> |
||
309 | )} |
||
310 | {/* This span only shown for veterans */} |
||
311 | {(application.veteran_status.name === "current" || |
||
312 | application.veteran_status.name === "past") && ( |
||
313 | <span className="veteran-status"> |
||
314 | <img |
||
315 | alt={intl.formatMessage(messages.veteranLogo)} |
||
316 | src="/images/icon_veteran.svg" |
||
317 | />{" "} |
||
318 | <FormattedMessage |
||
319 | id="veteranStatus.veteran" |
||
320 | defaultMessage="Veteran" |
||
321 | description="Veteran" |
||
322 | /> |
||
323 | </span> |
||
324 | )} |
||
325 | </div> |
||
326 | |||
327 | <div className="box lg-2of11 applicant-links"> |
||
328 | <a |
||
329 | title={intl.formatMessage(messages.viewApplicationTitle)} |
||
330 | href={routes.managerApplicationShow(intl.locale, application.id)} |
||
331 | > |
||
332 | <i className="fas fa-file-alt" /> |
||
333 | <FormattedMessage |
||
334 | id="apl.viewApplication" |
||
335 | defaultMessage="View Application" |
||
336 | description="Button text View Application" |
||
337 | /> |
||
338 | </a> |
||
339 | <a |
||
340 | title={intl.formatMessage(messages.viewProfileTitle)} |
||
341 | href={routes.managerApplicantShow( |
||
342 | intl.locale, |
||
343 | application.applicant_id, |
||
344 | )} |
||
345 | > |
||
346 | <i className="fas fa-user" /> |
||
347 | <FormattedMessage |
||
348 | id="apl.viewProfile" |
||
349 | defaultMessage="View Profile" |
||
350 | description="Button text View Profile" |
||
351 | /> |
||
352 | </a> |
||
353 | </div> |
||
354 | |||
355 | <div className="box lg-2of11 applicant-decision" data-clone> |
||
356 | <Select |
||
357 | id={`review_status_${application.id}`} |
||
358 | name="review_status" |
||
359 | label={intl.formatMessage(messages.decision)} |
||
360 | required={false} |
||
361 | selected={selectedStatusId || null} |
||
362 | nullSelection={intl.formatMessage(messages.notReviewed)} |
||
363 | options={l10nReviewStatusOptions} |
||
364 | onChange={this.handleStatusChange} |
||
365 | /> |
||
366 | </div> |
||
367 | |||
368 | <div className="box lg-2of11 applicant-notes"> |
||
369 | <button |
||
370 | className="button--outline" |
||
371 | type="button" |
||
372 | onClick={this.showNotes} |
||
373 | > |
||
374 | {noteButtonText} |
||
375 | </button> |
||
376 | </div> |
||
377 | |||
378 | <div className="box lg-2of11 applicant-save-button"> |
||
379 | <button |
||
380 | className="button--blue light-bg" |
||
381 | type="button" |
||
382 | onClick={() => this.handleSaveClicked()} |
||
383 | > |
||
384 | <span>{saveButtonText}</span> |
||
385 | </button> |
||
386 | </div> |
||
387 | </div> |
||
388 | </form> |
||
389 | ); |
||
394 |