mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 11:37:58 +00:00
feat: Add UI to manage web widget allowed domains (#12495)
## Summary - add allowed domains controls in the web widget configuration page. <img width="1064" height="699" alt="Screenshot 2025-09-23 at 8 52 21 PM" src="https://github.com/user-attachments/assets/8afd60b6-c81d-4f52-9cbe-07e70ad003d2" /> fixes: https://linear.app/chatwoot/issue/CW-5661/add-the-options-for-configure-allowed-domains-for-web-widget --------- Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: iamsivin <iamsivin@gmail.com>
This commit is contained in:
@@ -145,3 +145,34 @@ export const extractFilenameFromUrl = url => {
|
||||
return match ? match[1] : url;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalizes a comma/newline separated list of domains
|
||||
* @param {string} domains - The comma/newline separated list of domains
|
||||
* @returns {string} - The normalized list of domains
|
||||
* - Converts newlines to commas
|
||||
* - Trims whitespace
|
||||
* - Lowercases entries
|
||||
* - Removes empty values
|
||||
* - De-duplicates while preserving original order
|
||||
*/
|
||||
export const sanitizeAllowedDomains = domains => {
|
||||
if (!domains) return '';
|
||||
|
||||
const tokens = domains
|
||||
.replace(/\r\n/g, '\n')
|
||||
.replace(/\s*\n\s*/g, ',')
|
||||
.split(',')
|
||||
.map(d => d.trim().toLowerCase())
|
||||
.filter(d => d.length > 0);
|
||||
|
||||
// De-duplicate while preserving order using Set and filter index
|
||||
const seen = new Set();
|
||||
const unique = tokens.filter(d => {
|
||||
if (seen.has(d)) return false;
|
||||
seen.add(d);
|
||||
return true;
|
||||
});
|
||||
|
||||
return unique.join(',');
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user