Fix missing signal notifications field
This commit is contained in:
parent
bf46bb5beb
commit
e9afa065b5
1 changed files with 28 additions and 9 deletions
|
|
@ -61,15 +61,19 @@ const soundOptions = Object.keys(EnumNotificationSoundFile).map((sound) => ({
|
|||
value: sound,
|
||||
}))
|
||||
|
||||
// CDR Link: Check if any Signal notification checkbox is selected in the matrix
|
||||
const hasSignalNotificationSelected = computed(() => {
|
||||
const matrix = values.value?.matrix
|
||||
if (!matrix) return false
|
||||
// CDR Link: Track if any Signal notification checkbox is selected
|
||||
// Using a ref + onChangedField for reactivity instead of computed on values
|
||||
const showSignalPhoneField = ref(false)
|
||||
|
||||
// Check all rows (create, update, reminderReached, escalation) for signal channel enabled
|
||||
// Helper to check if any signal checkbox is enabled in matrix
|
||||
const checkSignalSelected = (matrix: any): boolean => {
|
||||
if (!matrix) return false
|
||||
const rows = ['create', 'update', 'reminderReached', 'escalation']
|
||||
return rows.some((row) => matrix[row]?.channel?.signal === true)
|
||||
})
|
||||
}
|
||||
|
||||
// CDR Link: Key for form re-rendering when signal field visibility changes
|
||||
const formKey = computed(() => `notifications-${showSignalPhoneField.value}`)
|
||||
|
||||
// CDR Link: Dynamically build schema based on signal notification setting
|
||||
const schema = computed(() => {
|
||||
|
|
@ -95,7 +99,7 @@ const schema = computed(() => {
|
|||
|
||||
// CDR Link: Add Signal phone number field only when Signal notifications are enabled
|
||||
// AND at least one Signal notification checkbox is selected
|
||||
if (signalNotificationEnabled.value && hasSignalNotificationSelected.value) {
|
||||
if (signalNotificationEnabled.value && showSignalPhoneField.value) {
|
||||
baseSchema.push({
|
||||
type: 'text',
|
||||
name: 'signal_uid',
|
||||
|
|
@ -155,12 +159,25 @@ watch(initialFormValues, (newValues) => {
|
|||
if (isEqual(values.value, newValues) && !isDirty.value) return
|
||||
|
||||
formReset({ values: newValues })
|
||||
})
|
||||
// CDR Link: Update signal field visibility from initial values
|
||||
showSignalPhoneField.value = checkSignalSelected(newValues.matrix)
|
||||
}, { immediate: true })
|
||||
|
||||
onChangedField('file', (fileName) => {
|
||||
new Audio(`/assets/sounds/${fileName?.toString()}.mp3`)?.play()
|
||||
})
|
||||
|
||||
// CDR Link: Watch matrix field changes to show/hide signal phone field
|
||||
onChangedField('matrix', (matrix) => {
|
||||
showSignalPhoneField.value = checkSignalSelected(matrix)
|
||||
})
|
||||
|
||||
// CDR Link: Get CSRF token from meta tag
|
||||
const getCsrfToken = (): string => {
|
||||
const metaTag = document.querySelector('meta[name="csrf-token"]')
|
||||
return metaTag?.getAttribute('content') || ''
|
||||
}
|
||||
|
||||
// CDR Link: Save signal_uid via REST API
|
||||
const saveSignalUid = async (signalUid: string | undefined) => {
|
||||
if (!signalNotificationEnabled.value) return
|
||||
|
|
@ -170,6 +187,7 @@ const saveSignalUid = async (signalUid: string | undefined) => {
|
|||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': getCsrfToken(),
|
||||
},
|
||||
body: JSON.stringify({
|
||||
notification_config: {
|
||||
|
|
@ -287,7 +305,8 @@ const onResetToDefaultSettings = async () => {
|
|||
<LayoutContent :breadcrumb-items="breadcrumbItems" width="narrow">
|
||||
<div class="mb-4">
|
||||
<Form
|
||||
id="notifications-form"
|
||||
:id="formKey"
|
||||
:key="formKey"
|
||||
ref="form"
|
||||
:schema="schema"
|
||||
:form-updater-id="EnumFormUpdaterId.FormUpdaterUpdaterUserNotifications"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue