Skip to content

Commit c2e68c9

Browse files
feat: add validation on initial account setup
1 parent 2504e09 commit c2e68c9

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

app/components/billing/first-plan.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,23 @@ export default Component.extend({
286286
},
287287
togglePlanDetails() {
288288
this.set('planDetailsVisible', !this.planDetailsVisible);
289-
}
289+
},
290+
validateBillingEmails(billingEmailField) {
291+
if (!billingEmailField) {
292+
return true;
293+
}
294+
295+
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
296+
const emails = billingEmailField.split(',').map(email => email.trim());
290297

298+
const invalidEmails = emails.filter(email => !emailRegex.test(email));
299+
300+
if (invalidEmails.length > 0) {
301+
const invalidEmailsList = invalidEmails.join(', ');
302+
return `The following email addresses are not valid: ${invalidEmailsList}`;
303+
}
304+
305+
return true;
306+
},
291307
}
292308
});

app/templates/components/billing/first-plan.hbs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</div>
2525

2626

27-
<div class='full-width cc-form-elem'>
27+
<div class='full-width cc-form-elem'>
2828
<form.field @label="Credit Card details"
2929
onSubmit={{perform this.createSubscription}} @required={{true}} @showRequiredMark={{true}} as |field|>
3030
<StripeCard class="cc-form-internal" @onComplete={{action "complete" }} @options={{this.options}} as |stripeError|>
@@ -38,7 +38,7 @@
3838
<div class='full-width form-elem'>
3939

4040
<form.field @label="Billing e-mail address" @value={{this.billingEmail}} @onChange={{action (mut
41-
this.billingEmail)}} @required={{true}} @validator={{form-validator form.validators.email}}
41+
this.billingEmail)}} @required={{true}} @validator={{form-validator form.validators.email action "validateBillingEmails"}}
4242
@showRequiredMark={{true}} as |field|>
4343
<field.input @type="text" />
4444
</form.field>
@@ -158,7 +158,7 @@
158158
{{#unless this.isTrial}}
159159
<p class="plan-desc">{{format-currency this.selectedPlan.startingPrice floor="true"}}{{ if this.selectedPlan.isAnnual '/annualy'
160160
'/monthly'}}</p>
161-
161+
162162
<button class=" no-button plan-details" {{action 'togglePlanDetails' }}>
163163
Plan details </button>
164164
{{#if this.planDetailsVisible}}
@@ -174,7 +174,7 @@
174174
<p class='billing-plans__box-v2--desc cnowrap' data-test-selected-plan-os="true">
175175
<SvgImage @name="stage-passed" @class="icon icon-desc" />Linux, Windows, macOS, FreeBSD
176176
</p>
177-
177+
178178
{{#if this.selectedPlan.hasOSSCreditAddons}}
179179
<p class='billing-plans__box-v2--desc' data-test-selected-plan-oss-credits="true">
180180
<SvgImage @name="stage-passed" @class="icon icon-desc" /> {{this.selectedPlan.publicCredits}} OSS Credits<span
@@ -218,7 +218,7 @@
218218
<div class="align-left font-size-s" id="first-plan-charge-info">
219219
{{#if this.isTrial}}
220220
<b class="font-bold">We will charge you $1 and refund you in 7 days</b>. This is needed to make sure your card
221-
221+
222222
is valid. By clicking on "Verify Your Account" you agree to <a href="{{this.travisTermsUrl}}" class="travis-link" target="_blank">Travis CI
223223
Terms and Privacy
224224
Policy</a>.
@@ -227,10 +227,10 @@
227227

228228
will not be able to use Travis CI features.
229229
{{else}}
230-
230+
231231
You'll be charged {{format-currency this.selectedPlan.startingPrice floor="true"}} {{ if
232232
this.selectedPlan.isAnnual 'annualy' 'monthly'}} until you cancel your subscription. Previous
233-
233+
234234
charges won't be refunded when you cancel unless it's legally required. By clicking
235235
on "{{this.getActivateButtonText}}" you agree to <a href="{{this.travisTermsUrl}}" class="travis-link" target="_blank">Travis CI Terms and Privacy
236236
Policy</a>.

0 commit comments

Comments
 (0)