Skip to content

Commit c211c50

Browse files
committed
fix(pci.projects.new): take consideration vouchers
1 parent 0934e40 commit c211c50

File tree

12 files changed

+63
-69
lines changed

12 files changed

+63
-69
lines changed

packages/manager/apps/public-cloud/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@ovh-ux/ng-ovh-cloud-universe-components": "^1.3.0-alpha.3",
2828
"@ovh-ux/ng-ovh-contacts": "^1.0.1",
2929
"@ovh-ux/ng-ovh-otrs": "^7.0.1",
30-
"@ovh-ux/ng-ovh-payment-method": "^2.1.1",
30+
"@ovh-ux/ng-ovh-payment-method": "^3.0.0",
3131
"@ovh-ux/ng-ovh-proxy-request": "^1.0.0-beta.0",
3232
"@ovh-ux/ng-ovh-responsive-popover": "^5.0.0-beta.0",
3333
"@ovh-ux/ng-ovh-sso-auth": "^4.0.0",
@@ -68,4 +68,4 @@
6868
"webpack": "^4.30.0",
6969
"webpack-merge": "^4.1.4"
7070
}
71-
}
71+
}

packages/manager/modules/pci/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"@ovh-ux/ng-ovh-api-wrappers": "^3.0.0",
4343
"@ovh-ux/ng-ovh-cloud-universe-components": "^1.3.0-alpha.3",
4444
"@ovh-ux/ng-ovh-otrs": "^7.0.0",
45-
"@ovh-ux/ng-ovh-payment-method": "^2.2.0",
45+
"@ovh-ux/ng-ovh-payment-method": "^3.0.0",
4646
"@ovh-ux/ng-ovh-proxy-request": "^1.0.0-beta.0",
4747
"@ovh-ux/ng-ovh-responsive-popover": "^5.0.0-beta.0",
4848
"@ovh-ux/ng-ovh-swimming-poll": "^4.0.0",
@@ -69,4 +69,4 @@
6969
"ovh-ui-kit": "^2.29.0",
7070
"ovh-ui-kit-bs": "^2.1.1"
7171
}
72-
}
72+
}

packages/manager/modules/pci/src/projects/new/new.controller.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,17 @@ export default class PciProjectNewCtrl {
145145
this.loading.creating = true;
146146

147147
const hasCredit = this.paymentModel.mode === 'credits' && this.paymentModel.credit.value;
148+
const hasVoucher = this.paymentModel.voucher.valid && this.paymentModel.voucher.value;
148149
const createParams = {
149150
description: this.descriptionModel.name,
150151
};
151152

152-
if (hasCredit) {
153+
if (hasVoucher) {
154+
createParams.voucher = this.paymentModel.voucher.value;
155+
} else if (hasCredit) {
153156
createParams.credit = this.paymentModel.credit.value;
154157
} else if (this.newProjectInfo.order
155-
&& (!this.paymentStatus || ['success', 'accepted'].includes(this.paymentStatus))) {
158+
&& (!this.paymentStatus || ['success', 'accepted'].includes(this.paymentStatus))) {
156159
createParams.credit = this.newProjectInfo.order.value;
157160
}
158161

@@ -246,7 +249,10 @@ export default class PciProjectNewCtrl {
246249

247250
// if default payment or credit amount - create project
248251
if (this.paymentModel.defaultPaymentMethod
249-
|| (this.paymentModel.mode === 'credits' && this.paymentModel.credit.value)) {
252+
|| (this.paymentModel.mode === 'credits' && this.paymentModel.credit.value)
253+
|| (this.paymentModel.voucher.valid
254+
&& this.paymentModel.voucher.paymentMeanRequired === false)
255+
) {
250256
return this.createProject();
251257
}
252258

packages/manager/modules/pci/src/projects/new/new.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="pci-projects-new h-100 overflow-auto">
22
<div class="container-fluid h-100">
33
<div class="row minh-100 justify-content-md-center">
4-
<div class="col-md-7 p-4 p-md-5 bg-white minh-100">
4+
<div class="col-lg-7 p-4 p-md-5 bg-white minh-100">
55
<div class="p-0 p-md-5">
66
<!-- progress -->
77
<div class="oui-progress-tracker mx-auto mb-5">

packages/manager/modules/pci/src/projects/new/new.routing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export default /* @ngInject */ ($stateProvider) => {
120120
voucher: {
121121
valid: false,
122122
value: null,
123+
paymentMeanRequired: null,
123124
},
124125
defaultPaymentMethod: null,
125126
paymentType: null,

packages/manager/modules/pci/src/projects/new/payment/add/add.component.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export default {
66
controller,
77
bindings: {
88
onLoaded: '&',
9-
onSelectedPaymentTypeChange: '&',
9+
selectedPaymentType: '=',
1010
},
1111
};
Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import isFunction from 'lodash/isFunction';
2-
31
export default class PciProjectsNewPaymentAddCtrl {
42
/* @ngInject */
53
constructor($translate, CucCloudMessage, ovhPaymentMethod) {
64
// dependencies injections
75
this.$translate = $translate;
86
this.CucCloudMessage = CucCloudMessage;
97
this.ovhPaymentMethod = ovhPaymentMethod;
10-
11-
this.selectedPaymentType = null;
128
}
139

1410
/* =============================
@@ -20,19 +16,5 @@ export default class PciProjectsNewPaymentAddCtrl {
2016
.error(this.$translate.instant('pci_projects_new_payment_add_load_error'));
2117
}
2218

23-
onPaymentTypeChange(paymentType) {
24-
this.selectedPaymentType = paymentType;
25-
26-
// if it's a function reference ...
27-
// otherwise the call will be made passing an Object Literal
28-
// when testing if the callback function is a function ref or not
29-
if (isFunction(this.onSelectedPaymentTypeChange({
30-
paymentType,
31-
}))) {
32-
// ... invoke it
33-
this.onSelectedPaymentTypeChange()(this.selectedPaymentType);
34-
}
35-
}
36-
3719
/* ----- End of Events ------ */
3820
}

packages/manager/modules/pci/src/projects/new/payment/add/add.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<ovh-payment-method-available-types
1414
data-on-loaded="$ctrl.onLoaded()"
1515
data-on-load-error="$ctrl.onAvailablePaymentTypesLoadError.bind($ctrl)"
16-
data-on-selected-payment-type-change="$ctrl.onPaymentTypeChange.bind($ctrl)">
16+
data-selected-payment-type="$ctrl.selectedPaymentType">
1717
</ovh-payment-method-available-types>
1818

1919
<small data-ng-switch="$ctrl.selectedPaymentType.paymentType.value"

packages/manager/modules/pci/src/projects/new/payment/payment.controller.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,20 @@ export default class PciProjectNewPaymentCtrl {
4040
.then(() => {
4141
this.voucherForm.voucher.$setValidity('voucher', true);
4242
this.step.model.voucher.valid = true;
43+
this.step.model.voucher.paymentMeanRequired = false;
44+
this.step.model.paymentType = null;
4345
})
44-
.catch(() => {
45-
this.voucherForm.voucher.$setValidity('voucher', false);
46-
this.step.model.voucher.valid = false;
46+
.catch((error) => {
47+
// @TODO => remove this test when API will be ready
48+
if (error.status === 403 && error.data.message === 'Please register a payment method') { //
49+
this.voucherForm.voucher.$setValidity('voucher', true);
50+
this.step.model.voucher.valid = true;
51+
this.step.model.voucher.paymentMeanRequired = true;
52+
} else {
53+
this.voucherForm.voucher.$setValidity('voucher', false);
54+
this.step.model.voucher.valid = false;
55+
this.step.model.voucher.paymentMeanRequired = null;
56+
}
4757
})
4858
.finally(() => {
4959
this.step.loading.voucher = false;

packages/manager/modules/pci/src/projects/new/payment/payment.html

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<pci-project-new-payment-add
2626
data-ng-if="!$ctrl.step.model.defaultPaymentMethod"
2727
data-on-loaded="$ctrl.step.loading.paymentTypes = false"
28-
data-on-selected-payment-type-change="$ctrl.onPaymentAddTypeChange.bind($ctrl)">
28+
data-selected-payment-type="$ctrl.step.model.paymentType">
2929
</pci-project-new-payment-add>
3030
</div>
3131

@@ -76,17 +76,28 @@
7676
name="$ctrl.voucherForm"
7777
data-ng-if="$ctrl.displayVoucher && !$ctrl.step.model.voucher.valid"
7878
data-ng-submit="$ctrl.onVoucherFormSubmit()">
79-
<oui-field
80-
data-label="{{ :: 'pci_project_new_payment_enter_voucher' | translate }}"
81-
data-size="s"
82-
data-error-messages="{ voucher: ('pci_project_new_payment_invalid_voucher' | translate) }">
83-
<input
84-
class="oui-input"
85-
type="text"
86-
id="voucher"
87-
name="voucher"
88-
data-ng-model="$ctrl.step.model.voucher.value" />
89-
</oui-field>
79+
<div class="oui-field"
80+
data-ng-class="{ 'oui-field_error': !$ctrl.voucherForm.voucher.$pristine && $ctrl.voucherForm.voucher.$invalid && !$ctrl.step.loading.voucher }">
81+
<label for="text-5" class="oui-field__label oui-label"
82+
data-translate="pci_project_new_payment_enter_voucher">
83+
</label>
84+
<div class="oui-field__control oui-field__control_s">
85+
<input
86+
class="oui-input"
87+
type="text"
88+
id="voucher"
89+
name="voucher"
90+
data-ng-model="$ctrl.step.model.voucher.value" />
91+
</div>
92+
<div class="oui-field__error"
93+
data-ng-if="!$ctrl.voucherForm.voucher.$pristine && $ctrl.voucherForm.voucher.$invalid && !$ctrl.step.loading.voucher">
94+
<span role="alert"
95+
data-ng-if="$ctrl.voucherForm.voucher.$error.voucher">
96+
<span class="oui-icon oui-icon-error" aria-hidden="true"></span>
97+
<span data-translate="pci_project_new_payment_invalid_voucher"></span>
98+
</span>
99+
</div>
100+
</div>
90101
<button type="submit" class="oui-button oui-button_link oui-button_icon-right"
91102
data-ng-disabled="!$ctrl.step.model.voucher.value || $ctrl.step.loading.voucher">
92103
<span data-translate="pci_project_new_payment_add_voucher"></span>

0 commit comments

Comments
 (0)