mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 03:27:52 +00:00
Fixes https://github.com/chatwoot/chatwoot/issues/8436 Fixes https://github.com/chatwoot/chatwoot/issues/9767 Fixes https://github.com/chatwoot/chatwoot/issues/10156 Fixes https://github.com/chatwoot/chatwoot/issues/6031 Fixes https://github.com/chatwoot/chatwoot/issues/5696 Fixes https://github.com/chatwoot/chatwoot/issues/9250 Fixes https://github.com/chatwoot/chatwoot/issues/9762 --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com>
55 lines
1.4 KiB
JavaScript
55 lines
1.4 KiB
JavaScript
export const set = (state, data) => {
|
|
state.records = data;
|
|
};
|
|
|
|
export const create = (state, data) => {
|
|
state.records.push(data);
|
|
};
|
|
|
|
export const setSingleRecord = (state, data) => {
|
|
const recordIndex = state.records.findIndex(record => record.id === data.id);
|
|
if (recordIndex > -1) {
|
|
state.records[recordIndex] = data;
|
|
} else {
|
|
create(state, data);
|
|
}
|
|
};
|
|
|
|
export const update = (state, data) => {
|
|
state.records.forEach((element, index) => {
|
|
if (element.id === data.id) {
|
|
state.records[index] = data;
|
|
}
|
|
});
|
|
};
|
|
|
|
/* when you don't want to overwrite the whole object */
|
|
export const updateAttributes = (state, data) => {
|
|
state.records.forEach((element, index) => {
|
|
if (element.id === data.id) {
|
|
state.records[index] = { ...state.records[index], ...data };
|
|
}
|
|
});
|
|
};
|
|
|
|
export const updatePresence = (state, data) => {
|
|
state.records.forEach((element, index) => {
|
|
const availabilityStatus = data[element.id];
|
|
state.records[index].availability_status = availabilityStatus || 'offline';
|
|
});
|
|
};
|
|
|
|
export const updateSingleRecordPresence = (
|
|
records,
|
|
{ id, availabilityStatus }
|
|
) => {
|
|
const [selectedRecord] = records.filter(record => record.id === Number(id));
|
|
if (selectedRecord) {
|
|
selectedRecord.availability_status = availabilityStatus;
|
|
}
|
|
};
|
|
|
|
export const destroy = (state, id) => {
|
|
state.records = state.records.filter(record => record.id !== id);
|
|
};
|