Skip to content

Commit

Permalink
feat(dedicated.account): add phone typeand sms consent to account edi…
Browse files Browse the repository at this point in the history
…tion

ref: MANAGER-11435

Signed-off-by: Jacques Larique <[email protected]>
  • Loading branch information
Jacques Larique committed Jul 27, 2023
1 parent 5957ec5 commit dbc33ee
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ export default class NewAccountFormFieldController {
});
}

// reset sms consent value when phone type is no longer 'mobile'
if (this.rule.fieldName === 'smsConsent') {
this.$scope.$on('account.smsConsent.reset', () => {
// switch value to false only if it is true
if (this.value) {
this.onChange();
this.value = false;
}
});
}

// handle special phone prefix case
if (this.getFieldType() === 'phone') {
this.$scope.$watch(
Expand Down Expand Up @@ -218,6 +229,9 @@ export default class NewAccountFormFieldController {
if (this.rule.fieldType) {
return this.rule.fieldType;
}
if ((this.rule.fieldName || '') === this.FIELD_NAME_LIST.phoneType) {
return 'radio';
}
if (this.rule.in) {
return 'select';
}
Expand Down Expand Up @@ -268,8 +282,11 @@ export default class NewAccountFormFieldController {
};
});

result = this.$filter('orderBy')(result, 'translated', false, (a, b) =>
String(a.value).localeCompare(String(b.value)),
result = this.$filter('orderBy')(
result,
'translated',
this.rule.fieldName === this.FIELD_NAME_LIST.phoneType,
(a, b) => String(a.value).localeCompare(String(b.value)),
);

// if there is only a single value, auto select it
Expand Down Expand Up @@ -347,6 +364,11 @@ export default class NewAccountFormFieldController {
return ['phone', 'fax'].includes(this.rule.fieldName);
}

shouldDisplayLabel() {
const type = this.getFieldType();
return type !== 'checkbox' && type !== 'radio';
}

// callback for when model changed
onChange() {
let { value } = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
'oui-field_error': $ctrl.isInvalid()
}"
>
<div
class="oui-field__header"
data-ng-if="$ctrl.getFieldType() !== 'checkbox'"
>
<div class="oui-field__header" data-ng-if="$ctrl.shouldDisplayLabel()">
<label
class="oui-field__label"
data-ng-if="$ctrl.rule.fieldName !== 'area'"
Expand Down Expand Up @@ -162,12 +159,33 @@
data-ng-blur="$ctrl.focused = false"
data-ng-pattern="$ctrl.inputValidator"
data-ng-required="$ctrl.rule.mandatory"
data-disabled="$ctrl.rule.disabled()"
>
<span
data-translate="{{ 'signup_field_' + $ctrl.rule.displayFieldName | translate }} {{ !$ctrl.rule.mandatory ? 'signup_not_mandatory_field' : '' | translate }}"
></span>
</oui-checkbox>

<!-- RADIO INPUT -->
<oui-radio-group
data-ng-if="$ctrl.getFieldType() === 'radio'"
data-ng-attr-id="{{ 'ovh_field_' + $ctrl.rule.fieldName }}"
data-ng-attr-name="{{ 'ovh_field_' + $ctrl.rule.fieldName }}"
data-model="$ctrl.value"
data-ng-required="$ctrl.rule.mandatory"
data-on-change="$ctrl.onChange()"
data-ng-focus="$ctrl.focused = true"
data-ng-blur="$ctrl.focused = false"
>
<oui-radio
data-ng-repeat="value in $ctrl.getTranslatedEnums()"
data-value="value.key"
inline
>
<span data-ng-bind="value.translated"></span>
</oui-radio>
</oui-radio-group>

<p
class="help-block text-danger"
role="alert"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const READY_ONLY_RULES_PARAMS = [
'state',
'commercialCommunicationsApproval',
'managerLanguage',
'smsConsent',
];

export const READY_ONLY_PARAMS = [
Expand Down Expand Up @@ -72,8 +73,10 @@ export const SECTIONS = {
'city',
'zip',
'area',
'phoneType',
'phoneCountry',
'phone',
'smsConsent',
'fax',
],
language: ['language', 'managerLanguage'],
Expand Down Expand Up @@ -111,8 +114,10 @@ export const FIELD_NAME_LIST = {
address: 'address',
zip: 'zip',
city: 'city',
phoneType: 'phoneType',
phoneCountry: 'phoneCountry',
phone: 'phone',
smsConsent: 'smsConsent',
fax: 'fax',
language: 'language',
managerLanguage: 'managerLanguage',
Expand Down Expand Up @@ -370,6 +375,8 @@ export const PHONE_PREFIX = {
ZW: '263',
};

export const FIELD_WITHOUT_MARGIN_BOTTOM = ['email', 'phoneType', 'phone'];

export default {
ENUM_TRANSLATION_RULES,
MODEL_DEBOUNCE_DELAY,
Expand All @@ -381,4 +388,5 @@ export default {
PHONE_PREFIX,
CONSENT_MARKETING_EMAIL_NAME,
FIELD_NAME_LIST,
FIELD_WITHOUT_MARGIN_BOTTOM,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
GST_SUBSIDIARIES,
SECTIONS,
FIELD_NAME_LIST,
FIELD_WITHOUT_MARGIN_BOTTOM,
} from './new-account-form-component.constants';

export default class NewAccountFormController {
Expand All @@ -27,6 +28,7 @@ export default class NewAccountFormController {
Alerter,
$translate,
$anchorScroll,
$scope,
) {
this.$q = $q;
this.$http = $http;
Expand All @@ -46,6 +48,7 @@ export default class NewAccountFormController {
this.originalManagerLanguage = coreConfig.getUserLocale();
this.user = coreConfig.getUser();
this.$anchorScroll = $anchorScroll;
this.$scope = $scope;
this.SECTIONS = SECTIONS;
}

Expand All @@ -55,6 +58,7 @@ export default class NewAccountFormController {
this.originalModel = angular.copy(this.model);

this.consentDecision = null;
this.smsConsentDecision = null;

return this.$q
.all({
Expand Down Expand Up @@ -109,14 +113,22 @@ export default class NewAccountFormController {

params.action = this.action;

return this.userAccountServiceInfos
.fetchConsentDecision(CONSENT_MARKETING_EMAIL_NAME)
.then((fetchedConsentDecision) => {
this.consentDecision = fetchedConsentDecision.value || false;
return this.$q
.all({
email: this.userAccountServiceInfos.fetchConsentDecision(
CONSENT_MARKETING_EMAIL_NAME,
),
sms: this.userAccountServiceInfos.fetchMarketingConsentDecision(),
})
.then(({ email, sms }) => {
this.consentDecision = email.value || false;
this.smsConsentDecision =
Object.keys(sms.sms).some((key) => sms.sms[key]) || false;
})
.then(() => this.userAccountServiceInfos.postRules(params))
.then((result) => {
let emailFieldIndex;
let phoneFieldIndex;

// hide rules that are not editable
const rules = result.map((rule, index) => {
Expand All @@ -130,7 +142,11 @@ export default class NewAccountFormController {
editedRule.hasBottomMargin = this.coreConfig.isRegion('US');
} else {
editedRule.readonly = this.readonly.includes(editedRule.fieldName);
editedRule.hasBottomMargin = true;
editedRule.hasBottomMargin =
FIELD_WITHOUT_MARGIN_BOTTOM.indexOf(editedRule.fieldName) === -1;
if (editedRule.fieldName === 'phone') {
phoneFieldIndex = index;
}
}

return editedRule;
Expand All @@ -156,6 +172,19 @@ export default class NewAccountFormController {
examples: null,
hasBottomMargin: true,
});
rules.splice(phoneFieldIndex + 1, 0, {
in: null,
mandatory: false,
defaultValue: null,
initialValue: this.smsConsentDecision,
fieldName: FIELD_NAME_LIST.smsConsent,
fieldType: 'checkbox',
regularExpression: null,
prefix: null,
examples: null,
hasBottomMargin: true,
disabled: () => this.model.phoneType !== 'mobile',
});
}
return rules;
})
Expand Down Expand Up @@ -297,25 +326,37 @@ export default class NewAccountFormController {
);
}

if (
this.originalModel.commercialCommunicationsApproval !==
this.model.commercialCommunicationsApproval &&
!this.coreConfig.isRegion('US')
) {
promise = promise
.then(() =>
if (!this.coreConfig.isRegion('US')) {
const consentRequests = [];
if (
this.originalModel.commercialCommunicationsApproval !==
this.model.commercialCommunicationsApproval
) {
consentRequests.push(
this.userAccountServiceInfos.updateConsentDecision(
CONSENT_MARKETING_EMAIL_NAME,
this.model.commercialCommunicationsApproval || false,
),
)
.then(
() =>
this.$timeout(
angular.noop,
3000,
) /* add some delay for task creation */,
);
}
if (this.originalModel.smsConsent !== this.model.smsConsent) {
consentRequests.push(
this.userAccountServiceInfos.updateSmsMarketingConsentDecision(
this.model.smsConsent || false,
),
);
}
if (consentRequests.length > 0) {
promise = promise
.then(() => this.$q.all(consentRequests))
.then(
() =>
this.$timeout(
angular.noop,
3000,
) /* add some delay for task creation */,
);
}
}

return promise
Expand Down Expand Up @@ -409,6 +450,11 @@ export default class NewAccountFormController {
// update model
this.model[rule.fieldName] = value;

// if phone type is set to a value other than 'mobile' we reset the sms consent value
if (rule.fieldName === 'phoneType' && value !== 'mobile') {
this.$scope.$broadcast('account.smsConsent.reset');
}

return this.updateRules();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"signup_field_timezone": "Fuseau horaire",
"signup_field_customerCode": "Code client",
"signup_field_italianSDI": "Numéro SDI",
"signup_field_smsConsent": "J'accepte de recevoir des SMS relatifs aux nouveautés et offres commerciales d'OVHcloud",
"signup_field_required_error": "Veuillez compléter ce champ.",
"signup_field_pattern_error": "Veuillez saisir un format valide.",
"signup_enum_legalform_association": "Association",
Expand Down Expand Up @@ -759,5 +760,7 @@
"signup_enum_IN_area_IN-TR": "Tripura",
"signup_enum_IN_area_IN-UP": "Uttar Pradesh",
"signup_enum_IN_area_IN-UT": "Uttarakhand",
"signup_enum_IN_area_IN-WB": "West Bengal"
"signup_enum_IN_area_IN-WB": "West Bengal",
"signup_enum_phoneType_landline": "Fixe",
"signup_enum_phoneType_mobile": "Mobile"
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,27 @@ export default class UserAccountInfosService {
});
}

fetchMarketingConsentDecision() {
return this.$http.get('/me/marketing').then((response) => {
if (response.status < 300) {
return response.data;
}
return this.$q.reject(response);
});
}

updateSmsMarketingConsentDecision(value) {
return this.$http.put('/me/marketing', {
denyAll: false,
sms: {
events: value,
newProductRecommendation: value,
newsletter: value,
offerAndDiscount: value,
},
});
}

fetchConsentDecision(campaignName) {
return this.$http
.get(
Expand Down

0 comments on commit dbc33ee

Please sign in to comment.