Files
gochat/frontend/app/javascript/dashboard/store/modules/agents.js
T
rogee 321c61aaae Vendor Chatwoot Vue 3 frontend into frontend/
Copy the Chatwoot (v4.14.0) frontend runnable subset into frontend/ for
customization:
- app/javascript/ (Vue SPA: dashboard, widget, sdk, portal, superadmin)
- app/views/ (ERB templates for vite-plugin-ruby entrypoint resolution)
- app/helpers/, app/assets/ (Rails view helpers, static assets)
- enterprise/ (Enterprise edition frontend overlay)
- config/vite.json, vite.config.ts, bin/vite (Vite-Rails toolchain)
- package.json, pnpm-lock.yaml, tailwind/postcss/eslint configs
- Gemfile, Gemfile.lock (vite_rails gem for bin/vite binstub)

Excluded Rails backend: controllers, models, services, jobs, mailers,
policies, db, lib, spec, public, node_modules.

Update references to the new frontend location:
- .gitignore: exclude frontend build artifacts (node_modules, tmp, packs),
  keep frontend/bin/ and frontend/vendor/ via negation
- backend/scripts/parity_frontend_smoke.sh: CHATWOOT_DIR default
  reference/chatwoot -> ../frontend
- backend/scripts/parity_frontend_browser_smoke.mjs: same default update
- AGENTS.md: add frontend section with Rails/Vite coupling notes
- README: architecture tree includes frontend/
2026-07-07 14:56:01 +08:00

134 lines
3.9 KiB
JavaScript

import * as MutationHelpers from 'shared/helpers/vuex/mutationHelpers';
import * as types from '../mutation-types';
import AgentAPI from '../../api/agents';
export const state = {
records: [],
uiFlags: {
isFetching: false,
isCreating: false,
isUpdating: false,
isDeleting: false,
},
};
export const getters = {
getAgents($state) {
return $state.records;
},
getVerifiedAgents($state) {
return $state.records.filter(record => record.confirmed);
},
getUIFlags($state) {
return $state.uiFlags;
},
getAgentById: $state => id => {
return $state.records.find(record => record.id === Number(id)) || {};
},
getAgentStatus($state) {
let status = {
online: $state.records.filter(
agent => agent.availability_status === 'online'
).length,
busy: $state.records.filter(agent => agent.availability_status === 'busy')
.length,
offline: $state.records.filter(
agent => agent.availability_status === 'offline'
).length,
};
return status;
},
};
export const actions = {
get: async ({ commit }) => {
commit(types.default.SET_AGENT_FETCHING_STATUS, true);
try {
const response = await AgentAPI.get();
commit(types.default.SET_AGENT_FETCHING_STATUS, false);
commit(types.default.SET_AGENTS, response.data);
} catch (error) {
commit(types.default.SET_AGENT_FETCHING_STATUS, false);
}
},
create: async ({ commit }, agentInfo) => {
commit(types.default.SET_AGENT_CREATING_STATUS, true);
try {
const response = await AgentAPI.create(agentInfo);
commit(types.default.ADD_AGENT, response.data);
commit(types.default.SET_AGENT_CREATING_STATUS, false);
} catch (error) {
commit(types.default.SET_AGENT_CREATING_STATUS, false);
throw error;
}
},
update: async ({ commit }, { id, ...agentParams }) => {
commit(types.default.SET_AGENT_UPDATING_STATUS, true);
try {
const response = await AgentAPI.update(id, agentParams);
commit(types.default.EDIT_AGENT, response.data);
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
} catch (error) {
commit(types.default.SET_AGENT_UPDATING_STATUS, false);
throw new Error(error);
}
},
updateSingleAgentPresence: ({ commit }, { id, availabilityStatus }) => {
commit(types.default.UPDATE_SINGLE_AGENT_PRESENCE, {
id,
availabilityStatus,
});
},
updatePresence: async ({ commit }, data) => {
commit(types.default.UPDATE_AGENTS_PRESENCE, data);
},
delete: async ({ commit }, agentId) => {
commit(types.default.SET_AGENT_DELETING_STATUS, true);
try {
await AgentAPI.delete(agentId);
commit(types.default.DELETE_AGENT, agentId);
commit(types.default.SET_AGENT_DELETING_STATUS, false);
} catch (error) {
commit(types.default.SET_AGENT_DELETING_STATUS, false);
throw new Error(error);
}
},
};
export const mutations = {
[types.default.SET_AGENT_FETCHING_STATUS]($state, status) {
$state.uiFlags.isFetching = status;
},
[types.default.SET_AGENT_CREATING_STATUS]($state, status) {
$state.uiFlags.isCreating = status;
},
[types.default.SET_AGENT_UPDATING_STATUS]($state, status) {
$state.uiFlags.isUpdating = status;
},
[types.default.SET_AGENT_DELETING_STATUS]($state, status) {
$state.uiFlags.isDeleting = status;
},
[types.default.SET_AGENTS]: MutationHelpers.set,
[types.default.ADD_AGENT]: MutationHelpers.create,
[types.default.EDIT_AGENT]: MutationHelpers.update,
[types.default.DELETE_AGENT]: MutationHelpers.destroy,
[types.default.UPDATE_AGENTS_PRESENCE]: MutationHelpers.updatePresence,
[types.default.UPDATE_SINGLE_AGENT_PRESENCE]: (
$state,
{ id, availabilityStatus }
) =>
MutationHelpers.updateSingleRecordPresence($state.records, {
id,
availabilityStatus,
}),
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};