Skip to content

Commit

Permalink
prettier, packages, and fixing postcss
Browse files Browse the repository at this point in the history
  • Loading branch information
faultyserver committed Dec 2, 2019
1 parent 949199e commit d57f11e
Show file tree
Hide file tree
Showing 44 changed files with 551 additions and 598 deletions.
16 changes: 8 additions & 8 deletions bundles/donate/donation/DonationActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ export function loadDonation(donation) {
wantsEmails: donation.requestedsolicitemail,
amount: null,
comment: null,
}
}
};
},
};
}

export function updateDonation(fields={}) {
if(fields.hasOwnProperty('amount')) {
export function updateDonation(fields = {}) {
if (fields.hasOwnProperty('amount')) {
const parsedAmount = Number(fields.amount);
fields.amount = parsedAmount === NaN ? null : parsedAmount;
}

return {
type: 'donation/UPDATE_DONATION',
data: {
...fields
}
...fields,
},
};
};
}
2 changes: 1 addition & 1 deletion bundles/donate/donation/DonationConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const EMAIL_OPTIONS = [
{
name: 'Use Existing Preference (No if not set)',
value: 'CURR',
}
},
];

export const AMOUNT_PRESETS = [25, 50, 75, 100, 250, 500];
31 changes: 16 additions & 15 deletions bundles/donate/donation/DonationReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,31 @@ import _ from 'lodash';
// };

const defaultDonation = {
name: "",
name: '',
nameVisibility: 'ANON',
email: "",
email: '',
wantsEmails: 'CURR',
amount: null,
comment: "",
comment: '',
};
const defaultState = {...defaultDonation};
const defaultState = { ...defaultDonation };

const actions = {
'donation/UPDATE_DONATION': (state, {data}) => {
return _.merge({...state}, {
name: data.name,
nameVisibility: !!data.name ? 'ALIAS' : 'ANON',
email: data.email,
wantsEmails: data.wantsEmails,
amount: data.amount,
comment: data.comment,
});
'donation/UPDATE_DONATION': (state, { data }) => {
return _.merge(
{ ...state },
{
name: data.name,
nameVisibility: !!data.name ? 'ALIAS' : 'ANON',
email: data.email,
wantsEmails: data.wantsEmails,
amount: data.amount,
comment: data.comment,
},
);
},
};



export default function reducer(state = defaultState, action) {
const func = actions[action.type];
const newState = func ? func(state, action) : state;
Expand Down
6 changes: 3 additions & 3 deletions bundles/donate/donation/DonationStore.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {createSelector} from 'reselect';
import { createSelector } from 'reselect';

const getDonationState = (state) => state.donation;
const getDonationState = state => state.donation;

export const getDonation = getDonationState;

export const getDonationAmount = createSelector(
[getDonationState],
(donation) => donation.amount,
donation => donation.amount,
);
154 changes: 80 additions & 74 deletions bundles/donate/donation/components/DonationForm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';
import { connect } from 'react-redux';
import _ from 'lodash';
import cn from 'classnames';

Expand All @@ -14,30 +14,33 @@ import TextInput from '../../../uikit/TextInput';
import Incentives from '../../incentives/components/Incentives';
import * as EventDetailsStore from '../../event_details/EventDetailsStore';
import * as DonationActions from '../DonationActions';
import {EMAIL_OPTIONS, AMOUNT_PRESETS} from '../DonationConstants';
import { EMAIL_OPTIONS, AMOUNT_PRESETS } from '../DonationConstants';
import * as DonationStore from '../DonationStore';
import DonationPrizes from './DonationPrizes';

import styles from './DonationForm.mod.css';


class DonationForm extends React.PureComponent {
static propTypes = {
formErrors: PropTypes.shape({
bidsform: PropTypes.array.isRequired,
commentform: PropTypes.object.isRequired,
}).isRequired,
initialIncentives: PropTypes.arrayOf(PropTypes.shape({
bid: PropTypes.number, // will be null if the bid closed while we were filling it out
amount: PropTypes.string.isRequired,
customoptionname: PropTypes.string.isRequired,
}).isRequired).isRequired,
prizes: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
description: PropTypes.string,
minimumbid: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}).isRequired).isRequired,
initialIncentives: PropTypes.arrayOf(
PropTypes.shape({
bid: PropTypes.number, // will be null if the bid closed while we were filling it out
amount: PropTypes.string.isRequired,
customoptionname: PropTypes.string.isRequired,
}).isRequired,
).isRequired,
prizes: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
description: PropTypes.string,
minimumbid: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}).isRequired,
).isRequired,
csrfToken: PropTypes.string,
onSubmit: PropTypes.func,
};
Expand All @@ -52,24 +55,17 @@ class DonationForm extends React.PureComponent {
};

sumIncentives_() {
return this.state.currentIncentives.reduce((sum, ci) => ci.bid ? sum + (+ci.amount) : 0, 0);
return this.state.currentIncentives.reduce((sum, ci) => (ci.bid ? sum + +ci.amount : 0), 0);
}

updateDonation = (fields={}) => {
const {dispatch} = this.props;
updateDonation = (fields = {}) => {
const { dispatch } = this.props;
dispatch(DonationActions.updateDonation(fields));
}
};

cannotSubmit_() {
const {
amount,
currentIncentives,
showIncentives,
} = this.state;
const {
minimumDonation,
incentives,
} = this.props;
const { amount, currentIncentives, showIncentives } = this.state;
const { minimumDonation, incentives } = this.props;
if (currentIncentives.length > 10) {
return 'Too many incentives.';
}
Expand All @@ -82,27 +78,31 @@ class DonationForm extends React.PureComponent {
if (amount < minimumDonation) {
return 'Donation amount below minimum.';
}
if (currentIncentives.some(ci => {
const incentive = incentives.find(i => i.id === ci.bid);
return incentive && incentive.maxlength && ci.customoptionname.length > incentive.maxlength;
})) {
if (
currentIncentives.some(ci => {
const incentive = incentives.find(i => i.id === ci.bid);
return incentive && incentive.maxlength && ci.customoptionname.length > incentive.maxlength;
})
) {
return 'Suggestion is too long.';
}
return null;
}

render() {
const {formErrors, prizes, incentives, eventDetails, donation, csrfToken, onSubmit} = this.props;
const {showIncentives} = this.state;
const {receiverName, donateUrl, prizesUrl, rulesUrl, minimumDonation, maximumDonation, step} = eventDetails;
const {name, nameVisibility, email, wantsEmails, amount, comment} = donation;
const { formErrors, prizes, incentives, eventDetails, donation, csrfToken, onSubmit } = this.props;
const { showIncentives } = this.state;
const { receiverName, donateUrl, prizesUrl, rulesUrl, minimumDonation, maximumDonation, step } = eventDetails;
const { name, nameVisibility, email, wantsEmails, amount, comment } = donation;

// TODO: show more form errors
const cannotSubmit = this.cannotSubmit_();

return (
<form className={styles.donationForm} action={donateUrl} method="post" onSubmit={onSubmit}>
<Header size={Header.Sizes.H1} marginless>Thank You For Your Donation</Header>
<Header size={Header.Sizes.H1} marginless>
Thank You For Your Donation
</Header>
<Text size={Text.Sizes.SIZE_16}>100% of your donation goes directly to {receiverName}.</Text>

<section className={styles.section}>
Expand All @@ -112,7 +112,7 @@ class DonationForm extends React.PureComponent {
label="Preferred Name/Alias"
hint="Leave blank to donate anonymously"
size={TextInput.Sizes.LARGE}
onChange={(name) => this.updateDonation({name})}
onChange={name => this.updateDonation({ name })}
maxLength={32}
autoFocus
/>
Expand All @@ -122,45 +122,55 @@ class DonationForm extends React.PureComponent {
label="Email Address"
hint={
<React.Fragment>
Click <Anchor href='https://gamesdonequick.com/privacy/' external newTab>here</Anchor> for our privacy policy
Click{' '}
<Anchor href="https://gamesdonequick.com/privacy/" external newTab>
here
</Anchor>{' '}
for our privacy policy
</React.Fragment>
}
size={TextInput.Sizes.LARGE}
type={TextInput.Types.EMAIL}
onChange={(email) => this.updateDonation({email})}
onChange={email => this.updateDonation({ email })}
/>

<Text size={Text.Sizes.SIZE_16} marginless>Do you want to receive emails from {receiverName}?</Text>
<Text size={Text.Sizes.SIZE_16} marginless>
Do you want to receive emails from {receiverName}?
</Text>
<div className={styles.emailButtons}>
<RadioGroup
className={styles.emailOptin}
options={EMAIL_OPTIONS}
value={wantsEmails}
onChange={(value) => this.updateDonation({wantsEmails: value})}
onChange={value => this.updateDonation({ wantsEmails: value })}
/>
</div>

<TextInput
name="amount"
value={amount || ""}
value={amount || ''}
label="Amount"
leader="$"
placeholder="0.00"
hint={<React.Fragment>Minimum donation is <strong>{CurrencyUtils.asCurrency(minimumDonation)}</strong></React.Fragment>}
hint={
<React.Fragment>
Minimum donation is <strong>{CurrencyUtils.asCurrency(minimumDonation)}</strong>
</React.Fragment>
}
size={TextInput.Sizes.LARGE}
type={TextInput.Types.NUMBER}
onChange={(amount) => this.updateDonation({amount})}
onChange={amount => this.updateDonation({ amount })}
step={step}
min={minimumDonation}
max={maximumDonation}
/>
<div className={styles.amountPresets}>
{AMOUNT_PRESETS.map((amountPreset) => (
{AMOUNT_PRESETS.map(amountPreset => (
<Button
className={styles.amountPreset}
key={amountPreset}
look={Button.Looks.OUTLINED}
onClick={() => this.updateDonation({amount: amountPreset})}>
className={styles.amountPreset}
key={amountPreset}
look={Button.Looks.OUTLINED}
onClick={() => this.updateDonation({ amount: amountPreset })}>
${amountPreset}
</Button>
))}
Expand All @@ -173,54 +183,50 @@ class DonationForm extends React.PureComponent {
placeholder="Enter Comment Here"
hint="Please refrain from offensive language or hurtful remarks. All donation comments are screened and will be removed from the website if deemed unacceptable."
multiline
onChange={(comment) => this.updateDonation({comment})}
onChange={comment => this.updateDonation({ comment })}
maxLength={5000}
rows={5}
/>
</section>

{ prizes.length > 0 &&
{prizes.length > 0 && (
<section className={styles.section}>
<DonationPrizes prizes={prizes} prizesURL={prizesUrl} rulesURL={rulesUrl} />
</section>
}
)}

<section className={styles.section}>
<Header size={Header.Sizes.H3}>Incentives</Header>
<Text>Donation incentives can be used to add bonus runs to the schedule and influence choices by runners. Would you like to put your donation towards an incentive?</Text>
{ showIncentives
? <Incentives
className={styles.incentives}
step={step}
total={(amount || 0) - this.sumIncentives_()}
/>
: <Button
disabled={showIncentives}
look={Button.Looks.OUTLINED}
fullwidth
onClick={() => this.setState({showIncentives: true})}>
Add Incentives
</Button>
}
<Text>
Donation incentives can be used to add bonus runs to the schedule and influence choices by runners. Would
you like to put your donation towards an incentive?
</Text>
{showIncentives ? (
<Incentives className={styles.incentives} step={step} total={(amount || 0) - this.sumIncentives_()} />
) : (
<Button
disabled={showIncentives}
look={Button.Looks.OUTLINED}
fullwidth
onClick={() => this.setState({ showIncentives: true })}>
Add Incentives
</Button>
)}
</section>

<section className={styles.section}>
<Header size={Header.Sizes.H3}>Donate!</Header>
{cannotSubmit && <Text>{cannotSubmit}</Text>}
<Button
size={Button.Sizes.LARGE}
disabled={cannotSubmit}
fullwidth
type="submit">
<Button size={Button.Sizes.LARGE} disabled={cannotSubmit} fullwidth type="submit">
Finish
</Button>
</section>
</form>
);
}
};
}

const mapStateToProps = (state) => {
const mapStateToProps = state => {
return {
eventDetails: EventDetailsStore.getEventDetails(state),
donation: DonationStore.getDonation(state),
Expand Down
Loading

0 comments on commit d57f11e

Please sign in to comment.