Merge pull request #471 from sharetribe/require-min-stripe-account-age

Require min age from a Stripe account
This commit is contained in:
Kimmo Puputti 2017-10-06 09:45:37 +03:00 committed by GitHub
commit ccd99f284c
4 changed files with 26 additions and 2 deletions

View file

@ -8,6 +8,8 @@ const formName = 'Styleguide.BirthdayInput.Form';
const FormComponent = () => {
const required = validators.required('A valid date is required');
const minAge = 18;
const minAgeRequired = validators.ageAtLeast(`Age should be at least ${minAge}`, minAge);
return (
<form>
<BirthdayInputField
@ -15,7 +17,7 @@ const FormComponent = () => {
name="birthday"
label="Date of birth"
format={null}
validate={required}
validate={[required, minAgeRequired]}
/>
</form>
);

View file

@ -17,6 +17,8 @@ import * as validators from '../../util/validators';
import css from './PayoutDetailsForm.css';
const MIN_STRIPE_ACCOUNT_AGE = 18;
const supportedCountries = config.stripe.supportedCountries.map(c => c.code);
export const stripeCountryConfigs = countryCode => {
@ -78,6 +80,17 @@ const PayoutDetailsFormComponent = props => {
id: 'PayoutDetailsForm.birthdayRequired',
})
);
const birthdayMinAge = validators.ageAtLeast(
intl.formatMessage(
{
id: 'PayoutDetailsForm.birthdayMinAge',
},
{
minAge: MIN_STRIPE_ACCOUNT_AGE,
}
),
MIN_STRIPE_ACCOUNT_AGE
);
const countryLabel = intl.formatMessage({ id: 'PayoutDetailsForm.countryLabel' });
const countryPlaceholder = intl.formatMessage({ id: 'PayoutDetailsForm.countryPlaceholder' });
@ -218,7 +231,7 @@ const PayoutDetailsFormComponent = props => {
labelForMonth={birthdayLabelMonth}
labelForYear={birthdayLabelYear}
format={null}
validate={birthdayRequired}
validate={[birthdayRequired, birthdayMinAge]}
/>
</div>

View file

@ -317,6 +317,7 @@
"PayoutDetailsForm.birthdayLabel": "Birth date",
"PayoutDetailsForm.birthdayLabelMonth": "Month",
"PayoutDetailsForm.birthdayLabelYear": "Year",
"PayoutDetailsForm.birthdayMinAge": "You should be at least {minAge} years old.",
"PayoutDetailsForm.birthdayMonthPlaceholder": "mm",
"PayoutDetailsForm.birthdayRequired": "Birthday is required and must be a valid date.",
"PayoutDetailsForm.birthdayYearPlaceholder": "yyyy",

View file

@ -1,3 +1,4 @@
import moment from 'moment';
import { types } from 'sharetribe-sdk';
const { LatLng } = types;
@ -68,3 +69,10 @@ export const emailFormatValid = message =>
value => {
return value && EMAIL_RE.test(value) ? VALID : message;
};
export const ageAtLeast = (message, minYears) =>
value => {
const now = moment();
const ageInYears = now.diff(moment(value), 'years', true);
return value && value instanceof Date && ageInYears >= minYears ? VALID : message;
};