Skip to content

Commit

Permalink
fix(ZNTA-2318): dispatch save rejected status only after successful c…
Browse files Browse the repository at this point in the history
…omment
  • Loading branch information
efloden committed Feb 8, 2018
1 parent 2cc7568 commit 343255b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
Expand Up @@ -4,6 +4,8 @@ import {
getJsonHeaders,
buildAPIRequest
} from '../../actions/common-actions'
import { savePhraseWithStatus } from './phrases-actions'
import { STATUS_REJECTED } from '../utils/status-util'

export const ADD_REVIEW_REQUEST = 'ADD_REVIEW_REQUEST'
export const ADD_REVIEW_SUCCESS = 'ADD_REVIEW_SUCCESS'
Expand All @@ -15,11 +17,19 @@ export const GET_ALL_CRITERIA_FAILURE = 'GET_ALL_CRITERIA_FAILURE'
/**
* Perform a save of a translation review with the given review data
*/
export function rejectTranslation (review) {
export function rejectTranslation (dispatch, review) {
const endpoint = `${apiUrl}/review/trans/${review.localeId}`
const apiTypes = [
ADD_REVIEW_REQUEST,
ADD_REVIEW_SUCCESS,
{
type: ADD_REVIEW_SUCCESS,
payload: (action, state, res) => {
return res.json().then((json) => {
dispatch(savePhraseWithStatus(review.phrase, STATUS_REJECTED))
return json
})
}
},
ADD_REVIEW_FAILURE]
const body = {
transUnitId: review.transUnitId,
Expand Down
Expand Up @@ -93,8 +93,9 @@ class TransUnitTranslationFooter extends React.Component {
const saveCallback = (event) => {
if (status === STATUS_REJECTED) {
this.props.showRejectModal()
} else {
savePhraseWithStatus(phrase, status, event)
}
savePhraseWithStatus(phrase, status, event)
}

const shortcutKey = saveAsMode && statusShortcutKeys[status]
Expand Down
Expand Up @@ -102,7 +102,8 @@ class MainContent extends React.Component {
transUnitID={this.props.selectedPhraseId}
revision={selectedPhraseRevision}
localeId={this.props.translationLocale.id}
criteria={this.props.criteria} />
criteria={this.props.criteria}
selectedPhrase={selectedPhrase} />
</main>
)
}
Expand Down
Expand Up @@ -30,7 +30,8 @@ export class RejectTranslationModal extends Component {
description: PropTypes.string.isRequired,
priority: PropTypes.oneOf([MINOR, MAJOR, CRITICAL]).isRequired
})).isRequired,
addNewTransReview: PropTypes.func.isRequired
addNewTransReview: PropTypes.func.isRequired,
selectedPhrase: PropTypes.object
}
defaultState = {
review: {
Expand Down Expand Up @@ -89,7 +90,8 @@ export class RejectTranslationModal extends Component {
transUnitId: this.props.transUnitID,
revision: this.props.revision,
criteriaId: this.state.review.criteriaId,
reviewComment: this.state.review.reviewComment
reviewComment: this.state.review.reviewComment,
phrase: this.props.selectedPhrase
}
this.props.addNewTransReview(review)
this.props.onHide()
Expand Down Expand Up @@ -162,7 +164,7 @@ export class RejectTranslationModal extends Component {

const mapDispatchToProps = dispatch => {
return {
addNewTransReview: (review) => dispatch(rejectTranslation(review)
addNewTransReview: (review) => dispatch(rejectTranslation(dispatch, review)
)
}
}
Expand Down

0 comments on commit 343255b

Please sign in to comment.