From 68854db61e3d36b4746f60b75a2ec59f5b572d71 Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Mon, 25 Mar 2019 09:04:17 +0300 Subject: [PATCH] added selectors and template saga for updating legacy certificates --- .../src/components/settings/Certification.js | 15 ++++++-- client/src/redux/settings/index.js | 18 +++++++++- .../update-legacy-certificate-saga.js | 36 +++++++++++++++++++ 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 client/src/redux/settings/update-legacy-certificate-saga.js diff --git a/client/src/components/settings/Certification.js b/client/src/components/settings/Certification.js index 4c27c41feb..a3f0e34c0e 100644 --- a/client/src/components/settings/Certification.js +++ b/client/src/components/settings/Certification.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; import { find, first } from 'lodash'; import { Table, @@ -11,6 +13,7 @@ import { import { Link, navigate } from 'gatsby'; import { createSelector } from 'reselect'; +import { updateLegacyCertificate } from '../../redux/settings'; import { projectMap, legacyProjectMap } from '../../resources/certProjectMap'; import SectionHeader from './SectionHeader'; @@ -22,6 +25,9 @@ import { maybeUrlRE } from '../../utils'; import './certification.css'; +const mapDispatchToProps = dispatch => + bindActionCreators({ updateLegacyCertificate }, dispatch); + const propTypes = { completedChallenges: PropTypes.arrayOf( PropTypes.shape({ @@ -45,6 +51,7 @@ const propTypes = { isInfosecQaCert: PropTypes.bool, isJsAlgoDataStructCert: PropTypes.bool, isRespWebDesignCert: PropTypes.bool, + updateLegacyCertificate: PropTypes.func.isRequired, username: PropTypes.string, verifyCert: PropTypes.func.isRequired }; @@ -279,7 +286,8 @@ class CertificationSettings extends Component { // legacy projects rendering handleSubmit(values) { - console.log(values); + const { updateLegacyCertificate } = this.props; + updateLegacyCertificate(values); } renderLegacyCertifications = certName => { @@ -405,4 +413,7 @@ class CertificationSettings extends Component { CertificationSettings.displayName = 'CertificationSettings'; CertificationSettings.propTypes = propTypes; -export default CertificationSettings; +export default connect( + null, + mapDispatchToProps +)(CertificationSettings); diff --git a/client/src/redux/settings/index.js b/client/src/redux/settings/index.js index 8982d71f8e..5204b9c9f2 100644 --- a/client/src/redux/settings/index.js +++ b/client/src/redux/settings/index.js @@ -5,6 +5,10 @@ import { createDangerZoneSaga } from './danger-zone-saga'; import { createSettingsSagas } from './settings-sagas'; import { createUpdateMyEmailSaga } from './update-email-saga'; +// prettier-ignore +import { createUpdateLegacyCertificateSaga } from +'./update-legacy-certificate-saga'; + export const ns = 'settings'; const defaultFetchState = { @@ -27,6 +31,7 @@ export const types = createTypes( ...createAsyncTypes('submitNewAbout'), ...createAsyncTypes('submitNewUsername'), ...createAsyncTypes('updateMyEmail'), + ...createAsyncTypes('updateLegacyCertificate'), ...createAsyncTypes('updateUserFlag'), ...createAsyncTypes('submitProfileUI'), ...createAsyncTypes('verifyCert'), @@ -39,7 +44,8 @@ export const types = createTypes( export const sagas = [ ...createSettingsSagas(types), ...createUpdateMyEmailSaga(types), - ...createDangerZoneSaga(types) + ...createDangerZoneSaga(types), + ...createUpdateLegacyCertificateSaga(types) ]; const checkForSuccessPayload = ({ type, payload }) => @@ -72,6 +78,16 @@ export const updateMyEmail = createAction(types.updateMyEmail); export const updateMyEmailComplete = createAction(types.updateMyEmailComplete); export const updateMyEmailError = createAction(types.updateMyEmailError); +export const updateLegacyCertificate = createAction( + types.updateLegacyCertificate +); +export const updateLegacyCertificateComplete = createAction( + types.updateLegacyCertificateComplete +); +export const updateLegacyCertificateError = createAction( + types.updateLegacyCertificateError +); + export const updateUserFlag = createAction(types.updateUserFlag); export const updateUserFlagComplete = createAction( types.updateUserFlagComplete, diff --git a/client/src/redux/settings/update-legacy-certificate-saga.js b/client/src/redux/settings/update-legacy-certificate-saga.js new file mode 100644 index 0000000000..660a8f18f5 --- /dev/null +++ b/client/src/redux/settings/update-legacy-certificate-saga.js @@ -0,0 +1,36 @@ +import { takeEvery } from 'redux-saga/effects'; + +// import { +// updateLegacyCertificateComplete, +// updateLegacyCertificateError +// } from './'; +// import { createFlashMessage } from '../../components/Flash/redux'; + +// import { putUserUpdateEmail } from '../../utils/ajax'; +// import reallyWeirdErrorMessage from '../../utils/reallyWeirdErrorMessage'; + +function* updateLegacyCertificateSaga(values) { + console.log(values); + /* if (!email || !isEmail(email)) { + yield put(createFlashMessage(reallyWeirdErrorMessage)); + return; + } + try { + const { data: response } = yield call(putUserUpdateEmail, email); + yield put( + updateMyEmailComplete({ + ...response, + payload: { email, isEmailVerified: false } + }) + ); + yield put(createFlashMessage(response)); + } catch (e) { + yield put(updateMyEmailError(e)); + }*/ +} + +export function createUpdateLegacyCertificateSaga(types) { + return [ + takeEvery(types.updateLegacyCertificate, updateLegacyCertificateSaga) + ]; +}