mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-27 19:42:11 +10:00
Merge pull request #737 from sharetribe/edit-phone-number
Rename edit email to edit contact details
This commit is contained in:
commit
e7d1155fc8
10 changed files with 78 additions and 69 deletions
|
|
@ -45,7 +45,7 @@ class ContactDetailsFormComponent extends Component {
|
|||
const {
|
||||
rootClassName,
|
||||
className,
|
||||
changeEmailError,
|
||||
saveContactDetailsError,
|
||||
currentUser,
|
||||
form,
|
||||
handleSubmit,
|
||||
|
|
@ -86,7 +86,7 @@ class ContactDetailsFormComponent extends Component {
|
|||
sendVerificationEmailError
|
||||
);
|
||||
|
||||
const emailTakenErrorText = isChangeEmailTakenError(changeEmailError)
|
||||
const emailTakenErrorText = isChangeEmailTakenError(saveContactDetailsError)
|
||||
? intl.formatMessage({ id: 'ContactDetailsForm.emailTakenError' })
|
||||
: null;
|
||||
|
||||
|
|
@ -187,7 +187,7 @@ class ContactDetailsFormComponent extends Component {
|
|||
const passwordFailedMessage = intl.formatMessage({
|
||||
id: 'ContactDetailsForm.passwordFailed',
|
||||
});
|
||||
const passwordErrorText = isChangeEmailWrongPassword(changeEmailError)
|
||||
const passwordErrorText = isChangeEmailWrongPassword(saveContactDetailsError)
|
||||
? passwordFailedMessage
|
||||
: null;
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ class ContactDetailsFormComponent extends Component {
|
|||
});
|
||||
|
||||
const genericFailure =
|
||||
changeEmailError && !(emailTakenErrorText || passwordErrorText) ? (
|
||||
saveContactDetailsError && !(emailTakenErrorText || passwordErrorText) ? (
|
||||
<span className={css.error}>
|
||||
<FormattedMessage id="ContactDetailsForm.genericFailure" />
|
||||
</span>
|
||||
|
|
@ -260,7 +260,7 @@ class ContactDetailsFormComponent extends Component {
|
|||
ContactDetailsFormComponent.defaultProps = {
|
||||
rootClassName: null,
|
||||
className: null,
|
||||
changeEmailError: null,
|
||||
saveContactDetailsError: null,
|
||||
inProgress: false,
|
||||
sendVerificationEmailError: null,
|
||||
sendVerificationEmailInProgress: false,
|
||||
|
|
@ -272,7 +272,7 @@ ContactDetailsFormComponent.propTypes = {
|
|||
...formPropTypes,
|
||||
rootClassName: string,
|
||||
className: string,
|
||||
changeEmailError: propTypes.error,
|
||||
saveContactDetailsError: propTypes.error,
|
||||
inProgress: bool,
|
||||
intl: intlShape.isRequired,
|
||||
onResendVerificationEmail: func.isRequired,
|
||||
|
|
|
|||
|
|
@ -3,36 +3,41 @@ import { currentUserShowSuccess } from '../../ducks/user.duck';
|
|||
|
||||
// ================ Action types ================ //
|
||||
|
||||
export const CHANGE_EMAIL_REQUEST = 'app/ContactDetailsPage/CHANGE_EMAIL_REQUEST';
|
||||
export const CHANGE_EMAIL_SUCCESS = 'app/ContactDetailsPage/CHANGE_EMAIL_SUCCESS';
|
||||
export const CHANGE_EMAIL_ERROR = 'app/ContactDetailsPage/CHANGE_EMAIL_ERROR';
|
||||
export const SAVE_CONTACT_DETAILS_REQUEST = 'app/ContactDetailsPage/SAVE_CONTACT_DETAILS_REQUEST';
|
||||
export const SAVE_CONTACT_DETAILS_SUCCESS = 'app/ContactDetailsPage/SAVE_CONTACT_DETAILS_SUCCESS';
|
||||
export const SAVE_CONTACT_DETAILS_ERROR = 'app/ContactDetailsPage/SAVE_CONTACT_DETAILS_ERROR';
|
||||
|
||||
export const CHANGE_EMAIL_CLEAR = 'app/ContactDetailsPage/CHANGE_EMAIL_CLEAR';
|
||||
export const SAVE_CONTACT_DETAILS_CLEAR = 'app/ContactDetailsPage/SAVE_CONTACT_DETAILS_CLEAR';
|
||||
|
||||
// ================ Reducer ================ //
|
||||
|
||||
const initialState = {
|
||||
changeEmailError: null,
|
||||
changeEmailInProgress: false,
|
||||
emailChanged: false,
|
||||
saveContactDetailsError: null,
|
||||
saveContactDetailsInProgress: false,
|
||||
contactDetailsChanged: false,
|
||||
};
|
||||
|
||||
export default function reducer(state = initialState, action = {}) {
|
||||
const { type, payload } = action;
|
||||
switch (type) {
|
||||
case CHANGE_EMAIL_REQUEST:
|
||||
return { ...state, changeEmailInProgress: true, changeEmailError: null, emailChanged: false };
|
||||
case CHANGE_EMAIL_SUCCESS:
|
||||
return { ...state, changeEmailInProgress: false, emailChanged: true };
|
||||
case CHANGE_EMAIL_ERROR:
|
||||
return { ...state, changeEmailInProgress: false, changeEmailError: payload };
|
||||
|
||||
case CHANGE_EMAIL_CLEAR:
|
||||
case SAVE_CONTACT_DETAILS_REQUEST:
|
||||
return {
|
||||
...state,
|
||||
changeEmailInProgress: false,
|
||||
changeEmailError: null,
|
||||
emailChanged: false,
|
||||
saveContactDetailsInProgress: true,
|
||||
saveContactDetailsError: null,
|
||||
contactDetailsChanged: false,
|
||||
};
|
||||
case SAVE_CONTACT_DETAILS_SUCCESS:
|
||||
return { ...state, saveContactDetailsInProgress: false, contactDetailsChanged: true };
|
||||
case SAVE_CONTACT_DETAILS_ERROR:
|
||||
return { ...state, saveContactDetailsInProgress: false, saveContactDetailsError: payload };
|
||||
|
||||
case SAVE_CONTACT_DETAILS_CLEAR:
|
||||
return {
|
||||
...state,
|
||||
saveContactDetailsInProgress: false,
|
||||
saveContactDetailsError: null,
|
||||
contactDetailsChanged: false,
|
||||
};
|
||||
|
||||
default:
|
||||
|
|
@ -42,28 +47,28 @@ export default function reducer(state = initialState, action = {}) {
|
|||
|
||||
// ================ Action creators ================ //
|
||||
|
||||
export const changeEmailRequest = () => ({ type: CHANGE_EMAIL_REQUEST });
|
||||
export const changeEmailSuccess = () => ({ type: CHANGE_EMAIL_SUCCESS });
|
||||
export const changeEmailError = error => ({
|
||||
type: CHANGE_EMAIL_ERROR,
|
||||
export const saveContactDetailsRequest = () => ({ type: SAVE_CONTACT_DETAILS_REQUEST });
|
||||
export const saveContactDetailsSuccess = () => ({ type: SAVE_CONTACT_DETAILS_SUCCESS });
|
||||
export const saveContactDetailsError = error => ({
|
||||
type: SAVE_CONTACT_DETAILS_ERROR,
|
||||
payload: error,
|
||||
error: true,
|
||||
});
|
||||
|
||||
export const changeEmailClear = () => ({ type: CHANGE_EMAIL_CLEAR });
|
||||
export const saveContactDetailsClear = () => ({ type: SAVE_CONTACT_DETAILS_CLEAR });
|
||||
|
||||
// ================ Thunks ================ //
|
||||
|
||||
export const changeEmail = params => (dispatch, getState, sdk) => {
|
||||
dispatch(changeEmailRequest());
|
||||
export const saveContactDetails = params => (dispatch, getState, sdk) => {
|
||||
dispatch(saveContactDetailsRequest());
|
||||
const { email, currentPassword } = params;
|
||||
|
||||
return sdk.currentUser
|
||||
.changeEmail({ email, currentPassword }, { expand: true })
|
||||
.then(response => {
|
||||
const currentUser = response.data.data;
|
||||
dispatch(changeEmailSuccess());
|
||||
dispatch(saveContactDetailsSuccess());
|
||||
dispatch(currentUserShowSuccess(currentUser));
|
||||
})
|
||||
.catch(e => dispatch(changeEmailError(storableError(e))));
|
||||
.catch(e => dispatch(saveContactDetailsError(storableError(e))));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -19,27 +19,27 @@ import {
|
|||
import { ContactDetailsForm, TopbarContainer } from '../../containers';
|
||||
|
||||
import { isScrollingDisabled } from '../../ducks/UI.duck';
|
||||
import { changeEmail, changeEmailClear } from './ContactDetailsPage.duck';
|
||||
import { saveContactDetails, saveContactDetailsClear } from './ContactDetailsPage.duck';
|
||||
import css from './ContactDetailsPage.css';
|
||||
|
||||
export const ContactDetailsPageComponent = props => {
|
||||
const {
|
||||
changeEmailError,
|
||||
changeEmailInProgress,
|
||||
saveContactDetailsError,
|
||||
saveContactDetailsInProgress,
|
||||
currentUser,
|
||||
emailChanged,
|
||||
contactDetailsChanged,
|
||||
onChange,
|
||||
scrollingDisabled,
|
||||
sendVerificationEmailInProgress,
|
||||
sendVerificationEmailError,
|
||||
onResendVerificationEmail,
|
||||
onSubmitChangeEmail,
|
||||
onSubmitContactDetails,
|
||||
intl,
|
||||
} = props;
|
||||
|
||||
const tabs = [
|
||||
{
|
||||
text: <FormattedMessage id="ContactDetailsPage.emailTabTitle" />,
|
||||
text: <FormattedMessage id="ContactDetailsPage.contactDetailsTabTitle" />,
|
||||
selected: true,
|
||||
linkProps: {
|
||||
name: 'ContactDetailsPage',
|
||||
|
|
@ -63,17 +63,17 @@ export const ContactDetailsPageComponent = props => {
|
|||
|
||||
const user = ensureCurrentUser(currentUser);
|
||||
const email = user.attributes.email || '';
|
||||
const changeEmailForm = user.id ? (
|
||||
const contactInfoForm = user.id ? (
|
||||
<ContactDetailsForm
|
||||
className={css.form}
|
||||
initialValues={{ email }}
|
||||
changeEmailError={changeEmailError}
|
||||
saveContactDetailsError={saveContactDetailsError}
|
||||
currentUser={currentUser}
|
||||
onResendVerificationEmail={onResendVerificationEmail}
|
||||
onSubmit={onSubmitChangeEmail}
|
||||
onSubmit={onSubmitContactDetails}
|
||||
onChange={onChange}
|
||||
inProgress={changeEmailInProgress}
|
||||
ready={emailChanged}
|
||||
inProgress={saveContactDetailsInProgress}
|
||||
ready={contactDetailsChanged}
|
||||
sendVerificationEmailInProgress={sendVerificationEmailInProgress}
|
||||
sendVerificationEmailError={sendVerificationEmailError}
|
||||
/>
|
||||
|
|
@ -98,7 +98,7 @@ export const ContactDetailsPageComponent = props => {
|
|||
<h1 className={css.title}>
|
||||
<FormattedMessage id="ContactDetailsPage.heading" />
|
||||
</h1>
|
||||
{changeEmailForm}
|
||||
{contactInfoForm}
|
||||
</div>
|
||||
</LayoutWrapperMain>
|
||||
<LayoutWrapperFooter>
|
||||
|
|
@ -110,7 +110,7 @@ export const ContactDetailsPageComponent = props => {
|
|||
};
|
||||
|
||||
ContactDetailsPageComponent.defaultProps = {
|
||||
changeEmailError: null,
|
||||
saveContactDetailsError: null,
|
||||
currentUser: null,
|
||||
sendVerificationEmailError: null,
|
||||
};
|
||||
|
|
@ -118,12 +118,12 @@ ContactDetailsPageComponent.defaultProps = {
|
|||
const { bool, func } = PropTypes;
|
||||
|
||||
ContactDetailsPageComponent.propTypes = {
|
||||
changeEmailError: propTypes.error,
|
||||
changeEmailInProgress: bool.isRequired,
|
||||
saveContactDetailsError: propTypes.error,
|
||||
saveContactDetailsInProgress: bool.isRequired,
|
||||
currentUser: propTypes.currentUser,
|
||||
emailChanged: bool.isRequired,
|
||||
contactDetailsChanged: bool.isRequired,
|
||||
onChange: func.isRequired,
|
||||
onSubmitChangeEmail: func.isRequired,
|
||||
onSubmitContactDetails: func.isRequired,
|
||||
scrollingDisabled: bool.isRequired,
|
||||
sendVerificationEmailInProgress: bool.isRequired,
|
||||
sendVerificationEmailError: propTypes.error,
|
||||
|
|
@ -136,12 +136,16 @@ ContactDetailsPageComponent.propTypes = {
|
|||
const mapStateToProps = state => {
|
||||
// Topbar needs user info.
|
||||
const { currentUser, sendVerificationEmailInProgress, sendVerificationEmailError } = state.user;
|
||||
const { changeEmailError, changeEmailInProgress, emailChanged } = state.ContactDetailsPage;
|
||||
const {
|
||||
saveContactDetailsError,
|
||||
saveContactDetailsInProgress,
|
||||
contactDetailsChanged,
|
||||
} = state.ContactDetailsPage;
|
||||
return {
|
||||
changeEmailError,
|
||||
changeEmailInProgress,
|
||||
saveContactDetailsError,
|
||||
saveContactDetailsInProgress,
|
||||
currentUser,
|
||||
emailChanged,
|
||||
contactDetailsChanged,
|
||||
scrollingDisabled: isScrollingDisabled(state),
|
||||
sendVerificationEmailInProgress,
|
||||
sendVerificationEmailError,
|
||||
|
|
@ -149,9 +153,9 @@ const mapStateToProps = state => {
|
|||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
onChange: () => dispatch(changeEmailClear()),
|
||||
onChange: () => dispatch(saveContactDetailsClear()),
|
||||
onResendVerificationEmail: () => dispatch(sendVerificationEmail()),
|
||||
onSubmitChangeEmail: values => dispatch(changeEmail(values)),
|
||||
onSubmitContactDetails: values => dispatch(saveContactDetails(values)),
|
||||
});
|
||||
|
||||
const ContactDetailsPage = compose(connect(mapStateToProps, mapDispatchToProps), injectIntl)(
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ describe('ContactDetailsPage', () => {
|
|||
onManageDisableScrolling={noop}
|
||||
sendVerificationEmailInProgress={false}
|
||||
onResendVerificationEmail={noop}
|
||||
onSubmitChangeEmail={noop}
|
||||
changeEmailInProgress={false}
|
||||
emailChanged={false}
|
||||
onSubmitContactDetails={noop}
|
||||
saveContactDetailsInProgress={false}
|
||||
contactDetailsChanged={false}
|
||||
intl={fakeIntl}
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ exports[`ContactDetailsPage matches snapshot 1`] = `
|
|||
},
|
||||
"selected": true,
|
||||
"text": <FormattedMessage
|
||||
id="ContactDetailsPage.emailTabTitle"
|
||||
id="ContactDetailsPage.contactDetailsTabTitle"
|
||||
values={Object {}}
|
||||
/>,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export const PasswordChangePageComponent = props => {
|
|||
|
||||
const tabs = [
|
||||
{
|
||||
text: <FormattedMessage id="PasswordChangePage.emailTabTitle" />,
|
||||
text: <FormattedMessage id="PasswordChangePage.contactDetailsTabTitle" />,
|
||||
selected: false,
|
||||
linkProps: {
|
||||
name: 'ContactDetailsPage',
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ exports[`PasswordChangePage matches snapshot 1`] = `
|
|||
},
|
||||
"selected": false,
|
||||
"text": <FormattedMessage
|
||||
id="PasswordChangePage.emailTabTitle"
|
||||
id="PasswordChangePage.contactDetailsTabTitle"
|
||||
values={Object {}}
|
||||
/>,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export const PayoutPreferencesPageComponent = props => {
|
|||
|
||||
const tabs = [
|
||||
{
|
||||
text: <FormattedMessage id="PayoutPreferencesPage.emailTabTitle" />,
|
||||
text: <FormattedMessage id="PayoutPreferencesPage.contactDetailsTabTitle" />,
|
||||
selected: false,
|
||||
linkProps: {
|
||||
name: 'ContactDetailsPage',
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ exports[`PayoutPreferencesPage matches snapshot with Stripe connected 1`] = `
|
|||
},
|
||||
"selected": false,
|
||||
"text": <FormattedMessage
|
||||
id="PayoutPreferencesPage.emailTabTitle"
|
||||
id="PayoutPreferencesPage.contactDetailsTabTitle"
|
||||
values={Object {}}
|
||||
/>,
|
||||
},
|
||||
|
|
@ -124,7 +124,7 @@ exports[`PayoutPreferencesPage matches snapshot with Stripe not connected 1`] =
|
|||
},
|
||||
"selected": false,
|
||||
"text": <FormattedMessage
|
||||
id="PayoutPreferencesPage.emailTabTitle"
|
||||
id="PayoutPreferencesPage.contactDetailsTabTitle"
|
||||
values={Object {}}
|
||||
/>,
|
||||
},
|
||||
|
|
@ -223,7 +223,7 @@ exports[`PayoutPreferencesPage matches snapshot with details submitted 1`] = `
|
|||
},
|
||||
"selected": false,
|
||||
"text": <FormattedMessage
|
||||
id="PayoutPreferencesPage.emailTabTitle"
|
||||
id="PayoutPreferencesPage.contactDetailsTabTitle"
|
||||
values={Object {}}
|
||||
/>,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@
|
|||
"ContactDetailsForm.resendEmailVerificationText": "Resend verification email.",
|
||||
"ContactDetailsForm.saveChanges": "Save changes",
|
||||
"ContactDetailsForm.tooManyVerificationRequests": "Too many email verification requests sent.",
|
||||
"ContactDetailsPage.emailTabTitle": "Email",
|
||||
"ContactDetailsPage.contactDetailsTabTitle": "Email",
|
||||
"ContactDetailsPage.heading": "Email settings",
|
||||
"ContactDetailsPage.passwordTabTitle": "Password",
|
||||
"ContactDetailsPage.paymentsTabTitle": "Payments",
|
||||
|
|
@ -346,7 +346,7 @@
|
|||
"PasswordChangeForm.passwordTooLong": "The password should be at most {maxLength} characters",
|
||||
"PasswordChangeForm.passwordTooShort": "The password should be at least {minLength} characters",
|
||||
"PasswordChangeForm.saveChanges": "Save changes",
|
||||
"PasswordChangePage.emailTabTitle": "Email",
|
||||
"PasswordChangePage.contactDetailsTabTitle": "Email",
|
||||
"PasswordChangePage.heading": "Password settings",
|
||||
"PasswordChangePage.passwordTabTitle": "Password",
|
||||
"PasswordChangePage.paymentsTabTitle": "Payments",
|
||||
|
|
@ -439,7 +439,7 @@
|
|||
"PayoutDetailsForm.streetAddressRequired": "This field is required",
|
||||
"PayoutDetailsForm.submitButtonText": "Save details & publish listing",
|
||||
"PayoutDetailsForm.title": "One more thing: payout preferences",
|
||||
"PayoutPreferencesPage.emailTabTitle": "Email",
|
||||
"PayoutPreferencesPage.contactDetailsTabTitle": "Email",
|
||||
"PayoutPreferencesPage.heading": "Payment settings",
|
||||
"PayoutPreferencesPage.loadingData": "Loading data…",
|
||||
"PayoutPreferencesPage.passwordTabTitle": "Password",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue