Fix missing signal notifications field

This commit is contained in:
Darren Clarke 2026-02-12 20:52:47 +01:00
parent bf46bb5beb
commit e9afa065b5

View file

@ -61,15 +61,19 @@ const soundOptions = Object.keys(EnumNotificationSoundFile).map((sound) => ({
value: sound, value: sound,
})) }))
// CDR Link: Check if any Signal notification checkbox is selected in the matrix // CDR Link: Track if any Signal notification checkbox is selected
const hasSignalNotificationSelected = computed(() => { // Using a ref + onChangedField for reactivity instead of computed on values
const matrix = values.value?.matrix const showSignalPhoneField = ref(false)
if (!matrix) return 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'] const rows = ['create', 'update', 'reminderReached', 'escalation']
return rows.some((row) => matrix[row]?.channel?.signal === true) 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 // CDR Link: Dynamically build schema based on signal notification setting
const schema = computed(() => { const schema = computed(() => {
@ -95,7 +99,7 @@ const schema = computed(() => {
// CDR Link: Add Signal phone number field only when Signal notifications are enabled // CDR Link: Add Signal phone number field only when Signal notifications are enabled
// AND at least one Signal notification checkbox is selected // AND at least one Signal notification checkbox is selected
if (signalNotificationEnabled.value && hasSignalNotificationSelected.value) { if (signalNotificationEnabled.value && showSignalPhoneField.value) {
baseSchema.push({ baseSchema.push({
type: 'text', type: 'text',
name: 'signal_uid', name: 'signal_uid',
@ -155,12 +159,25 @@ watch(initialFormValues, (newValues) => {
if (isEqual(values.value, newValues) && !isDirty.value) return if (isEqual(values.value, newValues) && !isDirty.value) return
formReset({ values: newValues }) formReset({ values: newValues })
}) // CDR Link: Update signal field visibility from initial values
showSignalPhoneField.value = checkSignalSelected(newValues.matrix)
}, { immediate: true })
onChangedField('file', (fileName) => { onChangedField('file', (fileName) => {
new Audio(`/assets/sounds/${fileName?.toString()}.mp3`)?.play() 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 // CDR Link: Save signal_uid via REST API
const saveSignalUid = async (signalUid: string | undefined) => { const saveSignalUid = async (signalUid: string | undefined) => {
if (!signalNotificationEnabled.value) return if (!signalNotificationEnabled.value) return
@ -170,6 +187,7 @@ const saveSignalUid = async (signalUid: string | undefined) => {
method: 'PUT', method: 'PUT',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRF-Token': getCsrfToken(),
}, },
body: JSON.stringify({ body: JSON.stringify({
notification_config: { notification_config: {
@ -287,7 +305,8 @@ const onResetToDefaultSettings = async () => {
<LayoutContent :breadcrumb-items="breadcrumbItems" width="narrow"> <LayoutContent :breadcrumb-items="breadcrumbItems" width="narrow">
<div class="mb-4"> <div class="mb-4">
<Form <Form
id="notifications-form" :id="formKey"
:key="formKey"
ref="form" ref="form"
:schema="schema" :schema="schema"
:form-updater-id="EnumFormUpdaterId.FormUpdaterUpdaterUserNotifications" :form-updater-id="EnumFormUpdaterId.FormUpdaterUpdaterUserNotifications"