- Arquitetura corrigida: templates agora pertencem à inbox (WhatsApp),
não à unidade PIX (que é uma config financeira, não de mensagens)
- Migration: troca FK captain_unit_id -> inbox_id (up/down explícito)
- Model: belongs_to :inbox; scope for_inbox
- Controller: escopo via account.inboxes.find(inbox_id)
- Rotas: move de captain/units/:id → inboxes/:id/notification_templates
- Scanner job: joins(:conversation).where(conversations: {inbox_id:})
- UI: página /captain/notifications com seletor de inbox no topo
(chips clicáveis, templates carregam por watch no selectedInboxId)
- i18n PT/EN: novas keys INBOX_LABEL, SELECT_INBOX_HINT, EMPTY
85 lines
2.0 KiB
JavaScript
85 lines
2.0 KiB
JavaScript
import notificationTemplatesAPI from '../../api/captain/notificationTemplates';
|
|
|
|
const state = {
|
|
records: [],
|
|
uiFlags: {
|
|
isFetching: false,
|
|
isSaving: false,
|
|
},
|
|
};
|
|
|
|
const getters = {
|
|
getRecords: $state => $state.records,
|
|
getUIFlags: $state => $state.uiFlags,
|
|
};
|
|
|
|
const actions = {
|
|
async fetch({ commit }, inboxId) {
|
|
commit('SET_UI_FLAG', { isFetching: true });
|
|
try {
|
|
const { data } = await notificationTemplatesAPI.getAll(inboxId);
|
|
commit('SET_RECORDS', data);
|
|
} finally {
|
|
commit('SET_UI_FLAG', { isFetching: false });
|
|
}
|
|
},
|
|
|
|
async create({ commit }, { inboxId, payload }) {
|
|
commit('SET_UI_FLAG', { isSaving: true });
|
|
try {
|
|
const { data } = await notificationTemplatesAPI.create(inboxId, payload);
|
|
commit('ADD_RECORD', data);
|
|
return data;
|
|
} finally {
|
|
commit('SET_UI_FLAG', { isSaving: false });
|
|
}
|
|
},
|
|
|
|
async update({ commit }, { inboxId, id, payload }) {
|
|
commit('SET_UI_FLAG', { isSaving: true });
|
|
try {
|
|
const { data } = await notificationTemplatesAPI.update(
|
|
inboxId,
|
|
id,
|
|
payload
|
|
);
|
|
commit('UPDATE_RECORD', data);
|
|
return data;
|
|
} finally {
|
|
commit('SET_UI_FLAG', { isSaving: false });
|
|
}
|
|
},
|
|
|
|
async delete({ commit }, { inboxId, id }) {
|
|
await notificationTemplatesAPI.delete(inboxId, id);
|
|
commit('DELETE_RECORD', id);
|
|
},
|
|
};
|
|
|
|
const mutations = {
|
|
SET_RECORDS($state, records) {
|
|
$state.records = records;
|
|
},
|
|
ADD_RECORD($state, record) {
|
|
$state.records.push(record);
|
|
},
|
|
UPDATE_RECORD($state, record) {
|
|
const idx = $state.records.findIndex(r => r.id === record.id);
|
|
if (idx !== -1) $state.records.splice(idx, 1, record);
|
|
},
|
|
DELETE_RECORD($state, id) {
|
|
$state.records = $state.records.filter(r => r.id !== id);
|
|
},
|
|
SET_UI_FLAG($state, flags) {
|
|
$state.uiFlags = { ...$state.uiFlags, ...flags };
|
|
},
|
|
};
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state,
|
|
getters,
|
|
actions,
|
|
mutations,
|
|
};
|