mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
fix: reverse meta relation and tidy code
This commit is contained in:
@ -2,19 +2,11 @@ export const renderCustomEmailTemplate = <T extends Record<string, string>>(
|
||||
template: string,
|
||||
variables: T,
|
||||
): string => {
|
||||
let t = template;
|
||||
|
||||
Object.entries(variables).forEach((entry) => {
|
||||
const [key, value] = entry;
|
||||
|
||||
const placeholder = `{${key}}`;
|
||||
|
||||
const re = new RegExp(placeholder, 'g');
|
||||
|
||||
if (Object.prototype.hasOwnProperty.call(variables, key)) {
|
||||
t = t.replace(re, String(value));
|
||||
return template.replace(/\{(\S+)\}/g, (_, key) => {
|
||||
if (key in variables) {
|
||||
return variables[key];
|
||||
}
|
||||
});
|
||||
|
||||
return t;
|
||||
return key;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user