Skip to content

Commit

Permalink
Finish generic error dialog message and send sentry error notification
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinesalib committed Mar 4, 2020
1 parent 4a67724 commit 02aefab
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
13 changes: 8 additions & 5 deletions app/javascript/actions/dialogMessage.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
export const types = {
SET_ERROR_DIALOG_MESSAGE: 'DIALOG_MESSAGE/SET_ERROR_DIALOG_MESSAGE',
CLEAN_DIALOG_MESSAGE: 'DIALOG_MESSAGE/CLEAN_DIALOG_MESSAGE',
SET_ERROR_DIALOG_MESSAGE: 'DIALOG_MESSAGE/SET_ERROR_DIALOG_MESSAGE',
CLEAN_DIALOG_MESSAGE: 'DIALOG_MESSAGE/CLEAN_DIALOG_MESSAGE',
};

export const setErrorDialogMessage = (message) => ({
const DEFAULT_ERROR_MESSAGE = "Oops! Algo deu errado, por favor tente novamente.";

export const setErrorDialogMessage = (error, message = DEFAULT_ERROR_MESSAGE) => ({
type: types.SET_ERROR_DIALOG_MESSAGE,
message,
error,
});

export const cleanDialogMessage = () => ({
type: types.CLEAN_DIALOG_MESSAGE,
message: null,
type: types.CLEAN_DIALOG_MESSAGE,
message: null,
});
14 changes: 10 additions & 4 deletions app/javascript/components/DialogMessage/DialogMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@ import React from 'react'
import SimpleModal from "../SimpleModal/SimpleModal";
import {createStructuredSelector} from "reselect";
import {connect} from "react-redux";
import {cleanDialogMessage} from "../../actions/dialogMessage";
import * as Sentry from "@sentry/browser";

const DialogMessage = ({dialogMessage}) => {
const DialogMessage = ({dialogMessage, cleanDialogMessage}) => {
if (!dialogMessage.message) {
return null;
}

return <SimpleModal show={true}>
<p>Errou</p>
Sentry.captureException(dialogMessage.error);

return <SimpleModal show={true} modalClosed={cleanDialogMessage}>
<p>{dialogMessage.message}</p>
</SimpleModal>
};

const structuredSelector = createStructuredSelector({
dialogMessage: state => state.dialogMessage,
});

const mapDispatchToProps = {};
const mapDispatchToProps = {
cleanDialogMessage,
};

export default connect(structuredSelector, mapDispatchToProps)(DialogMessage);
5 changes: 1 addition & 4 deletions app/javascript/containers/AdoptionList/AdoptionList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,11 @@ class AdoptionList extends React.Component {
params: {register_interest: {user_email: userEmail, pet_id: pet.id}}
})
.then(() => {
console.log('then');
this.props.fetchPetsForAdoption(userEmail);
this.setState({showAdoptingModal: true});
})
.catch((error) => {
this.props.setErrorDialogMessage(error);
console.log('error');
console.log(error);
this.props.setErrorDialogMessage({error});
});
};

Expand Down
4 changes: 3 additions & 1 deletion app/javascript/reducers/dialogMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { types } from '../actions/dialogMessage';

const dialogMessageReducerDefaultState = {
type: null,
message: null
message: null,
error: null,
};

export default (state = dialogMessageReducerDefaultState, action) => {
Expand All @@ -11,6 +12,7 @@ export default (state = dialogMessageReducerDefaultState, action) => {
return {
...state,
message: action.message,
error: action.error,
type: "ERROR",
};
case types.CLEAN_DIALOG_MESSAGE:
Expand Down

0 comments on commit 02aefab

Please sign in to comment.