Skip to content

Add banner about updating default email address to email action #2239

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

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

AbdiTolesa
Copy link
Contributor

@AbdiTolesa AbdiTolesa commented Feb 3, 2025

Fix https://github.com/Strategy11/formidable-pro/issues/5453
Design: https://www.figma.com/design/QnMV8Njb7k5hDSdgrvNveY/Form-Actions-(Explorations)?node-id=6-207&t=Y9cwZI7PmScrnuVF-0

image

Test procedure

  1. Go to form actions tab of your form and open an email action.
  2. Confirm that a banner is implemented as per the design in the url above.
  3. Confirm that clicking Got it dismisses the banner and it would never be displayed for that user again, even after form reload.
  4. Confirm that Setup emails redirects user to the email setup page.

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Walkthrough

This pull request introduces a feature that displays a warning about potential email delivery issues when the 'To' and 'From' addresses are the same. A new conditional block in the view renders this warning along with buttons for acknowledgment and redirection to the email setup. Additionally, new CSS rules enhance the visual styling of the warning message. AJAX functionality is implemented, including an action hook, a new controller method, and a JavaScript event handler, allowing users to dismiss the warning message.

Changes

File(s) Change Summary
classes/views/frm-form-actions/_action_inside.php
css/frm_admin.css
Added a conditional block in the view to display an email warning message with acknowledgment and redirect buttons; introduced new CSS styling for the default email message container.
classes/controllers/FrmHooksController.php
js/admin/settings.js
classes/controllers/FrmFormsController.php
Added an AJAX action hook and a corresponding public static method (dismiss_default_email_message) to handle dismiss requests; enhanced JavaScript by adding an event listener that sends an AJAX request to dismiss the default email message and removes the message from the DOM upon success.
classes/controllers/FrmFormActionsController.php Introduced a new public static method (should_show_notice_about_using_the_same_to_from_email) to determine when to show the email notice based on specific conditions.

Possibly related PRs

  • Add Default from address setting #1967: The changes in the main PR, which introduce a method for determining whether to show a notice about using the same 'To' and 'From' email addresses, are related to the retrieved PR that adds a default "From" email address setting, as both involve modifications to email handling logic within the application.
  • Add redirect delay settings #2117: The changes in the main PR are related to the FrmFormsController class, specifically the addition of the dismiss_default_email_message method, which is also modified in the retrieved PR that alters the FrmFormsController class, indicating a direct connection in terms of code modifications.
  • Fix default email setting is never used #2013: The changes in the main PR, which introduce a method for determining when to show a notice about email settings, are related to the retrieved PR that modifies default email settings and introduces new shortcodes for email actions, as both involve handling email configurations within the same framework.

Suggested reviewers

  • truongwp
  • Crabcyborg
  • tuguirazvan

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ffce5eb and 8257807.

📒 Files selected for processing (1)
  • js/admin/settings.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
🔇 Additional comments (3)
js/admin/settings.js (3)

3-4: Good job importing the required AJAX function.

The destructuring import of doJsonPost from frmDom.ajax follows modern JavaScript practices and keeps the code clean.


8-8: Clean integration of the new click event listener.

The new click event listener is properly added to the document, maintaining consistency with the existing event handling structure.


25-39: Add missing semicolon in the promise handler.

The new click event handler for dismissing the default email message is well-structured with proper error handling. However, there's a missing semicolon at the end of line 34.

-				e.target.closest( '.frm_default_email_message' ).remove();
+				e.target.closest( '.frm_default_email_message' ).remove();

The implementation correctly:

  1. Prevents default behavior
  2. Uses FormData for the AJAX request
  3. Includes security nonce
  4. Properly removes the banner from DOM when dismissed
  5. Has error handling for the AJAX request
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
classes/views/frm-form-actions/_action_inside.php (2)

14-14: Remove empty style attribute.

The <p> tag contains an empty style attribute that should be removed.

-	<p class="frm10" style="">
+	<p class="frm10">

13-22: Improve semantic HTML structure and error handling.

The notice should use more semantic HTML elements and include error handling for translation functions.

-<div class="frm_grid_container frm_no_p_margin frm_default_email_notice">
-	<p class="frm10">
-		<b><?php esc_html_e( 'Heads up!', 'formidable' ); ?></b>
-		<?php esc_html_e( 'Using the same \'To\' and \'From\' email address can sometimes cause delivery issues. We recommend updating your default email addresses to maximize deliverability.', 'formidable' ); ?>
-	</p>
-	<p class="frm2">
+<div class="frm_grid_container frm_no_p_margin frm_default_email_notice" role="alert">
+	<div class="frm10">
+		<h4 class="frm_warning_heading">
+			<?php 
+			$heading = esc_html__( 'Heads up!', 'formidable' );
+			if ( false === $heading ) {
+				$heading = 'Heads up!'; // Fallback if translation fails
+			}
+			echo $heading;
+			?>
+		</h4>
+		<?php
+		$message = esc_html__( 'Using the same \'To\' and \'From\' email address can sometimes cause delivery issues. We recommend updating your default email addresses to maximize deliverability.', 'formidable' );
+		if ( false === $message ) {
+			$message = 'Please update your email settings to ensure proper delivery.'; // Fallback if translation fails
+		}
+		echo $message;
+		?>
+	</div>
+	<div class="frm2">
css/frm_admin.css (1)

5447-5451: Consider adding a hover/focus state for better interactivity.

If this notice contains any interactive elements like buttons or links, consider adding hover/focus states to provide visual feedback.

.frm_email_settings .frm_default_email_notice {
    background-color: var(--primary-25);
    padding:var(--gap-sm) var(--gap-md);
    border-radius:var(--small-radius);
+   transition: background-color 0.2s ease;
}

+.frm_email_settings .frm_default_email_notice:hover {
+   background-color: var(--primary-50);
+}

+.frm_email_settings .frm_default_email_notice:focus-within {
+   outline: 2px solid var(--primary-500);
+   outline-offset: 2px;
+}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf5222c and 5a4b1a8.

📒 Files selected for processing (2)
  • classes/views/frm-form-actions/_action_inside.php (1 hunks)
  • css/frm_admin.css (1 hunks)
🔇 Additional comments (4)
classes/views/frm-form-actions/_action_inside.php (2)

10-24: LGTM! Well-placed notice block.

The placement of the email notice block at the beginning of the form action settings is appropriate and follows a logical flow.


19-20: ⚠️ Potential issue

Add click handlers and improve accessibility for buttons.

The buttons have href="#" but no JavaScript handlers to process the clicks. Additionally, they need ARIA labels for better accessibility.

-		<a href="#" class="button frm-button-secondary"><?php esc_html_e( 'Got it', 'formidable' ); ?></a>
-		<a href="#" class="button frm-button-primary"><?php esc_html_e( 'Setup emails', 'formidable' ); ?></a>
+		<a href="#" 
+			class="button frm-button-secondary" 
+			onclick="frmDismissEmailNotice(this); return false;" 
+			aria-label="<?php esc_attr_e( 'Dismiss email setup notice', 'formidable' ); ?>">
+			<?php esc_html_e( 'Got it', 'formidable' ); ?>
+		</a>
+		<a href="#" 
+			class="button frm-button-primary" 
+			onclick="frmShowEmailSetup(this); return false;" 
+			aria-label="<?php esc_attr_e( 'Open email setup configuration', 'formidable' ); ?>">
+			<?php esc_html_e( 'Setup emails', 'formidable' ); ?>
+		</a>

Please ensure the JavaScript functions frmDismissEmailNotice and frmShowEmailSetup are defined in your JS files:

css/frm_admin.css (2)

5447-5451: LGTM! The styling for the default email notice is well-structured.

The new CSS rule for .frm_email_settings .frm_default_email_notice uses appropriate variables for consistent styling and follows best practices:

  • Uses the primary color variable for background
  • Applies consistent padding using gap variables
  • Uses border-radius variable for rounded corners

5447-5451: Verify the background color contrast meets accessibility standards.

The background color uses var(--primary-25) which appears to be a light blue. Let's verify that this provides sufficient contrast with the text color for accessibility.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
classes/controllers/FrmFormsController.php (1)

2528-2537: LGTM! The implementation looks secure and follows WordPress best practices.

The function properly verifies the AJAX nonce before updating user meta. However, the @since version tag is not defined yet.

Update the @since x.x version number to the actual version this feature will be released in.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22e4d5f and d5a82af.

📒 Files selected for processing (2)
  • classes/controllers/FrmFormsController.php (1 hunks)
  • classes/controllers/FrmHooksController.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • classes/controllers/FrmHooksController.php
🔇 Additional comments (1)
classes/controllers/FrmFormsController.php (1)

2549-2576: LGTM! The validation logic is thorough and handles different action types appropriately.

The function properly validates:

  • Redirect URLs through the frm_redirect_url filter
  • Page existence and status for page actions

@Crabcyborg Crabcyborg requested a review from truongwp February 14, 2025 18:04
@Crabcyborg Crabcyborg added this to the 6.19 milestone Feb 14, 2025
@AbdiTolesa AbdiTolesa requested a review from truongwp February 18, 2025 07:43
Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 26.85%. Comparing base (047c6ef) to head (aebe6d4).
Report is 422 commits behind head on master.

Files with missing lines Patch % Lines
classes/controllers/FrmFormsController.php 25.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #2239      +/-   ##
============================================
+ Coverage     26.82%   26.85%   +0.02%     
- Complexity     8320     8361      +41     
============================================
  Files           129      129              
  Lines         27488    27626     +138     
============================================
+ Hits           7375     7418      +43     
- Misses        20113    20208      +95     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@truongwp
Copy link
Contributor

@AbdiTolesa The buttons don't display well in my laptop. Can you fix it?

Screenshot 2025-02-20 at 22 43 54

@AbdiTolesa AbdiTolesa requested review from truongwp and removed request for truongwp February 24, 2025 09:08
@truongwp
Copy link
Contributor

@AbdiTolesa My last styling issue hasn't been fixed. You can check with the screen width less than 1700px.

@AbdiTolesa
Copy link
Contributor Author

@AbdiTolesa My last styling issue hasn't been fixed. You can check with the screen width less than 1700px.

@truongwp I think my new commit fixes that for you.

@truongwp
Copy link
Contributor

@AbdiTolesa Now this is what I see on iPad pro:
Screenshot 2025-02-26 at 22 18 32

@AbdiTolesa
Copy link
Contributor Author

AbdiTolesa commented Feb 27, 2025

@AbdiTolesa Now this is what I see on iPad pro:

@truongwp I originally wanted it to stack vertically if it must be responsive and I think you didn't like that on your laptop size. Should we stop forcing it to be side by side and make it stack vertically based on the screen size? So if there is no enough room to show it side by side (like in your previous comment) even if it is desktop size. The last resort would be defining a new media query in frm_admin.css and writing a style for responsive design which I believe isn't worth it. Not everything looks perfect on smaller devices in our admin pages actually.

@truongwp
Copy link
Contributor

@AbdiTolesa In my opinion, displaying them vertically doesn't look good. Can you make them horizontal in the bottom of the message? I also want to hear from @tuguirazvan.

@AbdiTolesa AbdiTolesa requested review from truongwp and removed request for truongwp March 4, 2025 11:19
@truongwp
Copy link
Contributor

truongwp commented Mar 4, 2025

@AbdiTolesa Now on small screen, the buttons are horizontally aligned. They should be left aligned.
Screenshot 2025-03-04 at 22 58 43

@AbdiTolesa
Copy link
Contributor Author

@AbdiTolesa Now on small screen, the buttons are horizontally aligned. They should be left aligned.

@truongwp Sorry I did the left alignment targeting the wrong class in 333a11c

It is fixed now.

@truongwp
Copy link
Contributor

truongwp commented Mar 5, 2025

@AbdiTolesa Only one more thing, the color of Heads up text (or maybe the whole message) needs to be darker.

@AbdiTolesa AbdiTolesa requested review from truongwp and removed request for truongwp March 6, 2025 13:46
Copy link
Contributor

@truongwp truongwp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now. Thanks @AbdiTolesa!

@truongwp truongwp requested a review from Crabcyborg March 6, 2025 14:36
@AbdiTolesa AbdiTolesa requested a review from Crabcyborg March 7, 2025 07:11
@Crabcyborg Crabcyborg modified the milestones: 6.19, 6.20 Mar 7, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (3)
classes/controllers/FrmFormActionsController.php (1)

432-445: Update the version placeholder and consider using get_current_user_id()

The @since x.x should be updated with the actual version number. Also, consider using get_current_user_id() instead of wp_get_current_user()->ID for better performance and consistency with WordPress coding standards.

-  * @since x.x
+  * @since 6.17 /* or whatever the actual version is */

Also, in line 444:

- return $form_action->post_excerpt === 'email' && ! get_user_meta( wp_get_current_user()->ID, 'frm_dismiss_default_email_message', true );
+ return $form_action->post_excerpt === 'email' && ! get_user_meta( get_current_user_id(), 'frm_dismiss_default_email_message', true );
classes/controllers/FrmFormsController.php (1)

2527-2542: Update the version placeholder and add permission check

Similar to the previous file, the @since x.x should be updated with the actual version number.

Additionally, while there is a nonce check for CSRF protection, it would be more secure to explicitly check if the user has the permission to edit forms using current_user_can('frm_edit_forms').

-  * @since x.x
+  * @since 6.17 /* or whatever the actual version is */

   public static function dismiss_default_email_message() {
       $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );

       if ( $permission_error !== false ) {
           wp_send_json_error( $permission_error, 403 );
       }
+      if ( ! current_user_can( 'frm_edit_forms' ) ) {
+          wp_send_json_error( __( 'You do not have permission to perform this action.', 'formidable' ), 403 );
+      }
       update_user_meta( get_current_user_id(), 'frm_dismiss_default_email_message', 1 );
       wp_send_json_success();
   }
js/admin/settings.js (1)

25-39: Add missing semicolon in the .then() callback

The code for handling the dismiss default email message click event is well structured, but there's a missing semicolon after the callback function in the .then() method.

   doJsonPost( 'dismiss_default_email_message', formData ).then( () => {
-      e.target.closest( '.frm_default_email_message' ).remove();
+      e.target.closest( '.frm_default_email_message' ).remove();
   }

Also, consider enhancing the error handling to provide user feedback rather than just logging to the console.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aebe6d4 and ffce5eb.

📒 Files selected for processing (4)
  • classes/controllers/FrmFormActionsController.php (1 hunks)
  • classes/controllers/FrmFormsController.php (1 hunks)
  • classes/views/frm-form-actions/_action_inside.php (1 hunks)
  • js/admin/settings.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • classes/views/frm-form-actions/_action_inside.php
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: Cypress
🔇 Additional comments (2)
js/admin/settings.js (2)

3-4: Good code structure for importing Ajax functionality

The explicit import of doJsonPost from frmDom.ajax is a good practice for clarity and maintainability.


8-8: Well-integrated event listener

The addition of the click event listener follows the existing pattern in the file, making it consistent with the rest of the code.

@AbdiTolesa AbdiTolesa requested a review from Crabcyborg March 10, 2025 09:05
@Crabcyborg Crabcyborg modified the milestones: 6.20, 6.21 Apr 2, 2025
@Crabcyborg Crabcyborg removed the request for review from lauramekaj1 May 2, 2025 14:58
@Crabcyborg Crabcyborg modified the milestones: 6.21, 6.22 May 9, 2025
@Crabcyborg Crabcyborg modified the milestones: 6.22, 6.23 Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants