{ formData.name = (e.target as any).value; }}
>
{
formData.match.direction = e.detail.key;
rerender();
}}
>
{ formData.priority = parseInt((e.target as any).value, 10) || 0; }}
>
{ formData.enabled = e.detail; }}
>
${formData.match.direction === 'inbound' ? html`
({ option: provider.displayName || provider.id, key: provider.id })),
]}
@selectedOption=${(e: CustomEvent) => { formData.match.sourceProvider = e.detail.key || undefined; }}
>
option.key === selectedIncomingNumberId) || incomingNumberOptions[0]}
.options=${incomingNumberOptions}
@selectedOption=${(e: CustomEvent) => {
selectedIncomingNumberId = e.detail.key || CUSTOM_REGEX_KEY;
const selectedIncomingNumber = incomingNumbers.find((entry) => entry.id === selectedIncomingNumberId);
if (selectedIncomingNumber) {
formData.match.numberPattern = getIncomingNumberPattern(selectedIncomingNumber) || undefined;
if (selectedIncomingNumber.providerId) {
formData.match.sourceProvider = selectedIncomingNumber.providerId;
}
}
rerender();
}}
>
${selectedIncomingNumberId === CUSTOM_REGEX_KEY ? html`
{ formData.match.numberPattern = (e.target as any).value || undefined; }}
>
` : html`
Selected Pattern
${formData.match.numberPattern || '(not set)'}
`}
{ formData.match.callerPattern = (e.target as any).value || undefined; }}
>
` : html`
{ formData.match.numberPattern = (e.target as any).value || undefined; }}
>
`}
${formData.match.direction === 'inbound' ? html`
{
const value = (e.target as any).value.trim();
formData.action.targets = value ? value.split(',').map((item: string) => item.trim()).filter(Boolean) : undefined;
}}
>
{ formData.action.ringBrowsers = e.detail; }}
>
({ option: voicebox.id, key: voicebox.id })),
]}
@selectedOption=${(e: CustomEvent) => { formData.action.voicemailBox = e.detail.key || undefined; }}
>
({ option: menu.name || menu.id, key: menu.id })),
]}
@selectedOption=${(e: CustomEvent) => { formData.action.ivrMenuId = e.detail.key || undefined; }}
>
` : html`
({ option: provider.displayName || provider.id, key: provider.id })),
]}
@selectedOption=${(e: CustomEvent) => { formData.action.provider = e.detail.key || undefined; }}
>
{ formData.action.stripPrefix = (e.target as any).value || undefined; }}
>
{ formData.action.prependPrefix = (e.target as any).value || undefined; }}
>
`}
${formData.match.direction === 'inbound' && devices.length ? html`
Known devices: ${devices.map((device: any) => device.id).join(', ')}
` : ''}
`;
};
modalRef = await DeesModal.createAndShow({
heading: existing ? `Edit Route: ${existing.name}` : 'New Route',
width: 'small',
showCloseButton: true,
content: renderContent(),
menuOptions: [
{
name: 'Cancel',
iconName: 'lucide:x',
action: async (modal: any) => { modal.destroy(); },
},
{
name: 'Save',
iconName: 'lucide:check',
action: async (modal: any) => {
const next = clone(formData);
next.name = next.name.trim();
if (!next.name) {
DeesToast.error('Route name is required');
return;
}
const selectedIncomingNumber = incomingNumbers.find((entry) => entry.id === selectedIncomingNumberId);
if (next.match.direction === 'inbound' && selectedIncomingNumber) {
next.match.numberPattern = getIncomingNumberPattern(selectedIncomingNumber) || undefined;
if (selectedIncomingNumber.providerId) {
next.match.sourceProvider = selectedIncomingNumber.providerId;
}
}
if (!next.match.numberPattern) delete next.match.numberPattern;
if (!next.match.callerPattern) delete next.match.callerPattern;
if (!next.match.sourceProvider) delete next.match.sourceProvider;
if (!next.match.sourceDevice) delete next.match.sourceDevice;
if (!next.action.provider) delete next.action.provider;
if (!next.action.stripPrefix) delete next.action.stripPrefix;
if (!next.action.prependPrefix) delete next.action.prependPrefix;
if (!next.action.targets?.length) delete next.action.targets;
if (!next.action.ringBrowsers) delete next.action.ringBrowsers;
if (!next.action.voicemailBox) delete next.action.voicemailBox;
if (!next.action.ivrMenuId) delete next.action.ivrMenuId;
if (!next.action.noAnswerTimeout) delete next.action.noAnswerTimeout;
const routes = [...this.getRoutes()];
const index = routes.findIndex((route) => route.id === next.id);
if (index >= 0) routes[index] = next;
else routes.push(next);
if (await this.saveRoutes(routes)) {
modal.destroy();
DeesToast.success(existing ? 'Route updated' : 'Route created');
} else {
DeesToast.error('Failed to save route');
}
},
},
],
});
}
}