mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-10-13 16:41:58 +00:00
fix: different autmation rule fields for different types of automation rules, as conversation update and time triggers don't need conversation content & subject.
This commit is contained in:
@@ -96,6 +96,7 @@
|
||||
@update-group="handleUpdateGroup"
|
||||
@add-condition="handleAddCondition"
|
||||
@remove-condition="handleRemoveCondition"
|
||||
:type="form.values.type"
|
||||
:groupIndex="0"
|
||||
/>
|
||||
|
||||
@@ -121,6 +122,7 @@
|
||||
@update-group="handleUpdateGroup"
|
||||
@add-condition="handleAddCondition"
|
||||
@remove-condition="handleRemoveCondition"
|
||||
:type="form.values.type"
|
||||
:groupIndex="1"
|
||||
/>
|
||||
<p class="font-semibold">Perform these actions</p>
|
||||
@@ -361,6 +363,15 @@ const areRulesValid = () => {
|
||||
if (rule.value.rules[0].groups[0].rules.length == 0) {
|
||||
return false
|
||||
}
|
||||
|
||||
// Make sure each rule has all the required fields.
|
||||
for (const group of rule.value.rules[0].groups) {
|
||||
for (const rule of group.rules) {
|
||||
if (!rule.value || !rule.operator || !rule.field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
<SelectContent>
|
||||
<SelectGroup>
|
||||
<SelectLabel>Conversation</SelectLabel>
|
||||
<SelectItem v-for="(field, key) in conversationFilters" :key="key" :value="key">
|
||||
<SelectItem v-for="(field, key) in currentFilters" :key="key" :value="key">
|
||||
{{ field.label }}
|
||||
</SelectItem>
|
||||
</SelectGroup>
|
||||
@@ -157,6 +157,7 @@
|
||||
</TagsInputItem>
|
||||
<TagsInputInput placeholder="Select values" />
|
||||
</TagsInput>
|
||||
<p class="text-xs text-gray-500 mt-1">Press enter to select a value</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -184,7 +185,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { toRefs } from 'vue'
|
||||
import { toRefs, computed, watch } from 'vue'
|
||||
import { Checkbox } from '@/components/ui/checkbox'
|
||||
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'
|
||||
import { Button } from '@/components/ui/button'
|
||||
@@ -219,13 +220,36 @@ const props = defineProps({
|
||||
groupIndex: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
})
|
||||
|
||||
const { conversationFilters } = useConversationFilters()
|
||||
const { conversationFilters, newConversationFilters } = useConversationFilters()
|
||||
const { ruleGroup } = toRefs(props)
|
||||
const emit = defineEmits(['update-group', 'add-condition', 'remove-condition'])
|
||||
|
||||
// Computed property to get the correct filters based on type
|
||||
const currentFilters = computed(() => {
|
||||
return props.type === 'new_conversation'
|
||||
? newConversationFilters.value
|
||||
: conversationFilters.value
|
||||
})
|
||||
|
||||
// Watch for type change and reset the rules as the fields will change
|
||||
watch(
|
||||
() => props.type,
|
||||
(newType, oldType) => {
|
||||
// Make sure types have values and they are different.
|
||||
if (newType !== oldType && newType && oldType) {
|
||||
ruleGroup.value.rules = []
|
||||
emitUpdate()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
const handleGroupOperator = (value) => {
|
||||
ruleGroup.value.logical_op = value
|
||||
emitUpdate()
|
||||
@@ -287,18 +311,18 @@ const emitUpdate = () => {
|
||||
}
|
||||
|
||||
const getFieldOperators = (field) => {
|
||||
return conversationFilters.value[field]?.operators || []
|
||||
return currentFilters.value[field]?.operators || []
|
||||
}
|
||||
|
||||
const getFieldOptions = (field) => {
|
||||
return conversationFilters.value[field]?.options || []
|
||||
return currentFilters.value[field]?.options || []
|
||||
}
|
||||
|
||||
const inputType = (index) => {
|
||||
const field = ruleGroup.value.rules[index]?.field
|
||||
const operator = ruleGroup.value.rules[index]?.operator
|
||||
if (['contains', 'not contains'].includes(operator)) return 'tag'
|
||||
if (field) return conversationFilters.value[field].type
|
||||
if (field) return currentFilters.value[field].type
|
||||
return ''
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,12 @@ export function useConversationFilters () {
|
||||
}
|
||||
}))
|
||||
|
||||
const conversationFilters = computed(() => ({
|
||||
const newConversationFilters = computed(() => ({
|
||||
email: {
|
||||
label: 'Email',
|
||||
type: FIELD_TYPE.TEXT,
|
||||
operators: FIELD_OPERATORS.TEXT
|
||||
},
|
||||
content: {
|
||||
label: 'Content',
|
||||
type: FIELD_TYPE.TEXT,
|
||||
@@ -99,6 +104,49 @@ export function useConversationFilters () {
|
||||
}
|
||||
}))
|
||||
|
||||
const conversationFilters = computed(() => ({
|
||||
status: {
|
||||
label: 'Status',
|
||||
type: FIELD_TYPE.SELECT,
|
||||
operators: FIELD_OPERATORS.SELECT,
|
||||
options: cStore.statusOptions
|
||||
},
|
||||
priority: {
|
||||
label: 'Priority',
|
||||
type: FIELD_TYPE.SELECT,
|
||||
operators: FIELD_OPERATORS.SELECT,
|
||||
options: cStore.priorityOptions
|
||||
},
|
||||
assigned_team: {
|
||||
label: 'Assigned team',
|
||||
type: FIELD_TYPE.SELECT,
|
||||
operators: FIELD_OPERATORS.SELECT,
|
||||
options: tStore.options
|
||||
},
|
||||
assigned_user: {
|
||||
label: 'Assigned agent',
|
||||
type: FIELD_TYPE.SELECT,
|
||||
operators: FIELD_OPERATORS.SELECT,
|
||||
options: uStore.options
|
||||
},
|
||||
hours_since_created: {
|
||||
label: 'Hours since created',
|
||||
type: FIELD_TYPE.NUMBER,
|
||||
operators: FIELD_OPERATORS.NUMBER
|
||||
},
|
||||
hours_since_resolved: {
|
||||
label: 'Hours since resolved',
|
||||
type: FIELD_TYPE.NUMBER,
|
||||
operators: FIELD_OPERATORS.NUMBER
|
||||
},
|
||||
inbox: {
|
||||
label: 'Inbox',
|
||||
type: FIELD_TYPE.SELECT,
|
||||
operators: FIELD_OPERATORS.SELECT,
|
||||
options: iStore.options
|
||||
}
|
||||
}))
|
||||
|
||||
const conversationActions = computed(() => ({
|
||||
assign_team: {
|
||||
label: 'Assign to team',
|
||||
@@ -175,6 +223,7 @@ export function useConversationFilters () {
|
||||
return {
|
||||
conversationsListFilters,
|
||||
conversationFilters,
|
||||
newConversationFilters,
|
||||
conversationActions,
|
||||
macroActions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user