Comp To Mob
Comp To Mob
defaultState = {
activationDate: moment().format('MM/DD/YYYY'),
allSelected: false,
activating: false,
selectionMade: false,
onAirNotifications: true,
showModal: false,
message: null,
error: null,
showPartialCallSignMessage: false,
showCallsignActivation: false,
showPowerCorrectionButton:true,
isChecked:false
}
state = this.defaultState
componentDidMount() {
this.initialize()
this.props.fetchSiteActivationEmailList(this.props.project.get('proj_number'),
this.props.loginId)
}
componentDidUpdate(prevProps) {
if (!prevProps.rows.equals(this.props.rows)) {
this.initialize()
}
}
initialize = () => {
this.resetState()
this.props.setInitialValues({
rows: this.props.rows.map((row) => {
row = row.set('_id', UUID.create().toString())
row = row.set('checked', row.get('is_activated') === 'yes')
row = row.set('disabled', row.get('is_disabled') === 'yes')
return row
})
})
}
resetState = () => {
this.setState({...this.defaultState})
}
resetMessages = () => {
this.setState({message: null, error: null})
}
return row
})
if(value) {
this.setState({
isChecked: true,
selectionMade: true
})
} else {
const anyChecked = updated.some((updatedRow) => updatedRow.get('checked'))
this.setState({
isChecked: anyChecked,
selectionMade: anyChecked
})
}
this.props.setValue('rows', updated)
}
this.setState({activationDate})
this.props.setValue('rows', updated)
}
return row
})
}
toggleAllSelected = () => {
const {task, setValue} = this.props
this.setState({allSelected: !this.state.allSelected}, () => {
let allSelected = false
const rows = this.props.currentValues.get('rows') || List()
const checkedRows = rows.map((row) => {
if (task.get('status') === 'COMPLETED' && row.get('activated') !==
'Activated') {
return row
} else if (row.get('is_activated') === 'no') {
allSelected = this.state.allSelected
row = row.set('checked', allSelected)
}
return row
})
const updated =
this.state.activationDate !== '' && task.get('status') !== 'COMPLETED'
? this.assignActivationDate(checkedRows, this.state.activationDate)
: checkedRows
this.setState({selectionMade: allSelected})
setValue('rows', updated)
})
}
formatPayload = () => {
const taskId = this.props.task.get('task_inst_id')
const taskType = this.props.task.get('name')
let emails = this.props.currentValues.getIn(['emails'], List())
emails = emails.map((email) => email.get('value')).toJS()
const project = {
project_id: this.props.project.get('proj_number'),
wf_inst_id: this.props.project.get('si_workflow_instance_id'),
emails,
comments: this.props.currentValues.get('comments') || ''
}
onActivate = () => {
const callSignsPresent = this.props.details.get('call_signs', List()).size > 0
const {taskId, taskType, project, rows} = this.formatPayload()
const {projectWorkflow} = this.props
this.setState({activating: true})
this.props
.saveTaskDetails(
taskId,
taskType,
rows.toJS(),
{
...project,
wf_inst_id: projectWorkflow.wf_inst_id,
project_activation: callSignsPresent ? 'no' : 'yes'
},
this.props.currentValues.get('generate_pms') || ''
)
.then((res) => {
this.props.fetchTaskDetails(taskId, taskType)
this.resetState()
})
.catch(() => this.setState({activating: false, showPartialCallSignMessage:
false}))
}
onSendActivation = () => {
this.setState({activating: true})
const callSignsPresent = this.props.details.get('call_signs', List()).size > 0
const {taskId, taskType, project, rows} = this.formatPayload()
const payload = {
...project,
task_inst_id: taskId,
fuze_site_id: this.props.project.get('fuze_site_id'),
user_id: this.props.loginId,
Site_Activation: rows.toJS(),
project_activation: callSignsPresent ? 'no' : 'yes'
}
sendActivationEmail(payload)
.then((res) => {
this.props.fetchTaskDetails(taskId, taskType)
this.props.fetchSiteActivationEmailList(this.props.loginId)
this.resetState()
toastSuccessMsg(res.data.message)
})
.catch((err) => {
this.setState({activating: false})
toastEachError(err)
})
}
getColumns() {
const {columns} = this.props
handleActivate = () => {
this.setState({showCallsignActivation: true})
}
getActivationRows = () => {
return (this.props.currentValues.get('rows') || List())
.filter((row) => row.get('checked'))
.map((row) => {
row = row.delete('_id')
row = row.delete('checked')
return row
})
}
getCbandEmail=()=>{
let emails = this.props.currentValues.getIn(['emails'], List())
emails = emails.map((email) => email.get('value')).toJS()
return emails
}
render() {
const {activationDate, activating, allSelected, onAirNotifications} =
this.state
const {loading, emailList} = this.props
const columns = this.getColumns()
const isEditable = 'yes' // this.props.task.get('is_editable')
const status = this.props.task.get('status')
const pmModal = this.props.details.get('display_pm_modal')
const taskId = this.props.task.get('task_inst_id')
const taskType = this.props.task.get('name')
const callSignsPresent = this.props.details.get('call_signs', List()).size > 0
const data = this.props.currentValues.get('rows') || List()
const activatedRows = this.props.currentValues
.get('rows', List())
.toJS()
.filter((r) => r.activated === 'Activated')
const rtiDate = this.props.details.get('rti_completion_date', null)