[CM-1345] Prechat lead support for Regex - iOS SDK#505
Conversation
WalkthroughThe update introduces new optional regex-based validation for name, email, and password fields in the pre-chat form, with corresponding error messages and UI adjustments. It adds localized strings for new error cases, updates validation logic to handle custom regex patterns, and modifies a label in the user form view to better accommodate dynamic content. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant PreChatFormViewController
participant PreChatConfiguration
User->>PreChatFormViewController: Submit pre-chat form
PreChatFormViewController->>PreChatConfiguration: Access regex patterns (name, email, password)
PreChatFormViewController->>PreChatFormViewController: Validate fields
alt Field is empty
PreChatFormViewController-->>User: Show required field error
else Field not empty
alt Custom regex provided
PreChatFormViewController->>PreChatFormViewController: Validate with custom regex
alt Regex fails
PreChatFormViewController-->>User: Show custom regex error message
else Regex passes
PreChatFormViewController->>PreChatFormViewController: Continue validation
end
else No custom regex
PreChatFormViewController->>PreChatFormViewController: Use default validation
end
end
PreChatFormViewController-->>User: Show success or next step
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
Sources/Kommunicate/Classes/KMPreChatFormViewController.swift (1)
307-390: Consider simplifying the complex validation logic.The validation method has become quite complex with nested conditions and multiple validation paths. Consider refactoring to improve readability and maintainability:
- Extract individual field validation into separate methods
- Consider using a more functional approach with validation result accumulation
- The interaction between
allowEmailOrPhoneNumberand individual field validation could be clearerExample refactor approach:
private func validateEmail(_ text: String?) -> TextFieldValidationError? { guard let text = text, !text.isEmpty else { return .emptyEmailAddress } guard text.isValidEmail else { return .invalidEmailAddress } if let pattern = preChatConfiguration.emailRegexPattern, !text.matchesWithPattern(pattern) { return .invalidCustomEmailRegex } return nil }
♻️ Duplicate comments (1)
Example/Kommunicate/Base.lproj/Localizable.strings (1)
33-38: Consistent localization keys added.The localization keys are consistent with the main resource file, which is good for maintaining uniformity across the codebase. However, the same concern applies here regarding the generic nature of the error messages - they don't provide specific guidance about the expected input format for custom regex patterns.
🧹 Nitpick comments (1)
Sources/Resources/Assets/Localizable.strings (1)
29-34: Consider more descriptive validation error messages.The new regex validation error messages are quite generic and don't provide users with specific guidance about the expected input format. Since these are for custom regex patterns that developers will configure, consider making the messages more informative or allowing developers to provide custom error messages.
For example, instead of "Please enter valid email address", consider something like "Email format does not match the required pattern" or allow developers to specify custom error messages alongside their regex patterns.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
Example/Kommunicate/Base.lproj/Localizable.strings(1 hunks)Sources/Kommunicate/Classes/KMPreChatFormViewController.swift(4 hunks)Sources/Resources/Assets/KMPreChatUserFormView.xib(1 hunks)Sources/Resources/Assets/Localizable.strings(1 hunks)
🔇 Additional comments (5)
Sources/Resources/Assets/KMPreChatUserFormView.xib (1)
226-226: LGTM - UI improvements for better error message display.The label modifications appropriately support the new regex validation feature:
- Enabling user interaction allows for potential future enhancements (e.g., tappable error messages)
- Word wrap and unlimited lines enable better display of longer validation error messages
- Dynamic height adjustment ensures proper content display
These changes align well with the enhanced validation functionality.
Sources/Kommunicate/Classes/KMPreChatFormViewController.swift (4)
39-52: Well-documented regex pattern properties.The new regex pattern properties are well-documented and appropriately optional. The documentation clearly explains the fallback behavior when patterns are nil.
79-81: Properly integrated new validation error cases.The new error cases are well-integrated into the existing error handling system and follow the established pattern for localization.
Also applies to: 106-111
359-371: Phone number validation allows empty values - verify intended behavior.The phone number validation now allows empty values to pass through (line 360:
continue // optional empty allowed), but then validates against regex if the value is present. This differs from other mandatory fields that use guard statements to enforce non-empty values.Verify this is the intended behavior - should phone numbers be allowed to be empty even when marked as mandatory?
363-365: ```shell
#!/bin/bashShow implementation of isValidPhoneNumber in String+Extension.swift
rg -n "var isValidPhoneNumber" -A 20 Sources/Kommunicate/Classes/String+Extension.swift
</details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Summary
Example Code
Localizable Keys
Testing Branches
KM_ChatUI_Branch :
devKM_Core_Branch:
devSummary by CodeRabbit