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/
101 lines
2.7 KiB
JavaScript
101 lines
2.7 KiB
JavaScript
import types from '../../mutation-types';
|
|
|
|
export const mutations = {
|
|
[types.SET_UI_FLAG](_state, uiFlags) {
|
|
_state.uiFlags = {
|
|
..._state.uiFlags,
|
|
...uiFlags,
|
|
};
|
|
},
|
|
|
|
[types.ADD_ARTICLE]: ($state, article) => {
|
|
if (!article.id) return;
|
|
|
|
$state.articles.byId[article.id] = article;
|
|
},
|
|
[types.CLEAR_ARTICLES]: $state => {
|
|
$state.articles.allIds = [];
|
|
$state.articles.byId = {};
|
|
$state.articles.uiFlags.byId = {};
|
|
},
|
|
[types.ADD_MANY_ARTICLES]($state, articles) {
|
|
const allArticles = { ...$state.articles.byId };
|
|
articles.forEach(article => {
|
|
allArticles[article.id] = article;
|
|
});
|
|
|
|
$state.articles.byId = allArticles;
|
|
},
|
|
[types.ADD_MANY_ARTICLES_ID]($state, articleIds) {
|
|
$state.articles.allIds.push(...articleIds);
|
|
},
|
|
|
|
[types.SET_ARTICLES_META]: ($state, meta) => {
|
|
$state.meta = {
|
|
...$state.meta,
|
|
...meta,
|
|
};
|
|
},
|
|
|
|
[types.ADD_ARTICLE_ID]: ($state, articleId) => {
|
|
if ($state.articles.allIds.includes(articleId)) return;
|
|
$state.articles.allIds.push(articleId);
|
|
},
|
|
[types.UPDATE_ARTICLE_FLAG]: ($state, { articleId, uiFlags }) => {
|
|
const flags = $state.articles.uiFlags.byId[articleId] || {};
|
|
|
|
$state.articles.uiFlags.byId[articleId] = {
|
|
...{
|
|
isFetching: false,
|
|
isUpdating: false,
|
|
isDeleting: false,
|
|
},
|
|
...flags,
|
|
...uiFlags,
|
|
};
|
|
},
|
|
[types.ADD_ARTICLE_FLAG]: ($state, { articleId, uiFlags }) => {
|
|
$state.articles.uiFlags.byId[articleId] = {
|
|
...{
|
|
isFetching: false,
|
|
isUpdating: false,
|
|
isDeleting: false,
|
|
},
|
|
...uiFlags,
|
|
};
|
|
},
|
|
[types.SET_ARTICLE_POSITIONS]: ($state, positionsHash) => {
|
|
const { byId, allIds } = $state.articles;
|
|
// Update position on each article record
|
|
Object.entries(positionsHash).forEach(([id, position]) => {
|
|
if (byId[id]) byId[id] = { ...byId[id], position };
|
|
});
|
|
// Re-sort allIds so every consumer sees the new order
|
|
allIds.sort(
|
|
(a, b) =>
|
|
(byId[a]?.position ?? Infinity) - (byId[b]?.position ?? Infinity)
|
|
);
|
|
},
|
|
[types.UPDATE_ARTICLE]: ($state, updatedArticle) => {
|
|
const articleId = updatedArticle.id;
|
|
if ($state.articles.byId[articleId]) {
|
|
const existing = $state.articles.byId[articleId];
|
|
|
|
$state.articles.byId[articleId] = {
|
|
...existing,
|
|
...updatedArticle,
|
|
position: existing.position,
|
|
};
|
|
}
|
|
},
|
|
[types.REMOVE_ARTICLE]($state, articleId) {
|
|
const { [articleId]: toBeRemoved, ...newById } = $state.articles.byId;
|
|
$state.articles.byId = newById;
|
|
},
|
|
[types.REMOVE_ARTICLE_ID]($state, articleId) {
|
|
$state.articles.allIds = $state.articles.allIds.filter(
|
|
id => id !== articleId
|
|
);
|
|
},
|
|
};
|