-
Notifications
You must be signed in to change notification settings - Fork 12k
fix: workflow locale #26509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
fix: workflow locale #26509
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d8b4bfb
fix: workflow locale
Udit-takkar 32d1db4
fix: workflow locale
Udit-takkar 54edb06
fix: check if tmeplate is changed
Udit-takkar c1769ab
Merge branch 'main' into fix/workflow-locale
Udit-takkar cf927dc
fix: regression
Udit-takkar 03489d3
Merge branch 'main' into fix/workflow-locale
ThyMinimalDev e169153
fix: also check subject when determining if template is customized
devin-ai-integration[bot] 6b9ed29
Merge branch 'main' into fix/workflow-locale
ThyMinimalDev d888646
Merge branch 'main' into fix/workflow-locale
ThyMinimalDev e85e9bc
Merge branch 'main' into fix/workflow-locale
ThyMinimalDev d0f8ef5
refactor: extract template matching logic into testable function
devin-ai-integration[bot] 45cd08a
Merge branch 'main' into fix/workflow-locale
ThyMinimalDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/features/ee/workflows/lib/detectMatchedTemplate.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { WorkflowTemplates } from "@calcom/prisma/enums"; | ||
|
|
||
| import compareReminderBodyToTemplate from "./compareReminderBodyToTemplate"; | ||
|
|
||
| export type DefaultTemplates = { | ||
| reminder: { body: string | null; subject: string | null }; | ||
| rating: { body: string | null; subject: string | null }; | ||
| }; | ||
|
|
||
| export type DetectMatchedTemplateParams = { | ||
| emailBody: string; | ||
| emailSubject: string; | ||
| template?: WorkflowTemplates; | ||
| defaultTemplates: DefaultTemplates; | ||
| }; | ||
|
|
||
| /** | ||
| * Detects if the email body and subject match a default template (REMINDER or RATING). | ||
| * | ||
| * Logic: | ||
| * 1. If emailBody is empty but template is specified as REMINDER or RATING, return that template | ||
| * 2. If emailBody exists, check if both body AND subject match the REMINDER default template | ||
| * 3. If not matched, check if both body AND subject match the RATING default template | ||
| * 4. Return null if no match (indicating custom content that should be preserved) | ||
| * | ||
| * This is used to determine whether to regenerate the template with the recipient's locale | ||
| * for proper translation, or to preserve user customizations. | ||
| */ | ||
| export function detectMatchedTemplate({ | ||
| emailBody, | ||
| emailSubject, | ||
| template, | ||
| defaultTemplates, | ||
| }: DetectMatchedTemplateParams): WorkflowTemplates | null { | ||
| if (!emailBody && template === WorkflowTemplates.REMINDER) { | ||
| return WorkflowTemplates.REMINDER; | ||
| } | ||
|
|
||
| if (!emailBody && template === WorkflowTemplates.RATING) { | ||
| return WorkflowTemplates.RATING; | ||
| } | ||
|
|
||
| if (emailBody) { | ||
| const { reminder, rating } = defaultTemplates; | ||
|
|
||
| const bodyMatchesReminder = | ||
| reminder.body && compareReminderBodyToTemplate({ reminderBody: emailBody, template: reminder.body }); | ||
| const subjectMatchesReminder = reminder.subject && emailSubject === reminder.subject; | ||
|
|
||
| if (bodyMatchesReminder && subjectMatchesReminder) { | ||
| return WorkflowTemplates.REMINDER; | ||
| } | ||
|
|
||
| const bodyMatchesRating = | ||
| rating.body && compareReminderBodyToTemplate({ reminderBody: emailBody, template: rating.body }); | ||
| const subjectMatchesRating = rating.subject && emailSubject === rating.subject; | ||
|
|
||
| if (bodyMatchesRating && subjectMatchesRating) { | ||
| return WorkflowTemplates.RATING; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.