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/
102 lines
2.8 KiB
JavaScript
102 lines
2.8 KiB
JavaScript
import { computed } from 'vue';
|
|
import { useStore, useStoreGetters } from 'dashboard/composables/store';
|
|
|
|
/**
|
|
* Composable for managing conversation labels
|
|
* @returns {Object} An object containing methods and computed properties for conversation labels
|
|
*/
|
|
export function useConversationLabels() {
|
|
const store = useStore();
|
|
const getters = useStoreGetters();
|
|
|
|
/**
|
|
* The currently selected chat
|
|
* @type {import('vue').ComputedRef<Object>}
|
|
*/
|
|
const currentChat = computed(() => getters.getSelectedChat.value);
|
|
|
|
/**
|
|
* The ID of the current conversation
|
|
* @type {import('vue').ComputedRef<number|null>}
|
|
*/
|
|
const conversationId = computed(() => currentChat.value?.id);
|
|
|
|
/**
|
|
* All labels available for the account
|
|
* @type {import('vue').ComputedRef<Array>}
|
|
*/
|
|
const accountLabels = computed(() => getters['labels/getLabels'].value);
|
|
|
|
/**
|
|
* Labels currently saved to the conversation
|
|
* @type {import('vue').ComputedRef<Array>}
|
|
*/
|
|
const savedLabels = computed(() => {
|
|
return store.getters['conversationLabels/getConversationLabels'](
|
|
conversationId.value
|
|
);
|
|
});
|
|
|
|
/**
|
|
* Labels currently active on the conversation
|
|
* @type {import('vue').ComputedRef<Array>}
|
|
*/
|
|
const activeLabels = computed(() =>
|
|
accountLabels.value.filter(({ title }) => savedLabels.value.includes(title))
|
|
);
|
|
|
|
/**
|
|
* Labels available but not active on the conversation
|
|
* @type {import('vue').ComputedRef<Array>}
|
|
*/
|
|
const inactiveLabels = computed(() =>
|
|
accountLabels.value.filter(
|
|
({ title }) => !savedLabels.value.includes(title)
|
|
)
|
|
);
|
|
|
|
/**
|
|
* Updates the labels for the current conversation
|
|
* @param {string[]} selectedLabels - Array of label titles to be set for the conversation
|
|
* @returns {Promise<void>}
|
|
*/
|
|
const onUpdateLabels = async selectedLabels => {
|
|
await store.dispatch('conversationLabels/update', {
|
|
conversationId: conversationId.value,
|
|
labels: selectedLabels,
|
|
});
|
|
};
|
|
|
|
/**
|
|
* Adds a label to the current conversation
|
|
* @param {Object} value - The label object to be added
|
|
* @param {string} value.title - The title of the label to be added
|
|
*/
|
|
const addLabelToConversation = value => {
|
|
const result = activeLabels.value.map(item => item.title);
|
|
result.push(value.title);
|
|
onUpdateLabels(result);
|
|
};
|
|
|
|
/**
|
|
* Removes a label from the current conversation
|
|
* @param {string} value - The title of the label to be removed
|
|
*/
|
|
const removeLabelFromConversation = value => {
|
|
const result = activeLabels.value
|
|
.map(label => label.title)
|
|
.filter(label => label !== value);
|
|
onUpdateLabels(result);
|
|
};
|
|
|
|
return {
|
|
accountLabels,
|
|
savedLabels,
|
|
activeLabels,
|
|
inactiveLabels,
|
|
addLabelToConversation,
|
|
removeLabelFromConversation,
|
|
onUpdateLabels,
|
|
};
|
|
}
|