Skip to content

Commit

Permalink
Revert "Revert "Revert "ENT-3671 Keep email field populated while swi…
Browse files Browse the repository at this point in the history
…tching in between new and old templates"" (#423)" (#424)

This reverts commit 52c9657.
  • Loading branch information
zamanafzal authored Dec 24, 2020
1 parent 52c9657 commit aa9b429
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 146 deletions.
9 changes: 1 addition & 8 deletions src/components/CodeAssignmentModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ class BaseCodeAssignmentModal extends React.Component {
}
}

componentWillUnmount() {
this.props.setEmailAddress('', this.state.mode);
}

getNumberOfSelectedCodes() {
const {
data: {
Expand Down Expand Up @@ -423,7 +419,7 @@ class BaseCodeAssignmentModal extends React.Component {
{!isBulkAssign && <IndividualAssignFields />}
<div className="mt-4">
<h3>Email Template</h3>
<TemplateSourceFields emailTemplateType="assign" currentEmail={this.props.currentEmail} />
<TemplateSourceFields emailTemplateType="assign" />
<Field
id="email-template-subject"
name="email-template-subject"
Expand Down Expand Up @@ -541,13 +537,11 @@ BaseCodeAssignmentModal.defaultProps = {
error: null,
isBulkAssign: false,
data: {},
currentEmail: '',
};

BaseCodeAssignmentModal.propTypes = {
// props from redux
enterpriseSlug: PropTypes.string.isRequired,
currentEmail: PropTypes.string,
enableLearnerPortal: PropTypes.bool.isRequired,
// props From redux-form
handleSubmit: PropTypes.func.isRequired,
Expand All @@ -562,7 +556,6 @@ BaseCodeAssignmentModal.propTypes = {
onClose: PropTypes.func.isRequired,
onSuccess: PropTypes.func.isRequired,
sendCodeAssignment: PropTypes.func.isRequired,
setEmailAddress: PropTypes.func.isRequired,
couponDetailsTable: PropTypes.shape({
data: PropTypes.shape({
count: PropTypes.number,
Expand Down
16 changes: 3 additions & 13 deletions src/components/TemplateSourceFields/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ class TemplateSourceFields extends React.Component {

updateState(emailTemplateSource) {
const {
setEmailTemplateSource, allEmailTemplates, setEmailAddress, emailTemplateType, currentEmail,
setEmailTemplateSource, allEmailTemplates,
} = this.props;
if (emailTemplateType === 'assign') {
setEmailAddress(currentEmail, emailTemplateType);
}
setEmailTemplateSource(emailTemplateSource);
if (emailTemplateSource === EMAIL_TEMPLATE_SOURCE_FROM_TEMPLATE) {
this.makeOptions(this.props);
Expand All @@ -97,13 +94,9 @@ class TemplateSourceFields extends React.Component {
}

dispatchUpdatedTemplate(emailTemplate) {
const { currentFromTemplate, emailTemplateType, currentEmail } = this.props;
const { currentFromTemplate, emailTemplateType } = this.props;
if (emailTemplate.length > 0) {
const firstEmailTemplate = emailTemplate[0];
if (emailTemplateType === 'assign') {
firstEmailTemplate.email_address = currentEmail;
}
currentFromTemplate(emailTemplateType, firstEmailTemplate);
currentFromTemplate(emailTemplateType, emailTemplate[0]);
}
}

Expand Down Expand Up @@ -203,15 +196,12 @@ class TemplateSourceFields extends React.Component {
TemplateSourceFields.defaultProps = {
allEmailTemplates: [],
disabled: false,
currentEmail: '',
};

TemplateSourceFields.propTypes = {
emailTemplateSource: PropTypes.string.isRequired,
emailTemplateType: PropTypes.string.isRequired,
currentEmail: PropTypes.string,
setEmailTemplateSource: PropTypes.func.isRequired,
setEmailAddress: PropTypes.func.isRequired,
currentFromTemplate: PropTypes.func.isRequired,
fetchEmailTemplates: PropTypes.func.isRequired,
allEmailTemplates: PropTypes.arrayOf(PropTypes.shape({})),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ const initialState = {
},
},
},
form: {
'code-assignment-modal-form': {
values: {
'email-address': '[email protected]',
},
},
},
portalConfiguration: {
enterpriseSlug: 'bearsRus',
enableLearnerPortal: true,
Expand All @@ -44,15 +37,13 @@ const initialState = {
emailTemplateSource: EMAIL_TEMPLATE_SOURCE_NEW_EMAIL,
default: {
assign: {
'email-address': '',
'email-template-subject': assignEmailTemplate.subject,
'email-template-greeting': assignEmailTemplate.greeting,
'email-template-body': assignEmailTemplate.body,
'email-template-closing': assignEmailTemplate.closing,
},
},
assign: {
'email-address': '',
'email-template-subject': assignEmailTemplate.subject,
'email-template-greeting': assignEmailTemplate.greeting,
'email-template-body': assignEmailTemplate.body,
Expand Down
3 changes: 0 additions & 3 deletions src/containers/CodeAssignmentModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import CodeAssignmentModal from '../../components/CodeAssignmentModal';

import sendCodeAssignment from '../../data/actions/codeAssignment';
import { EMAIL_TEMPLATE_SOURCE_NEW_EMAIL } from '../../data/constants/emailTemplate';
import { setEmailAddress } from '../../data/actions/emailTemplate';

const mapStateToProps = (state) => {
let initialValues = state.emailTemplate.emailTemplateSource === EMAIL_TEMPLATE_SOURCE_NEW_EMAIL
Expand All @@ -14,7 +13,6 @@ const mapStateToProps = (state) => {
initialValues = { ...initialValues, 'enable-nudge-emails': true };

return {
currentEmail: state.form['code-assignment-modal-form']?.values['email-address'],
couponDetailsTable: state.table['coupon-details'],
initialValues,
enableReinitialize: true,
Expand All @@ -30,7 +28,6 @@ const mapDispatchToProps = dispatch => ({
onError: (error) => { reject(error); },
}));
}),
setEmailAddress: (emailAddress, emailType) => dispatch(setEmailAddress(emailAddress, emailType)),
});

export default connect(mapStateToProps, mapDispatchToProps)(CodeAssignmentModal);
7 changes: 0 additions & 7 deletions src/containers/CodeManagementPage/CodeManagementPage.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ const initialState = {
table: {
'coupon-details': {},
},
form: {
'code-assignment-modal-form': {
values: {
'email-address': '',
},
},
},
};

const CodeManagementPageWrapper = props => (
Expand Down
9 changes: 0 additions & 9 deletions src/containers/CouponDetails/CouponDetails.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ const enterpriseId = 'test-enterprise';
const mockStore = configureMockStore([thunk]);

const sampleEmailTemplate = {
'email-address': '',
'email-template-greeting': 'Sample email greeting.. ',
'email-template-body': 'Sample email body template.. ',
'email-template-closing': 'Sample email closing template.. ',
};

const emailDefaults = {
'template-id': 0,
'email-address': '',
'template-name-select': '',
'email-template-subject': 'Sample email subject.. ',
'email-template-greeting': 'Sample email greeting.. ',
Expand All @@ -47,13 +45,6 @@ const initialState = {
table: {
'coupon-details': {},
},
form: {
'code-assignment-modal-form': {
values: {
'email-address': '',
},
},
},
coupons: {
couponOverviewLoading: false,
couponOverviewError: null,
Expand Down
3 changes: 1 addition & 2 deletions src/containers/TemplateSourceFields/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { connect } from 'react-redux';

import TemplateSourceFields from '../../components/TemplateSourceFields';

import fetchEmailTemplates, { setEmailTemplateSource, currentFromTemplate, setEmailAddress } from '../../data/actions/emailTemplate';
import fetchEmailTemplates, { setEmailTemplateSource, currentFromTemplate } from '../../data/actions/emailTemplate';

const mapStateToProps = state => ({
emailTemplateSource: state.emailTemplate.emailTemplateSource,
Expand All @@ -11,7 +11,6 @@ const mapStateToProps = state => ({

const mapDispatchToProps = dispatch => ({
setEmailTemplateSource: templateSource => dispatch(setEmailTemplateSource(templateSource)),
setEmailAddress: (emailAddress, emailType) => dispatch(setEmailAddress(emailAddress, emailType)),
currentFromTemplate: (type, template) => dispatch(currentFromTemplate(type, template)),
fetchEmailTemplates: (options) => {
dispatch(fetchEmailTemplates(options));
Expand Down
13 changes: 0 additions & 13 deletions src/data/actions/emailTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
SAVE_TEMPLATE_FAILURE,
SET_EMAIL_TEMPLATE_SOURCE,
CURRENT_FROM_TEMPLATE,
SET_EMAIL_ADDRESS,
} from '../constants/emailTemplate';

import EcommerceApiService from '../services/EcommerceApiService';
Expand Down Expand Up @@ -92,16 +91,4 @@ export const setEmailTemplateSource = emailTemplateSource => (
}
);

export const setEmailAddress = (emailAddress, emailType) => (
(dispatch) => {
dispatch({
type: SET_EMAIL_ADDRESS,
payload: {
emailAddress,
emailType,
},
});
}
);

export default fetchEmailTemplates;
2 changes: 0 additions & 2 deletions src/data/constants/emailTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const SAVE_TEMPLATE_SUCCESS = 'SAVE_TEMPLATE_SUCCESS';
const SAVE_TEMPLATE_FAILURE = 'SAVE_TEMPLATE_FAILURE';
const SET_EMAIL_TEMPLATE_SOURCE = 'SET_EMAIL_TEMPLATE_SOURCE';
const CURRENT_FROM_TEMPLATE = 'CURRENT_FROM_TEMPLATE';
const SET_EMAIL_ADDRESS = 'SET_EMAIL_ADDRESS';

const OFFER_ASSIGNMENT_EMAIL_SUBJECT_LIMIT = 1000;
const EMAIL_TEMPLATE_FIELD_MAX_LIMIT = 50000;
Expand All @@ -26,5 +25,4 @@ export {
EMAIL_TEMPLATE_SOURCE_NEW_EMAIL,
EMAIL_TEMPLATE_SOURCE_FROM_TEMPLATE,
CURRENT_FROM_TEMPLATE,
SET_EMAIL_ADDRESS,
};
13 changes: 1 addition & 12 deletions src/data/reducers/emailTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import {
SET_EMAIL_TEMPLATE_SOURCE,
EMAIL_TEMPLATE_SOURCE_NEW_EMAIL,
CURRENT_FROM_TEMPLATE,
SET_EMAIL_ADDRESS,
} from '../constants/emailTemplate';

import { transformTemplate, updateAllTemplates, updateTemplateEmailAddress } from '../../utils';
import { transformTemplate, updateAllTemplates } from '../../utils';
import assignEmailTemplate from '../../components/CodeAssignmentModal/emailTemplate';
import remindEmailTemplate from '../../components/CodeReminderModal/emailTemplate';
import revokeEmailTemplate from '../../components/CodeRevokeModal/emailTemplate';
Expand All @@ -24,7 +23,6 @@ export const initialState = {
emailTemplateSource: EMAIL_TEMPLATE_SOURCE_NEW_EMAIL,
default: {
assign: {
'email-address': '',
'email-template-subject': assignEmailTemplate.subject,
'email-template-greeting': assignEmailTemplate.greeting,
'email-template-body': assignEmailTemplate.body,
Expand All @@ -45,7 +43,6 @@ export const initialState = {
},
assign: {
'template-id': 0,
'email-address': '',
'template-name-select': '',
'email-template-subject': assignEmailTemplate.subject,
'email-template-greeting': assignEmailTemplate.greeting,
Expand Down Expand Up @@ -127,14 +124,6 @@ const emailTemplate = (state = initialState, action) => {
...state,
emailTemplateSource: action.payload.emailTemplateSource,
};
case SET_EMAIL_ADDRESS:
return {
...state,
saving: false,
error: null,
...updateTemplateEmailAddress(action.payload.emailType, action.payload.emailAddress,
state.default[action.payload.emailType]),
};
default:
return state;
}
Expand Down
57 changes: 0 additions & 57 deletions src/data/reducers/emailTemplate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
SAVE_TEMPLATE_SUCCESS,
SAVE_TEMPLATE_FAILURE,
CURRENT_FROM_TEMPLATE,
SET_EMAIL_ADDRESS,
} from '../constants/emailTemplate';

import emailTemplate, { initialState as emailTemplateReducerInitialState } from './emailTemplate';
Expand All @@ -15,7 +14,6 @@ const saveTemplateSuccessResponse = {
email_body: 'I am email body',
email_closing: 'I am email closing',
name: 'template-1',
email_address: '',
id: 4,
};
const saveTemplateErrorResponse = {
Expand Down Expand Up @@ -66,7 +64,6 @@ describe('emailTemplate reducer', () => {
email_body: 'I am email body updated',
email_closing: 'I am email closing updated',
name: 'template-1 updated',
email_address: '[email protected]',
id: 4,
};

Expand All @@ -81,7 +78,6 @@ describe('emailTemplate reducer', () => {
'email-template-body': saveTemplateSuccessResponse.email_body,
'email-template-closing': saveTemplateSuccessResponse.email_closing,
'template-name-select': saveTemplateSuccessResponse.name,
'email-address': saveTemplateSuccessResponse.email_address,
'template-id': saveTemplateSuccessResponse.id,
},
},
Expand All @@ -98,7 +94,6 @@ describe('emailTemplate reducer', () => {
'email-template-body': saveTemplateSuccessUpdatedResponse.email_body,
'email-template-closing': saveTemplateSuccessUpdatedResponse.email_closing,
'template-name-select': saveTemplateSuccessUpdatedResponse.name,
'email-address': saveTemplateSuccessUpdatedResponse.email_address,
'template-id': saveTemplateSuccessUpdatedResponse.id,
},
},
Expand Down Expand Up @@ -161,56 +156,4 @@ describe('emailTemplate reducer', () => {
};
expect(emailTemplate(undefined, errorResponseActionData)).toEqual(expected);
});

it('updates store with email address on switching between new and saved templates', () => {
const saveTemplateSuccessUpdatedResponse = {
email_address: '[email protected]',
};

const initialState = {
...emailTemplateReducerInitialState,
saving: false,
error: null,
...{
default: {
[emailType]: {
'email-template-subject': saveTemplateSuccessResponse.email_subject,
'email-template-greeting': saveTemplateSuccessResponse.email_greeting,
'email-template-body': saveTemplateSuccessResponse.email_body,
'email-template-closing': saveTemplateSuccessResponse.email_closing,
'template-name-select': saveTemplateSuccessResponse.name,
'email-address': '',
'template-id': saveTemplateSuccessResponse.id,
},
},
},
};

const expected = {
...emailTemplateReducerInitialState,
saving: false,
error: null,
...{
default: {
[emailType]: {
'email-template-subject': saveTemplateSuccessResponse.email_subject,
'email-template-greeting': saveTemplateSuccessResponse.email_greeting,
'email-template-body': saveTemplateSuccessResponse.email_body,
'email-template-closing': saveTemplateSuccessResponse.email_closing,
'template-name-select': saveTemplateSuccessResponse.name,
'email-address': saveTemplateSuccessUpdatedResponse.email_address,
'template-id': saveTemplateSuccessResponse.id,
},
},
},
};
const successResponseActionData = {
type: SET_EMAIL_ADDRESS,
payload: {
emailType,
emailAddress: '[email protected]',
},
};
expect(emailTemplate(initialState, successResponseActionData)).toEqual(expected);
});
});
Loading

0 comments on commit aa9b429

Please sign in to comment.