Skip to content

Commit

Permalink
#453 move back option for shortlisted
Browse files Browse the repository at this point in the history
  • Loading branch information
lloback committed Jun 8, 2020
1 parent 22dbdd4 commit d47b0a2
Show file tree
Hide file tree
Showing 6 changed files with 135 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ const SHORTLISTING = {
OTHER: 'other',
};

export { STATUS, EXERCISE_STAGE, APPLICATION_STATUS, SHORTLISTING };
const DEFAULT = {
YES: 'Yes',
NO: 'No',
};

export { STATUS, EXERCISE_STAGE, APPLICATION_STATUS, SHORTLISTING, DEFAULT };
12 changes: 11 additions & 1 deletion src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import ExerciseStagesRecommendedEdit from '@/views/Exercises/Stages/RecommendedE
import ExerciseStagesHandoverList from '@/views/Exercises/Stages/HandoverList';
import ExerciseStagesShortlistList from '@/views/Exercises/Stages/ShortlistList';
import ExerciseStagesShortlistEdit from '@/views/Exercises/Stages/ShortlistEdit';
import ExerciseStagesShortlistBack from '@/views/Exercises/Stages/ShortlistBack';

// Report views
import ExerciseShowReports from '@/views/Exercises/Show/Reports';
Expand Down Expand Up @@ -312,7 +313,7 @@ const router = new Router({
requiresAuth: true,
title: 'Exercise Stages | Shortlist',
},
},
},
{
path: 'shortlisted/edit',
component: ExerciseStagesShortlistEdit,
Expand All @@ -322,6 +323,15 @@ const router = new Router({
title: 'Exercise Stages | Shortlist edit',
},
},
{
path: 'shortlisted/back',
component: ExerciseStagesShortlistBack,
name: 'exercise-stages-shortlist-back',
meta: {
requiresAuth: true,
title: 'Exercise Stages | Shortlist back',
},
},
],
},
{
Expand Down
27 changes: 15 additions & 12 deletions src/store/stage/shortlisted.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,11 @@ export default {
unbind: firestoreAction(({ unbindFirestoreRef }) => {
return unbindFirestoreRef('records');
}),
updateStatus: async ( context, { status } ) => {
let stageValue = EXERCISE_STAGE.SHORTLISTED; // initial value: 'shortlisted'
const moveToNextStage = (status === APPLICATION_STATUS.INVITED_TO_SELECTION_DAY);

if (moveToNextStage) {
stageValue = EXERCISE_STAGE.SELECTED;
}

updateStatus: async ( context, { status, nextStage } ) => {
const moveToNextStage = nextStage !== EXERCISE_STAGE.SHORTLISTED;
const data = {
status: status,
stage: stageValue,
stage: nextStage,
};

const selectedItems = context.state.selectedItems;
Expand All @@ -52,10 +46,15 @@ export default {
batch.update(ref, data);
});
await batch.commit();

let valueMessage = `Updated ${selectedItems.length} candidates to '${lookup(status)}'`;

let valueMessage = '';
if (status !== '') {
valueMessage = `Updated ${selectedItems.length} candidates to '${lookup(status)}'`;
} else {
valueMessage = `Updated ${selectedItems.length} candidates`;
}
if (moveToNextStage) {
valueMessage = `${valueMessage} and moved to '${stageValue}'`;
valueMessage = `${valueMessage} and moved to '${nextStage}'`;
}
context.commit('message', valueMessage);
},
Expand All @@ -72,6 +71,7 @@ export default {
records: [],
message: null,
selectedItems: [],
action: null,
},
mutations: {
message(state, msg) {
Expand All @@ -80,5 +80,8 @@ export default {
changeSelectedItems(state, items) {
state.selectedItems = items;
},
changeAction(state, action) {
state.action = action;
},
},
};
72 changes: 72 additions & 0 deletions src/views/Exercises/Stages/ShortlistBack.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<form @submit.prevent="validateAndSave">
<ErrorSummary
:errors="errors"
/>
<RadioGroup
id="selected-status"
v-model="newSelectedStatus"
label="Move back to the review stage?"
hint=""
required
>
<RadioItem
v-for="item in availableStatuses"
:key="item"
:value="item"
:label="item | lookup"
/>
</RadioGroup>
<button class="govuk-button">
Save and continue
</button>
</form>
</template>

<script>
import Form from '@/components/Form/Form';
import ErrorSummary from '@/components/Form/ErrorSummary';
import RadioGroup from '@/components/Form/RadioGroup';
import RadioItem from '@/components/Form/RadioItem';
import { DEFAULT, EXERCISE_STAGE } from '@/helpers/constants';
export default {
components: {
ErrorSummary,
RadioGroup,
RadioItem,
},
extends: Form,
data() {
return {
newSelectedStatus: null,
};
},
computed: {
applicationId() {
return this.$route.params.applicationId;
},
availableStatuses() {
const myStatus = [
DEFAULT.YES,
DEFAULT.NO,
];
return myStatus;
},
},
methods: {
async save() {
let stageValue = EXERCISE_STAGE.SHORTLISTED;
if (this.newSelectedStatus === DEFAULT.YES) {
stageValue = EXERCISE_STAGE.REVIEW;
}
await this.$store.dispatch('stageShortlisted/updateStatus', {
applicationId: this.applicationId,
status: '',
nextStage: stageValue,
});
this.$router.push({ name: 'exercise-stages-shortlist-list' });
},
},
};
</script>
11 changes: 10 additions & 1 deletion src/views/Exercises/Stages/ShortlistEdit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Form from '@/components/Form/Form';
import ErrorSummary from '@/components/Form/ErrorSummary';
import RadioGroup from '@/components/Form/RadioGroup';
import RadioItem from '@/components/Form/RadioItem';
import { EXERCISE_STAGE, APPLICATION_STATUS } from '@/helpers/constants';
export default {
components: {
Expand All @@ -51,7 +52,15 @@ export default {
},
methods: {
async save() {
await this.$store.dispatch('stageShortlisted/updateStatus', { applicationId: this.applicationId, status: this.newSelectedStatus });
let stageValue = EXERCISE_STAGE.SHORTLISTED;
if (this.newSelectedStatus === APPLICATION_STATUS.INVITED_TO_SELECTION_DAY) {
stageValue = EXERCISE_STAGE.SELECTED;
}
await this.$store.dispatch('stageShortlisted/updateStatus', {
applicationId: this.applicationId,
status: this.newSelectedStatus,
nextStage: stageValue,
});
this.$router.push({ name: 'exercise-stages-shortlist-list' });
},
},
Expand Down
23 changes: 21 additions & 2 deletions src/views/Exercises/Stages/ShortlistList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
:message="message"
status="success"
/>
<form @submit.prevent="checkForm">
<form>
<div class="moj-page-header-actions">
<div class="moj-page-header-actions__title">
<h1 class="govuk-heading-l">
Expand All @@ -14,9 +14,17 @@
<div class="moj-page-header-actions__actions">
<div class="moj-button-menu">
<div class="moj-button-menu__wrapper">
<button
class="govuk-button govuk-button--secondary moj-button-menu__item moj-page-header-actions__action govuk-!-margin-right-2"
:disabled="isButtonDisabled"
@click.prevent="btnAction('back')"
>
Move back to ...
</button>
<button
class="govuk-button moj-button-menu__item moj-page-header-actions__action govuk-!-margin-right-2"
:disabled="isButtonDisabled"
@click.prevent="btnAction('status')"
>
Set status
</button>
Expand Down Expand Up @@ -86,7 +94,18 @@ export default {
methods: {
checkForm() {
this.$store.dispatch('stageShortlisted/storeItems', { items: this.selectedItems });
this.$router.push({ name: 'exercise-stages-shortlist-edit' });
// this.$router.push({ name: 'exercise-stages-shortlist-edit' });
},
btnAction(action) {
this.$store.dispatch('stageShortlisted/storeItems', { items: this.selectedItems });
switch (action) {
case 'back': // Go back
this.$router.push({ name: 'exercise-stages-shortlist-back' });
break;
case 'status': // change status
this.$router.push({ name: 'exercise-stages-shortlist-edit' });
break;
}
},
},
};
Expand Down

0 comments on commit d47b0a2

Please sign in to comment.