Hide payment settings form if already connected

This commit is contained in:
Kimmo Puputti 2018-02-27 15:12:48 +02:00
parent b0bec19fca
commit 9566c849b5
5 changed files with 44 additions and 29 deletions

View file

@ -4,11 +4,14 @@ import { fetchCurrentUser, createStripeAccount } from '../../ducks/user.duck';
// ================ Action types ================ //
export const SET_INITIAL_STATE = 'app/PayoutPreferencesPage/SET_INITIAL_STATE';
export const SAVE_PAYOUT_DETAILS_REQUEST = 'app/PayoutPreferencesPage/SAVE_PAYOUT_DETAILS_REQUEST';
export const SAVE_PAYOUT_DETAILS_SUCCESS = 'app/PayoutPreferencesPage/SAVE_PAYOUT_DETAILS_SUCCESS';
export const SAVE_PAYOUT_DETAILS_ERROR = 'app/PayoutPreferencesPage/SAVE_PAYOUT_DETAILS_ERROR';
// ================ Reducer ================ //
const initialState = {
payoutDetailsSaveInProgress: false,
payoutDetailsSaved: false,
};
@ -17,8 +20,14 @@ export default function payoutPreferencesPageReducer(state = initialState, actio
switch (type) {
case SET_INITIAL_STATE:
return initialState;
case SAVE_PAYOUT_DETAILS_REQUEST:
return { ...state, payoutDetailsSaveInProgress: true };
case SAVE_PAYOUT_DETAILS_ERROR:
return { ...state, payoutDetailsSaveInProgress: false };
case SAVE_PAYOUT_DETAILS_SUCCESS:
return { ...state, payoutDetailsSaved: true };
return { ...state, payoutDetailsSaveInProgress: false, payoutDetailsSaved: true };
default:
return state;
}
@ -30,6 +39,12 @@ export const setInitialState = () => ({
type: SET_INITIAL_STATE,
});
export const savePayoutDetailsRequest = () => ({
type: SAVE_PAYOUT_DETAILS_REQUEST,
});
export const savePayoutDetailsError = () => ({
type: SAVE_PAYOUT_DETAILS_ERROR,
});
export const savePayoutDetailsSuccess = () => ({
type: SAVE_PAYOUT_DETAILS_SUCCESS,
});
@ -37,6 +52,7 @@ export const savePayoutDetailsSuccess = () => ({
// ================ Thunks ================ //
export const savePayoutDetails = values => (dispatch, getState, sdk) => {
dispatch(savePayoutDetailsRequest());
const {
firstName,
lastName,
@ -60,7 +76,9 @@ export const savePayoutDetails = values => (dispatch, getState, sdk) => {
bankAccountToken,
address: omitBy(address, isUndefined),
};
return dispatch(createStripeAccount(params)).then(() => dispatch(savePayoutDetailsSuccess()));
return dispatch(createStripeAccount(params))
.then(() => dispatch(savePayoutDetailsSuccess()))
.catch(() => dispatch(savePayoutDetailsError()));
};
export const loadData = () => (dispatch, getState, sdk) => {

View file

@ -26,10 +26,10 @@ export const PayoutPreferencesPageComponent = props => {
const {
currentUser,
scrollingDisabled,
fetchInProgress,
createStripeAccountError,
onPayoutDetailsFormChange,
onPayoutDetailsFormSubmit,
payoutDetailsSaveInProgress,
payoutDetailsSaved,
intl,
} = props;
@ -75,6 +75,19 @@ export const PayoutPreferencesPageComponent = props => {
message = <FormattedMessage id="PayoutPreferencesPage.stripeNotConnected" />;
}
const showForm =
currentUserLoaded && (payoutDetailsSaveInProgress || payoutDetailsSaved || !stripeConnected);
const form = showForm ? (
<PayoutDetailsForm
disabled={formDisabled}
inProgress={payoutDetailsSaveInProgress}
ready={payoutDetailsSaved}
createStripeAccountError={createStripeAccountError}
onChange={onPayoutDetailsFormChange}
onSubmit={onPayoutDetailsFormSubmit}
/>
) : null;
return (
<Page title={title} scrollingDisabled={scrollingDisabled}>
<LayoutSideNavigation>
@ -93,14 +106,7 @@ export const PayoutPreferencesPageComponent = props => {
<FormattedMessage id="PayoutPreferencesPage.heading" />
</h1>
<p>{message}</p>
<PayoutDetailsForm
disabled={formDisabled}
inProgress={fetchInProgress}
ready={payoutDetailsSaved}
createStripeAccountError={createStripeAccountError}
onChange={onPayoutDetailsFormChange}
onSubmit={onPayoutDetailsFormSubmit}
/>
{form}
</div>
</LayoutWrapperMain>
<LayoutWrapperFooter>
@ -119,7 +125,7 @@ PayoutPreferencesPageComponent.defaultProps = {
PayoutPreferencesPageComponent.propTypes = {
currentUser: propTypes.currentUser,
scrollingDisabled: bool.isRequired,
fetchInProgress: bool.isRequired,
payoutDetailsSaveInProgress: bool.isRequired,
createStripeAccountError: propTypes.error,
payoutDetailsSaved: bool.isRequired,
@ -131,13 +137,12 @@ PayoutPreferencesPageComponent.propTypes = {
};
const mapStateToProps = state => {
const { createStripeAccountInProgress, createStripeAccountError, currentUser } = state.user;
const fetchInProgress = createStripeAccountInProgress;
const { payoutDetailsSaved } = state.PayoutPreferencesPage;
const { createStripeAccountError, currentUser } = state.user;
const { payoutDetailsSaveInProgress, payoutDetailsSaved } = state.PayoutPreferencesPage;
return {
currentUser,
fetchInProgress,
createStripeAccountError,
payoutDetailsSaveInProgress,
payoutDetailsSaved,
scrollingDisabled: isScrollingDisabled(state),
};

View file

@ -15,7 +15,7 @@ describe('PayoutPreferencesPage', () => {
<PayoutPreferencesPageComponent
currentUser={currentUser}
scrollingDisabled={false}
fetchInProgress={false}
payoutDetailsSaveInProgress={false}
payoutDetailsSaved={false}
onPayoutDetailsFormChange={noop}
onPayoutDetailsFormSubmit={noop}
@ -31,7 +31,7 @@ describe('PayoutPreferencesPage', () => {
<PayoutPreferencesPageComponent
currentUser={currentUser}
scrollingDisabled={false}
fetchInProgress={false}
payoutDetailsSaveInProgress={false}
payoutDetailsSaved={false}
onPayoutDetailsFormChange={noop}
onPayoutDetailsFormSubmit={noop}
@ -47,7 +47,7 @@ describe('PayoutPreferencesPage', () => {
<PayoutPreferencesPageComponent
currentUser={currentUser}
scrollingDisabled={false}
fetchInProgress={false}
payoutDetailsSaveInProgress={false}
payoutDetailsSaved={true}
onPayoutDetailsFormChange={noop}
onPayoutDetailsFormSubmit={noop}

View file

@ -78,14 +78,6 @@ exports[`PayoutPreferencesPage matches snapshot with Stripe connected 1`] = `
values={Object {}}
/>
</p>
<Connect(ReduxForm)
createStripeAccountError={null}
disabled={true}
inProgress={false}
onChange={[Function]}
onSubmit={[Function]}
ready={false}
/>
</div>
</LayoutWrapperMain>
<LayoutWrapperFooter

View file

@ -442,8 +442,8 @@
"PayoutPreferencesPage.loadingData": "Loading data…",
"PayoutPreferencesPage.passwordTabTitle": "Password",
"PayoutPreferencesPage.paymentsTabTitle": "Payments",
"PayoutPreferencesPage.payoutDetailsSaved": "Payment information successfully saved!",
"PayoutPreferencesPage.stripeAlreadyConnected": "Payment information already saved. If you want to change your information, contact your administrator.",
"PayoutPreferencesPage.payoutDetailsSaved": "Payment information successfully saved! If you want to change your payment details, please contact the marketplace admins.",
"PayoutPreferencesPage.stripeAlreadyConnected": "Youve already entered your payment details. If you want to change your payment details, please contact the marketplace admins.",
"PayoutPreferencesPage.stripeNotConnected": "Payment information not saved. Please fill in the form to accept payments from your listings.",
"PayoutPreferencesPage.title": "Payment settings",
"PrivacyPolicyPage.heading": "Saunatime Privacy Policy",