diff --git a/src/api/call-blocking.js b/src/api/call-blocking.js index f4bd86cc..7c5a292a 100644 --- a/src/api/call-blocking.js +++ b/src/api/call-blocking.js @@ -1,13 +1,20 @@ import _ from 'lodash'; -import { enableBlockIn, disableBlockIn, - getPreferences, addToBlockInList, - editBlockInList, removeFromBlockInList, - enableBlockOut, disableBlockOut, - addToBlockOutList, editBlockOutList, +import { + enableBlockIn, + disableBlockIn, + getPreferences, + addToBlockInList, + editBlockInList, + removeFromBlockInList, + enableBlockOut, + disableBlockOut, + addToBlockOutList, + editBlockOutList, removeFromBlockOutList, - enablePrivacy, disablePrivacy + enablePrivacy, + disablePrivacy } from './subscriber'; export function enableIncomingCallBlocking(id) { @@ -133,9 +140,7 @@ export function disablePrivacyCallBlocking(id) { export function getPrivacyCallBlocking(id) { return new Promise((resolve, reject)=>{ getPreferences(id).then((result)=>{ - resolve({ - enabled: result.clir - }); + resolve(result.clir); }).catch((err)=>{ reject(err); }); diff --git a/src/components/pages/CallBlocking/Privacy.vue b/src/components/pages/CallBlocking/Privacy.vue index 807f00ca..7d9c0da5 100644 --- a/src/components/pages/CallBlocking/Privacy.vue +++ b/src/components/pages/CallBlocking/Privacy.vue @@ -1,45 +1,106 @@ diff --git a/src/locales/en.json b/src/locales/en.json index 57f250f4..f9308b8b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -318,6 +318,12 @@ "keyTypePrivate": "Private", "filterPhoneModel": "Filter by phone model" }, + "callBlocking": { + "privacyEnabledToast": "Your number is hidden to the callee", + "privacyEnabledLabel": "Your number is hidden to the callee", + "privacyDisabledToast": "Your number is visible to the callee", + "privacyDisabledLabel": "Your number is visible to the callee" + }, "communication": { "sendFax": "Send Fax", "quality": { diff --git a/src/store/call-blocking.js b/src/store/call-blocking.js index fcab5efc..3528a2ee 100644 --- a/src/store/call-blocking.js +++ b/src/store/call-blocking.js @@ -1,6 +1,8 @@ 'use strict'; -import { enableIncomingCallBlocking, +import { RequestState } from './common' +import { + enableIncomingCallBlocking, disableIncomingCallBlocking, getIncomingCallBlocking, addNumberToIncomingList, @@ -12,10 +14,11 @@ import { enableIncomingCallBlocking, addNumberToOutgoingList, editNumberFromOutgoingList, removeNumberFromOutgoingList, - enablePrivacyCallBlocking, - disablePrivacyCallBlocking, getPrivacyCallBlocking } from '../api/call-blocking'; +import { + setPrivacy +} from '../api/subscriber'; export default { namespaced: true, @@ -24,9 +27,28 @@ export default { incomingList: [], outgoingEnabled: false, outgoingList: [], - privacyEnabled: false + privacy: false, + privacyLoadingState: RequestState.initiated, + privacyUpdated: false, + privacyError: null + }, + getters: { + privacy(state) { + return state.privacy; + }, + privacyError(state) { + return state.privacyError; + }, + privacyUpdated(state) { + return state.privacyUpdated; + }, + privacyLoadingState(state) { + return state.privacyUpdated; + }, + privacyLoading(state) { + return state.privacyLoadingState === RequestState.requesting; + } }, - getters: {}, mutations: { enableIncoming (state) { state.incomingEnabled = true; @@ -38,15 +60,6 @@ export default { state.incomingEnabled = options.enabled; state.incomingList = options.list; }, - enablePrivacy (state) { - state.privacyEnabled = true; - }, - disablePrivacy (state) { - state.privacyEnabled= false; - }, - loadPrivacy(state, options) { - state.privacyEnabled = options.enabled; - }, enableOutgoing (state) { state.outgoingEnabled = true; }, @@ -56,6 +69,31 @@ export default { loadOutgoing(state, options) { state.outgoingEnabled = options.enabled; state.outgoingList = options.list; + }, + privacyLoading(state) { + state.privacyLoadingState = RequestState.requesting; + state.privacyError = null; + state.privacyUpdated = false; + }, + privacyLoaded(state, privacy) { + state.privacy = privacy; + state.privacyLoadingState = RequestState.succeeded; + state.privacyError = null; + }, + privacyLoadingFailed(state, error) { + state.privacyLoadingState = RequestState.failed; + state.privacyError = error; + }, + privacyUpdated(state, privacy) { + state.privacy = privacy; + state.privacyLoadingState = RequestState.succeeded; + state.privacyError = null; + state.privacyUpdated = true; + }, + privacyUpdatingFailed(state, error) { + state.privacyLoadingState = RequestState.failed; + state.privacyError = error; + state.privacyUpdated = true; } }, actions: { @@ -185,34 +223,20 @@ export default { }); }); }, - togglePrivacy(context, enabled) { - return new Promise((resolve, reject)=>{ - if(enabled) { - enablePrivacyCallBlocking(localStorage.getItem('subscriberId')).then(()=>{ - context.commit('enablePrivacy'); - resolve(); - }).catch((err)=>{ - reject(err); - }); - } - else { - disablePrivacyCallBlocking(localStorage.getItem('subscriberId')).then(()=>{ - context.commit('disablePrivacy'); - resolve(); - }).catch((err)=>{ - reject(err); - }); - } + updatePrivacy(context, privacy) { + context.commit('privacyLoading'); + setPrivacy(localStorage.getItem('subscriberId'), privacy).then(()=>{ + context.commit('privacyUpdated', privacy); + }).catch((err)=>{ + context.commit('privacyUpdatingFailed', err.message); }); }, loadPrivacy(context) { - return new Promise((resolve, reject)=>{ - getPrivacyCallBlocking(localStorage.getItem('subscriberId')).then((result)=>{ - context.commit('loadPrivacy', result); - resolve(); - }).catch((err)=>{ - reject(err); - }); + context.commit('privacyLoading'); + getPrivacyCallBlocking(localStorage.getItem('subscriberId')).then((privacy)=>{ + context.commit('privacyLoaded', privacy); + }).catch((err)=>{ + context.commit('privacyLoadingFailed', err.message); }); } } diff --git a/t/store/call-blocking.js b/t/store/call-blocking.js index cf6da492..a1be6e9e 100644 --- a/t/store/call-blocking.js +++ b/t/store/call-blocking.js @@ -62,12 +62,4 @@ describe('CallBlocking', function(){ assert.deepEqual(state.outgoingList, list); }); }); - - it('should enable/disable privacy call blocking', ()=>{ - var state = {}; - CallBlockingModule.mutations.enablePrivacy(state); - assert.equal(state.privacyEnabled, true); - CallBlockingModule.mutations.disablePrivacy(state); - assert.equal(state.privacyEnabled, false); - }); });