Skip to content

Commit

Permalink
Rename components & remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
LudvigHz committed Sep 18, 2019
1 parent b2b34aa commit 11b6698
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 55 deletions.
14 changes: 3 additions & 11 deletions app/reducers/registrations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import { union, get } from 'lodash';
import { union } from 'lodash';
import { Event } from '../actions/ActionTypes';
import createEntityReducer from 'app/utils/createEntityReducer';
import { normalize } from 'normalizr';
Expand Down Expand Up @@ -34,21 +34,13 @@ export default createEntityReducer({
if (!registration) {
return state;
}
let paymentErrorData = {};
if (action.type === Event.SOCKET_PAYMENT.FAILURE) {
paymentErrorData.paymentError = get(action, 'meta.errorMessage');
}
return {
...state,
byId: {
...state.byId,
[registration.id]: {
...omit(state.byId[registration.id], [
'unregistrationDate',
'paymentError'
]),
...registration,
...paymentErrorData
...omit(state.byId[registration.id], 'unregistrationDate'),
...registration
}
},
items: union(state.items, [registration.id])
Expand Down
83 changes: 45 additions & 38 deletions app/routes/events/components/StripeElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,36 @@ type Props = {
chargeStatus: EventRegistrationChargeStatus
};

/*
* Taken from https://stripe.com/docs/api/errors
*/
type StripeError = {
type: string,
charge: string,
code: string,
decline_code: string,
message: string,
doc_url: string
param: string,
doc_url: string,
payment_intent: Object,
setup_intent: Object,
source: Object
};

type FormProps = Props & {
fontSize?: number
};

type _SplitFormProps = FormProps & {
type CardFormProps = FormProps & {
ledgend: string,
setError: Object => void,
setError: StripeError => void,
setSuccess: () => void,
setLoading: boolean => void,
stripe: Stripe
};

type _PaymentRequestFormProps = FormProps & {
setError: Object => void,
type PaymentRequestFormProps = FormProps & {
setError: StripeError => void,
setSuccess: () => void,
setLoading: boolean => void,
setPaymentRequest: boolean => void,
Expand All @@ -65,26 +74,24 @@ type State = {
paymentRequest?: Object,
canMakePayment?: boolean
};
const createOptions = (fontSize, padding) => {
return {
style: {
base: {
fontSize,
color: '#424770',
letterSpacing: '0.025em',
fontFamily: 'Source Code Pro, monospace',
'::placeholder': {
color: '#aab7c4'
},
padding
},
invalid: {
color: '#9e2146'

const createOptions = {
style: {
base: {
color: '#424770',
letterSpacing: '0.025em',
fontFamily: 'Source Code Pro, monospace',
'::placeholder': {
color: '#aab7c4'
}
},
invalid: {
color: '#9e2146'
}
};
}
};
class _SplitForm extends React.Component<_SplitFormProps, FormState> {

class CardForm extends React.Component<CardFormProps, FormState> {
handleSubmit = async ev => {
ev.preventDefault();
const { stripe, createPaymentIntent } = this.props;
Expand All @@ -111,22 +118,22 @@ class _SplitForm extends React.Component<_SplitFormProps, FormState> {
Kortnummer
<CardNumberElement
className={stripeStyles.StripeElement}
{...createOptions(this.props.fontSize)}
{...createOptions}
/>
</label>
<label className={stripeStyles.StripeLabel}>
Utløpsdato
<CardExpiryElement
className={stripeStyles.StripeElement}
{...createOptions(this.props.fontSize)}
{...createOptions}
/>
</label>
<label className={stripeStyles.StripeLabel}>
CVC
<CardCVCElement
className={stripeStyles.StripeElement}
onReady={() => this.setState({})}
{...createOptions(this.props.fontSize)}
{...createOptions}
/>
</label>
<button className={stripeStyles.StripeButton}>Betal</button>
Expand All @@ -136,8 +143,8 @@ class _SplitForm extends React.Component<_SplitFormProps, FormState> {
}
}

class _PaymentRequestForm extends React.Component<
_PaymentRequestFormProps,
class PaymentRequestForm extends React.Component<
PaymentRequestFormProps,
State
> {
constructor(props) {
Expand Down Expand Up @@ -211,8 +218,8 @@ class _PaymentRequestForm extends React.Component<
}
}

const PaymentRequestForm = injectStripe(_PaymentRequestForm);
const SplitForm = injectStripe(_SplitForm);
const InjectedPaymentRequestForm = injectStripe(PaymentRequestForm);
const InjectedCardForm = injectStripe(CardForm);

class PaymentForm extends React.Component<FormProps, FormState> {
state = {
Expand All @@ -235,13 +242,19 @@ class PaymentForm extends React.Component<FormProps, FormState> {

render() {
const { success, error, loading } = this.state;
return !success ? (
return success ? (
<div className={stripeStyles.success}>
{`Din betaling på ${
this.props.event.price ? this.props.event.price / 100 : ''
} kr ble godkjent.`}
</div>
) : (
<>
{loading && <LoadingIndicator loading />}
{error && <div className={stripeStyles.error}>{error.message}</div>}
<div style={{ display: loading ? 'none' : 'block' }}>
<Elements locale="no">
<PaymentRequestForm
<InjectedPaymentRequestForm
{...this.props}
setSuccess={() => this.setSuccess()}
setError={error => this.setError(error)}
Expand All @@ -252,7 +265,7 @@ class PaymentForm extends React.Component<FormProps, FormState> {
/>
</Elements>
<Elements locale="no">
<SplitForm
<InjectedCardForm
{...this.props}
fontSize={'18px'}
setSuccess={() => this.setSuccess()}
Expand All @@ -267,12 +280,6 @@ class PaymentForm extends React.Component<FormProps, FormState> {
</Elements>
</div>
</>
) : (
<div className={stripeStyles.success}>
{`Din betaling på ${
this.props.event.price ? this.props.event.price / 100 : ''
} kr ble godkjent.`}
</div>
);
}
}
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
"react-select": "^1.0.0-rc.3",
"react-soundplayer": "^1.0.4",
"react-stickynode": "^2.1.1",
"react-stripe-checkout": "^2.4.0",
"react-stripe-elements": "^5.0.0",
"react-swipeable": "5.0.0",
"react-tagcloud": "^1.2.0",
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10855,11 +10855,6 @@ react-stickynode@^2.1.1:
shallowequal "^1.0.0"
subscribe-ui-event "^2.0.0"

react-stripe-checkout@^2.4.0:
version "2.6.3"
resolved "https://registry.yarnpkg.com/react-stripe-checkout/-/react-stripe-checkout-2.6.3.tgz#3173a870b04e5a3c321a06d24cd53c6030111c45"
integrity sha1-MXOocLBOWjwyGgbSTNU8YDARHEU=

react-stripe-elements@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/react-stripe-elements/-/react-stripe-elements-5.0.0.tgz#3a67717ddc9580c4dad9d45b672a9cf6c8a6dda4"
Expand Down

0 comments on commit 11b6698

Please sign in to comment.