1import { createResource } from "frappe-ui";
2import { defineStore } from "pinia";
3import { computed, ComputedRef } from "vue";
4import { globalStore } from "./globalStore";
5
6export const useConfigStore = defineStore("config", () => {
7 const { $socket } = globalStore();
8 const configResource = createResource({
9 url: "opendesk.api.config.get_config",
10 auto: true,
11 });
12
13 const config = computed(() => configResource.data || {});
14 const brandName = computed(() => config.value.brand_name);
15 const brandLogo = computed(() => config.value.brand_logo);
16 const favicon = computed(() => config.value.favicon);
17
18 const teamRestrictionApplied = computed(
19 () => !!parseInt(config.value.restrict_tickets_by_agent_group)
20 );
21 const disableGlobalScopeForSavedReplies = computed(
22 () => !!parseInt(config.value.disable_saved_replies_global_scope)
23 );
24 const assignWithinTeam = computed(
25 () => !!parseInt(config.value.assign_within_team)
26 );
27 const skipEmailWorkflow: ComputedRef<boolean> = computed(
28 () => !!parseInt(config.value.skip_email_workflow)
29 );
30 const isFeedbackMandatory = computed(
31 () => !!parseInt(config.value.is_feedback_mandatory)
32 );
33 const enableCommentReactions = computed(
34 () => !!parseInt(config.value.enable_comment_reactions)
35 );
36
37 $socket.on("opendesk:settings-updated", () => configResource.reload());
38
39 return {
40 configResource,
41 brandName,
42 brandLogo,
43 favicon,
44 config,
45 skipEmailWorkflow,
46 isFeedbackMandatory,
47 teamRestrictionApplied,
48 assignWithinTeam,
49 disableGlobalScopeForSavedReplies,
50 enableCommentReactions,
51 };
52});
53