Skip to content

Commit

Permalink
Send incident metadata to API.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsegura committed Oct 9, 2024
1 parent b3a23cd commit a311213
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
38 changes: 26 additions & 12 deletions src/navigation/task/Complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,20 @@ const FailureReasonPicker = ({ task, httpClient, onValueChange }) => {
);
};

const FailureReasonForm = ({ data }) => {
const FailureReasonForm = ({ data, onChange }) => {

const asQueryString = data.map(v => `${v.name}=${v.value}`).join('&')
const initialValues = qs.parse(asQueryString);

useEffect(() => {
onChange(initialValues)
}, [data])

Check failure on line 133 in src/navigation/task/Complete.js

View workflow job for this annotation

GitHub Actions / Basic tests

React Hook useEffect has missing dependencies: 'initialValues' and 'onChange'. Either include them or remove the dependency array. If 'onChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

return (
<Formik
initialValues={ initialValues }
validate={ values => console.log('VALIDATE', values) }
// onSubmit={ () => console.log('SUBMIT') }
// We use validate as a change handler
validate={ values => onChange(values) }
validateOnBlur={ true }
validateOnChange={ true }>
{({
Expand Down Expand Up @@ -172,7 +176,8 @@ class CompleteTask extends Component {
contactName: '',
isKeyboardVisible: false,
validateTaskAfterReport: false,
failureReasonFormData: [],
failureReasonMetadata: [],
failureReasonMetadataToSend: [],
};
}

Expand Down Expand Up @@ -253,12 +258,13 @@ class CompleteTask extends Component {

reportIncident() {
const task = this.props.route.params?.task;
const { notes, failureReason } = this.state;
const { notes, failureReason, failureReasonMetadataToSend } = this.state;

this.props.reportIncident(
task,
notes,
failureReason,
failureReasonMetadataToSend,
() => {
if (this.state.validateTaskAfterReport) {
this.markTaskDone();
Expand Down Expand Up @@ -430,16 +436,24 @@ class CompleteTask extends Component {
task={task}
httpClient={this.props.httpClient}
onValueChange={(code, obj) => {
if (obj && obj.form_data) {
this.setState({ failureReasonFormData: obj.form_data })
if (obj && obj.metadata) {
this.setState({
failureReasonMetadata: obj.metadata,
failureReasonMetadataToSend: []
})
} else {
this.setState({ failureReasonFormData: [] })
this.setState({
failureReasonMetadata: [],
failureReasonMetadataToSend: []
})
}
this.setState({ failureReason: code })
}}
/>
{ (Array.isArray(this.state.failureReasonFormData) && this.state.failureReasonFormData.length > 0) ?
<FailureReasonForm data={ this.state.failureReasonFormData } /> : null }
{ (Array.isArray(this.state.failureReasonMetadata) && this.state.failureReasonMetadata.length > 0) ?
<FailureReasonForm
data={ this.state.failureReasonMetadata }
onChange={ metadata => console.log('METADATA changed', metadata) } /> : null }
</FormControl>
)}
<FormControl p="3">
Expand Down Expand Up @@ -640,9 +654,9 @@ function mapDispatchToProps(dispatch) {
dispatch(markTaskDone(task, notes, onSuccess, contactName)),
markTasksDone: (tasks, notes, onSuccess, contactName) =>
dispatch(markTasksDone(tasks, notes, onSuccess, contactName)),
reportIncident: (task, notes, failureReasonCode, onSuccess) =>
reportIncident: (task, notes, failureReasonCode, failureReasonMetadata, onSuccess) =>
dispatch(
reportIncident(task, notes, failureReasonCode, onSuccess),
reportIncident(task, notes, failureReasonCode, failureReasonMetadata, onSuccess),
),
deleteSignatureAt: index => dispatch(deleteSignatureAt(index)),
deletePictureAt: index => dispatch(deletePictureAt(index)),
Expand Down
2 changes: 2 additions & 0 deletions src/redux/Courier/taskActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ export function reportIncident(
task,
description = null,
failureReasonCode = null,
failureReasonMetadata = [],
onSuccess,
) {
return function (dispatch, getState) {
Expand All @@ -277,6 +278,7 @@ export function reportIncident(
let payload = {
description,
failureReasonCode,
metadata: failureReasonMetadata,
task: task['@id']
};

Expand Down

0 comments on commit a311213

Please sign in to comment.