Redirect to proposal if you try to edit and its not in draft state. (#242)

This commit is contained in:
William O'Beirne 2019-02-21 17:07:55 -05:00 committed by GitHub
parent acb16771bc
commit b93348820c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import {
getProposalDrafts,
putProposal,
deleteProposalDraft,
getProposal,
} from 'api/api';
import { getDrafts, getDraftById, getFormState } from './selectors';
import {
@ -120,12 +121,21 @@ export function* handleInitializeForm(
action: ReturnType<typeof initializeForm>,
): SagaIterator {
try {
let draft: Yielded<typeof getDraftById> = yield select(getDraftById, action.payload);
const proposalId = action.payload;
let draft: Yielded<typeof getDraftById> = yield select(getDraftById, proposalId);
if (!draft) {
yield call(handleFetchDrafts);
draft = yield select(getDraftById, action.payload);
draft = yield select(getDraftById, proposalId);
if (!draft) {
throw new Error('Proposal not found');
// If it's a real proposal, just not in draft form, redirect to it
try {
yield call(getProposal, proposalId);
yield put({ type: types.INITIALIZE_FORM_REJECTED });
yield put(replace(`/proposals/${action.payload}`));
return;
} catch (err) {
throw new Error('Proposal not found');
}
}
}
yield put({