Skip to content
Snippets Groups Projects
Unverified Commit 01459229 authored by Tomasz Knapik's avatar Tomasz Knapik
Browse files

Add redirection at determination stages

parent 746614ab
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ from rest_framework import serializers ...@@ -3,6 +3,7 @@ from rest_framework import serializers
from django_bleach.templatetags.bleach_tags import bleach_value from django_bleach.templatetags.bleach_tags import bleach_value
from opentech.apply.activity.models import Activity from opentech.apply.activity.models import Activity
from opentech.apply.determinations.views import DeterminationCreateOrUpdateView
from opentech.apply.review.options import RECOMMENDATION_CHOICES from opentech.apply.review.options import RECOMMENDATION_CHOICES
from .models import ApplicationSubmission, RoundsAndLabs from .models import ApplicationSubmission, RoundsAndLabs
...@@ -12,10 +13,29 @@ markdown = mistune.Markdown() ...@@ -12,10 +13,29 @@ markdown = mistune.Markdown()
class ActionSerializer(serializers.Field): class ActionSerializer(serializers.Field):
def to_representation(self, instance): def to_representation(self, instance):
actions = instance.get_actions_for_user(self.context['request'].user) actions = instance.get_actions_for_user(self.context['request'].user)
return [ representation = []
{'value': transition, 'display': action} for transition, action in actions:
for transition, action in actions action_dict = {
] 'value': transition,
'display': action
}
# Sometimes the status does not exist in the
# determination matrix.
redirect = None
try:
redirect = DeterminationCreateOrUpdateView.should_redirect(
self.context['request'], instance, transition)
except KeyError:
pass
if redirect:
action_dict['type'] = 'redirect'
action_dict['target'] = redirect.url
else:
action_dict['type'] = 'submit'
representation.append(action_dict)
return representation
class ReviewSummarySerializer(serializers.Field): class ReviewSummarySerializer(serializers.Field):
......
...@@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; ...@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import { executeSubmissionAction } from '@actions/submissions'; import { executeSubmissionAction } from '@actions/submissions';
import Modal from '@components/Modal'; import Modal from '@components/Modal';
import { getSubmissionOfID } from '@selectors/submissions'; import { getSubmissionOfID } from '@selectors/submissions';
import { redirect } from '@utils';
class StatusActions extends React.Component { class StatusActions extends React.Component {
static propTypes = { static propTypes = {
...@@ -40,7 +41,21 @@ class StatusActions extends React.Component { ...@@ -40,7 +41,21 @@ class StatusActions extends React.Component {
} }
handleStatusChange = () => { handleStatusChange = () => {
this.props.changeStatus(this.state.statusSelectValue).then(this.closeStatusModal()); const { changeStatus, submission } = this.props
const { statusSelectValue } = this.state
const actionObject = submission.actions.find(
v => v.value === statusSelectValue
)
switch (actionObject.type) {
case 'redirect':
return redirect(actionObject.target)
case 'submit':
return changeStatus(statusSelectValue)
.then(() => this.closeStatusModal())
default:
throw "Invalid action type"
}
} }
renderModal = () => { renderModal = () => {
......
export function redirect(url) {
window.location.href = url;
}
...@@ -72,7 +72,6 @@ module.exports = (webpackEnv) => { ...@@ -72,7 +72,6 @@ module.exports = (webpackEnv) => {
} }
] ]
}, },
resolve: { resolve: {
modules: ['node_modules', './src'], modules: ['node_modules', './src'],
extensions: ['.js', '.jsx'], extensions: ['.js', '.jsx'],
...@@ -85,6 +84,7 @@ module.exports = (webpackEnv) => { ...@@ -85,6 +84,7 @@ module.exports = (webpackEnv) => {
'@actions': path.resolve(__dirname, 'src/redux/actions'), '@actions': path.resolve(__dirname, 'src/redux/actions'),
'@middleware': path.resolve(__dirname, 'src/redux/middleware'), '@middleware': path.resolve(__dirname, 'src/redux/middleware'),
'@api': path.resolve(__dirname, 'src/api'), '@api': path.resolve(__dirname, 'src/api'),
'@utils': path.resolve(__dirname, 'src/utils'),
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment