Skip to content

Commit

Permalink
add "close after incident report" btn
Browse files Browse the repository at this point in the history
  • Loading branch information
r0xsh committed Apr 30, 2024
1 parent 6aceeb4 commit 7c113da
Showing 1 changed file with 62 additions and 15 deletions.
77 changes: 62 additions & 15 deletions src/navigation/task/Complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,24 @@ class CompleteTask extends Component {
isContactNameModalVisible: false,
contactName: '',
isKeyboardVisible: false,
validateTaskAfterReport: false,
};
}

shouldComponentUpdate(nextProps, nextState, nextContext) {
return this.state.failureReason !== nextState.failureReason;
shouldComponentUpdate(nextProps, nextState) {
if (this.state.failureReason !== nextState.failureReason) return true;

if (
this.state.validateTaskAfterReport !== nextState.validateTaskAfterReport
)
return true;

if (this.props.signatures.length !== nextProps.signatures.length)
return true;

if (this.props.pictures.length !== nextProps.pictures.length) return true;

return false;
}

markTaskDone() {
Expand Down Expand Up @@ -193,7 +206,6 @@ class CompleteTask extends Component {
);
}


reportIncident() {
const task = this.props.route.params?.task;
const { notes, failureReason } = this.state;
Expand All @@ -204,13 +216,15 @@ class CompleteTask extends Component {
notes,
failureReason,
() => {
// Make sure to use merge = true, so that it doesn't break
// when navigating to DispatchTaskList
this.props.navigation.navigate({
name: this.props.route.params?.navigateAfter,
merge: true,
});
}
if (this.state.validateTaskAfterReport) {
this.markTaskDone();
} else {
this.props.navigation.navigate({
name: this.props.route.params?.navigateAfter,
merge: true,
});
}
},
);
}

Expand Down Expand Up @@ -267,9 +281,12 @@ class CompleteTask extends Component {
}

multipleTasksLabel(tasks) {
return tasks.reduce((label, task, idx) => {
return `${label}${idx !== 0 ? ',' : ''} #${task.id}`;
}, `${this.props.t('COMPLETE_TASKS')}: `);
return tasks.reduce(
(label, task, idx) => {
return `${label}${idx !== 0 ? ',' : ''} #${task.id}`;
},
`${this.props.t('COMPLETE_TASKS')}: `,
);
}

isDropoff() {
Expand Down Expand Up @@ -377,6 +394,34 @@ class CompleteTask extends Component {
totalLines={2}
onChangeText={text => this.setState({ notes: text })}
/>
{!success && (
<FormControl p="3">
<Button
bg={
this.state.validateTaskAfterReport
? greenColor
: undefined
}
onPress={() =>
this.setState({
validateTaskAfterReport:
!this.state.validateTaskAfterReport,
})
}
variant={
this.state.validateTaskAfterReport
? 'solid'
: 'outline'
}
endIcon={
this.state.validateTaskAfterReport ? (
<Icon as={FontAwesome} name="check" size="sm" />
) : undefined
}>
Validate the task after reporting
</Button>
</FormControl>
)}
</FormControl>
<View>
<ScrollView style={{ height: '50%' }}>
Expand Down Expand Up @@ -539,8 +584,10 @@ function mapDispatchToProps(dispatch) {
dispatch(markTaskDone(client, task, notes, onSuccess, contactName)),
markTasksDone: (client, tasks, notes, onSuccess, contactName) =>
dispatch(markTasksDone(client, tasks, notes, onSuccess, contactName)),
reportIncident: (client, task, notes, failureReasonCode ,onSuccess) =>
dispatch(reportIncident(client, task, notes, failureReasonCode, onSuccess)),
reportIncident: (client, task, notes, failureReasonCode, onSuccess) =>
dispatch(
reportIncident(client, task, notes, failureReasonCode, onSuccess),
),
deleteSignatureAt: index => dispatch(deleteSignatureAt(index)),
deletePictureAt: index => dispatch(deletePictureAt(index)),
};
Expand Down

0 comments on commit 7c113da

Please sign in to comment.