Skip to content

<fix> issue 102: submit without registration #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/actions/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,20 @@ function getChallengeDone(challengeId) {
return challengeService.getChallenge(challengeId);
}

/**
* @static
* @desc Check if a user has registered a challenge
* @param {String} challengeId Challenge ID.
* @param {String} userId User Id.
* @return {Action}
*/
async function getIsRegistered(challengeId, userId) {
const registrants = await challengeService.getChallengeRegistrants(challengeId);
const isRegistered = _.some(registrants, (r) => `${r.memberId}` === `${userId}`);
return { isRegistered };
}


export default createActions({
CHALLENGE: {
DROP_CHECKPOINTS: dropCheckpoints,
Expand Down Expand Up @@ -483,5 +497,6 @@ export default createActions({
GET_SUBMISSION_INFORMATION_DONE: getSubmissionInformationDone,
GET_CHALLENGE_INIT: _.noop,
GET_CHALLENGE_DONE: getChallengeDone,
GET_IS_REGISTERED: getIsRegistered,
},
});
14 changes: 12 additions & 2 deletions src/containers/Submission/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const Submission = ({
getCommunityList,
isLoadingChallenge,
isChallengeLoaded,

track,
agreed,
filePickers,
Expand All @@ -38,6 +37,7 @@ const Submission = ({
submitDone,
uploadProgress,

getIsRegistered,
getChallenge,
submit,
resetForm,
Expand Down Expand Up @@ -92,6 +92,11 @@ const Submission = ({
);
}

const handleSubmit = async (data) => {
const registered = await getIsRegistered(challengeId, userId);
if (registered) submit(data);
};

return (
<Submit
challengeId={challengeId}
Expand Down Expand Up @@ -119,7 +124,7 @@ const Submission = ({
setFilePickerUploadProgress={setFilePickerUploadProgress}
setFilePickerDragged={setFilePickerDragged}
setSubmissionFilestackData={setSubmissionFilestackData}
submit={submit}
submit={handleSubmit}
/>
);
};
Expand Down Expand Up @@ -155,6 +160,7 @@ Submission.propTypes = {
uploadProgress: PT.number,

getChallenge: PT.func,
getIsRegistered: PT.func,
submit: PT.func,
resetForm: PT.func,
setAgreed: PT.func,
Expand Down Expand Up @@ -209,6 +215,10 @@ const mapDispatchToProps = (dispatch) => {
setAuth: () => {
dispatch(actions.auth.setAuthDone());
},
getIsRegistered: async (challengeId, userId) => {
const action = await dispatch(actions.challenge.getIsRegistered(challengeId, userId));
return action?.payload?.isRegistered;
},
getChallenge: (challengeId) => {
dispatch(actions.challenge.getChallengeInit(challengeId));
dispatch(actions.challenge.getChallengeDone(challengeId));
Expand Down
25 changes: 25 additions & 0 deletions src/reducers/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,30 @@ function onGetChallengeDone(state, { error, payload }) {
};
}

/**
* Update isRegistered to before challenge submit
* @param {Object} state Old state.
* @param {Object} actions Action error/payload.
* @param {Object} action Action.
*/
function onGetIsRegistered(state, { error, payload }) {
if (error) {
logger.error("Failed to get the user's registration status!", payload);
fireErrorMessage(
"ERROR: Failed to submit",
"Please, try again a bit later"
);
return state;
}
return {
...state,
challenge: {
...state.challenge,
isRegistered: payload.isRegistered
}
};
}

/**
* Creates a new Challenge reducer with the specified initial state.
* @param {Object} initialState Optional. Initial state.
Expand Down Expand Up @@ -520,6 +544,7 @@ function create(initialState) {
[a.getSubmissionInformationDone]: onGetSubmissionInformationDone,
[a.getChallengeInit]: onGetChallengeInit,
[a.getChallengeDone]: onGetChallengeDone,
[a.getIsRegistered]: onGetIsRegistered,
},
_.defaults(initialState, {
details: null,
Expand Down
1 change: 1 addition & 0 deletions src/services/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ async function getChallenge(challengeId) {

export default {
getChallenge,
getChallengeRegistrants
};