|
| 1 | +import Component from '@glimmer/component'; |
| 2 | +import { action } from '@ember/object'; |
| 3 | +import { USER_STATES } from '../constants/user-status'; |
| 4 | +import { getUTCMidnightTimestampFromDate } from '../utils/date-conversion'; |
| 5 | + |
| 6 | +export default class UserStatusComponent extends Component { |
| 7 | + ALL_FEASIBLE_STATUS = { |
| 8 | + [USER_STATES.ACTIVE]: { |
| 9 | + status: USER_STATES.ACTIVE, |
| 10 | + message: 'Change your status to Active', |
| 11 | + class: 'buttons__active', |
| 12 | + }, |
| 13 | + [USER_STATES.IDLE]: { |
| 14 | + status: USER_STATES.IDLE, |
| 15 | + message: 'Change your status to Idle', |
| 16 | + class: 'buttons__idle', |
| 17 | + }, |
| 18 | + [USER_STATES.OOO]: { |
| 19 | + status: USER_STATES.OOO, |
| 20 | + message: 'Change your status to OOO', |
| 21 | + class: 'buttons__ooo', |
| 22 | + }, |
| 23 | + }; |
| 24 | + currentUserStatus = [ |
| 25 | + { |
| 26 | + status: USER_STATES.ACTIVE, |
| 27 | + message: 'You are Active', |
| 28 | + otherAvailableStatus: [this.ALL_FEASIBLE_STATUS.OOO], |
| 29 | + }, |
| 30 | + { |
| 31 | + status: USER_STATES.IDLE, |
| 32 | + message: 'You are Idle', |
| 33 | + otherAvailableStatus: [this.ALL_FEASIBLE_STATUS.OOO], |
| 34 | + }, |
| 35 | + { |
| 36 | + status: USER_STATES.OOO, |
| 37 | + message: 'You are OOO', |
| 38 | + otherAvailableStatus: [], |
| 39 | + }, |
| 40 | + { |
| 41 | + status: USER_STATES.ONBOARDING, |
| 42 | + }, |
| 43 | + { |
| 44 | + status: USER_STATES.DNE, |
| 45 | + message: `Your Status doesn't exist`, |
| 46 | + otherAvailableStatus: [this.ALL_FEASIBLE_STATUS.OOO], |
| 47 | + }, |
| 48 | + ]; |
| 49 | + |
| 50 | + @action async changeStatus(status) { |
| 51 | + if (status === USER_STATES.ACTIVE) { |
| 52 | + const currentDate = new Date(); |
| 53 | + const currentDateString = currentDate.toISOString().slice(0, 10); |
| 54 | + const from = getUTCMidnightTimestampFromDate(currentDateString); |
| 55 | + const updatedAt = Date.now(); |
| 56 | + const activeStateData = { |
| 57 | + updatedAt, |
| 58 | + from, |
| 59 | + until: undefined, |
| 60 | + message: undefined, |
| 61 | + state: USER_STATES.ACTIVE, |
| 62 | + }; |
| 63 | + await this.args.updateStatus({ currentStatus: activeStateData }); |
| 64 | + } else { |
| 65 | + this.args.changeStatus(status); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @action async cancelOOOStatus(status) { |
| 70 | + if (status === USER_STATES.OOO) { |
| 71 | + await this.args.updateStatus({ cancelOoo: true }); |
| 72 | + } |
| 73 | + } |
| 74 | +} |
0 commit comments