Our nightly tests flagged the fact that
the feature was unstable and unrealiable.
Changes:
* Extract subscriber phonebook api and state
* Change direct use of http in the sub-phonebook
method to use the relevant method in common.js
* Simplify logic to PATCH single properties
with a unique PUT in the Phonebook entry form
* Amend getList, handleResponseError and
put to allow use with API v2 endpoints
* Amend translations and methods to replace
"phonebook" with "phonebook entry" where
necessary
Change-Id: I189d45fe426a1ded400a251d7efdfa72f76f9061
(cherry picked from commit ff40864da0)
mr14.0
parent
d8d900e1f5
commit
236b9cf8f2
@ -0,0 +1,60 @@
|
|||||||
|
import {
|
||||||
|
del,
|
||||||
|
get,
|
||||||
|
getList,
|
||||||
|
patchReplace,
|
||||||
|
post,
|
||||||
|
putMinimal
|
||||||
|
} from 'src/api/common'
|
||||||
|
|
||||||
|
export async function createPhonebook (data) {
|
||||||
|
const payload = {
|
||||||
|
name: data.name,
|
||||||
|
number: data.number,
|
||||||
|
shared: data.shared,
|
||||||
|
subscriber_id: Number(data.subscriber_id)
|
||||||
|
}
|
||||||
|
return post({
|
||||||
|
path: `api/v2/subscribers/${data.subscriber_id}/phonebook`,
|
||||||
|
body: payload
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function deleteEntry (subscriberId, entryId) {
|
||||||
|
return del({
|
||||||
|
path: `api/v2/subscribers/${subscriberId}/phonebook/${entryId}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEntryById (subscriberId, id) {
|
||||||
|
return get({
|
||||||
|
path: `api/v2/subscribers/${subscriberId}/phonebook/${id}`
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getPhonebook (options) {
|
||||||
|
return getList({
|
||||||
|
path: `api/v2/subscribers/${options.subscriber_id}/phonebook`,
|
||||||
|
params: options
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setSharedValue (subscriberId, phonebookId, value) {
|
||||||
|
return patchReplace({
|
||||||
|
path: `api/v2/subscribers/${subscriberId}/phonebook/${phonebookId}`,
|
||||||
|
fieldPath: 'shared',
|
||||||
|
value
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function updateEntry (data) {
|
||||||
|
return putMinimal({
|
||||||
|
path: `api/v2/subscribers/${data.subscriberId}/phonebook/${data.id}`,
|
||||||
|
body: {
|
||||||
|
number: data.number,
|
||||||
|
shared: data.shared,
|
||||||
|
name: data.name,
|
||||||
|
subscriber_id: Number(data.subscriberId)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
import { LIST_DEFAULT_ROWS } from 'src/api/common'
|
||||||
|
import {
|
||||||
|
createPhonebook,
|
||||||
|
deleteEntry,
|
||||||
|
getEntryById,
|
||||||
|
getPhonebook,
|
||||||
|
setSharedValue,
|
||||||
|
updateEntry
|
||||||
|
} from 'src/api/subscriber-phonebook'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
namespaced: true,
|
||||||
|
state: {
|
||||||
|
phonebookRows: [],
|
||||||
|
pagination: {
|
||||||
|
sortBy: 'id',
|
||||||
|
descending: false,
|
||||||
|
page: 1,
|
||||||
|
rowsPerPage: LIST_DEFAULT_ROWS,
|
||||||
|
rowsNumber: 0
|
||||||
|
},
|
||||||
|
numberInput: null
|
||||||
|
},
|
||||||
|
getters: {
|
||||||
|
getEntryById: (state) => (id) => {
|
||||||
|
return state.phonebookRows.find((entry) => entry.id === id)
|
||||||
|
},
|
||||||
|
getPrefilledNumber: (state) => state.numberInput,
|
||||||
|
phonebookRows: (state) => state.phonebookRows,
|
||||||
|
pagination: (state) => state.pagination
|
||||||
|
},
|
||||||
|
mutations: {
|
||||||
|
setPhonebookRows (state, rows) {
|
||||||
|
state.phonebookRows = rows
|
||||||
|
},
|
||||||
|
setPagination (state, pagination) {
|
||||||
|
state.pagination = { ...state.pagination, ...pagination }
|
||||||
|
},
|
||||||
|
setSharedValue (state, { id, value }) {
|
||||||
|
const index = state.phonebookRows.findIndex((row) => row.id === id)
|
||||||
|
if (index > -1) {
|
||||||
|
state.phonebookRows[index].shared = value
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setNumber (state, numberInput) {
|
||||||
|
state.numberInput = numberInput
|
||||||
|
}
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
async loadPhonebook ({ commit }, options) {
|
||||||
|
try {
|
||||||
|
const list = await getPhonebook({
|
||||||
|
...options
|
||||||
|
})
|
||||||
|
commit('setPhonebookRows', list.items || [])
|
||||||
|
commit('setPagination', {
|
||||||
|
page: options.page,
|
||||||
|
rowsPerPage: options.rows,
|
||||||
|
rowsNumber: list.totalCount
|
||||||
|
})
|
||||||
|
return list
|
||||||
|
} catch (err) {
|
||||||
|
commit('setPhonebookRows', [])
|
||||||
|
throw err
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async removeEntry (context, { id, subscriberId }) {
|
||||||
|
await deleteEntry(subscriberId, id)
|
||||||
|
},
|
||||||
|
async getEntry (context, { id, subscriberId }) {
|
||||||
|
const cachedEntry = context.getters.getEntryById(id)
|
||||||
|
if (cachedEntry) {
|
||||||
|
return cachedEntry
|
||||||
|
}
|
||||||
|
// Fetch from API if not in store
|
||||||
|
const response = await getEntryById(subscriberId, id)
|
||||||
|
return response
|
||||||
|
},
|
||||||
|
async createPhonebook (context, data) {
|
||||||
|
await createPhonebook(data)
|
||||||
|
},
|
||||||
|
async updateEntry (context, data) {
|
||||||
|
await updateEntry(data)
|
||||||
|
},
|
||||||
|
async updateSharedValue (context, row) {
|
||||||
|
context.commit('setSharedValue', { id: row.id, value: !row.shared })
|
||||||
|
await setSharedValue(row.subscriber_id, row.id, row.shared)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue