Skip to content

Fix/redirection for new individual signup for pu visit#311

Merged
nishant22029 merged 14 commits intodevelopfrom
fix/redirection-for-new-individual-signup-for-pu-visit
Oct 2, 2024
Merged

Fix/redirection for new individual signup for pu visit#311
nishant22029 merged 14 commits intodevelopfrom
fix/redirection-for-new-individual-signup-for-pu-visit

Conversation

@nishant22029
Copy link
Copy Markdown
Collaborator

@nishant22029 nishant22029 commented Oct 2, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced user redirection logic for improved navigation based on interaction purpose.
    • Added query parameters for better tracking during user interactions.
    • Improved organization and management of tab configurations within the collection camp interface.
  • Bug Fixes

    • Improved functionality for user identification forms and individual creation processes.
  • Chores

    • Enhanced logging for better data flow tracking during user registration.

@nishant22029 nishant22029 self-assigned this Oct 2, 2024
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Oct 2, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces significant modifications to the CollectionCampService class in the Civi namespace and the functions.php file of the Goonj CRM theme. In CollectionCampService, the collectionCampTabset method has been refactored to utilize an associative array for tab configurations, enhancing organization and management. Changes in functions.php focus on improving user redirection logic by dynamically including organization names based on registration purposes and refining the redirection process for individual registrations.

Changes

File Path Change Summary
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php - Refactored collectionCampTabset to use an associative array for tab configurations.
- Updated logic in setIndianStateOptions to filter state options based on entity type.
wp-content/themes/goonj-crm/functions.php - Enhanced user redirection logic with organization names for specific registration purposes.
- Modified goonj_redirect_after_individual_creation to include Individual_fields.Source_Processing_Center in redirection logic.

Possibly related PRs

Suggested labels

in review

Suggested reviewers

  • pokhiii

Poem

In the land of Goonj where users roam,
New paths have opened, leading them home.
With sources and fields, their journeys are clear,
Each click and each form brings them near.
So hop along, let the data flow,
For every new change helps the users grow! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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
Copy Markdown

@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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a00e6e3 and 50d4395.

📒 Files selected for processing (1)
  • wp-content/themes/goonj-crm/functions.php (3 hunks)
🔇 Additional comments (1)
wp-content/themes/goonj-crm/functions.php (1)

238-242: Verify the correctness of URL parameters in the redirect.

Ensure that the values passed to the sprintf function match the expected URL parameters. Specifically, confirm that:

  • The 'source' parameter is correctly assigned 'pu-visit'.
  • The 'Individual_fields.Creation_Flow' parameter is assigned 'office-visit'.
  • The 'Individual_fields.Source_Processing_Center' parameter is assigned $target_id.

It's important to verify that these values are correctly mapped to prevent any unintended behavior during redirection.

Comment on lines +443 to +459
\Civi::log()->info('check',['cjec']);
$individual = \Civi\Api4\Contact::get( false )
->addSelect( 'source', 'Individual_fields.Creation_Flow', 'email.email', 'phone.phone' )
->addSelect( 'source', 'Individual_fields.Creation_Flow', 'email.email', 'phone.phone', 'Individual_fields.Source_Processing_Center' )
->addJoin( 'Email AS email', 'LEFT' )
->addJoin( 'Phone AS phone', 'LEFT' )
->addWhere( 'email.is_primary', '=', true )
->addWhere( 'phone.is_primary', '=', true )
->addWhere( 'id', '=', absint( $_GET['individualId'] ) )
->setLimit( 1 )
->execute()->single();

\Civi::log()->info('check2',['cjec2'=>$individual]);
$creationFlow = $individual['Individual_fields.Creation_Flow'];
$source = $individual['source'];
$sourceProcessingCenter = $individual['Individual_fields.Source_Processing_Center'];
// var_dump($creationFlow);
// var_dump($source);
// die;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Remove debugging statements and commented-out code for clean production code.

The code contains debugging statements and commented-out code that should be removed before deploying to production:

  • Logging statements with non-descriptive messages:

    \Civi::log()->info('check',['cjec']);
    \Civi::log()->info('check2',['cjec2'=>$individual]);
  • Commented-out debug code:

    // var_dump($creationFlow);
    // var_dump($source);
    // die;

Removing these will clean up the code and prevent unnecessary logging.

Apply this diff to remove the debugging code:

-\Civi::log()->info('check',['cjec']);
 $individual = \Civi\Api4\Contact::get( false )
     ->addSelect( 'source', 'Individual_fields.Creation_Flow', 'email.email', 'phone.phone', 'Individual_fields.Source_Processing_Center' )
     ->addJoin( 'Email AS email', 'LEFT' )
     ->addJoin( 'Phone AS phone', 'LEFT' )
     ->addWhere( 'email.is_primary', '=', true )
     ->addWhere( 'phone.is_primary', '=', true )
     ->addWhere( 'id', '=', absint( $_GET['individualId'] ) )
     ->setLimit( 1 )
     ->execute()->single();
-\Civi::log()->info('check2',['cjec2'=>$individual]);
 $creationFlow = $individual['Individual_fields.Creation_Flow'];
 $source = $individual['source'];
 $sourceProcessingCenter = $individual['Individual_fields.Source_Processing_Center'];
-// var_dump($creationFlow);
-// var_dump($source);
-// die;

Comment on lines +488 to +497
case 'office-visit':
$redirectPath = sprintf(
'/processing-center/office-visit/details/#?email=%s&phone=%s&Office_Visit.Goonj_Processing_Center=%s&source_contact_id=%s',
$email,
$phone,
$sourceProcessingCenter,
$individual['id']
);
break;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue

Initialize $email and $phone before using them in the redirect.

In the 'office-visit' case, the variables $email and $phone are used in the sprintf function but are not defined in the current scope, which will cause undefined variable errors.

Assign $email and $phone from the $individual array before using them:

$email = $individual['email.email'];
$phone = $individual['phone.phone'];

Apply this diff to fix the issue:

+        $email = $individual['email.email'];
+        $phone = $individual['phone.phone'];

         case 'office-visit':
             $redirectPath = sprintf(
                 '/processing-center/office-visit/details/#?email=%s&phone=%s&Office_Visit.Goonj_Processing_Center=%s&source_contact_id=%s',
                 $email,
                 $phone,
                 $sourceProcessingCenter,
                 $individual['id']
             );
             break;

@nishant22029 nishant22029 requested a review from pokhiii October 2, 2024 08:25
Nishant Kumar added 5 commits October 2, 2024 14:11
Copy link
Copy Markdown

@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

🧹 Outside diff range and nitpick comments (6)
wp-content/themes/goonj-crm/functions.php (3)

226-230: LGTM! Consider using constants for flow values.

The changes improve the tracking of user registration sources by adding 'source' and 'Individual_fields.Creation_Flow' parameters. This is a good enhancement for better data collection and user flow tracking.

Consider defining constants for the 'Individual_fields.Creation_Flow' values ('pu-visit-contribution' and 'office-visit-contribution') to improve code maintainability and reduce the risk of typos. For example:

define('CREATION_FLOW_PU_VISIT_CONTRIBUTION', 'pu-visit-contribution');
define('CREATION_FLOW_OFFICE_VISIT_CONTRIBUTION', 'office-visit-contribution');

// Then use them in the code:
'Individual_fields.Creation_Flow=%s',
CREATION_FLOW_PU_VISIT_CONTRIBUTION,

240-244: LGTM! Consider using constants for flow values (continued).

The changes in this segment are consistent with the previous improvements, adding 'source' and 'Individual_fields.Creation_Flow' parameters for better tracking of office visit registrations.

As suggested earlier, consider defining constants for the 'Individual_fields.Creation_Flow' values ('pu-visit' and 'office-visit') to improve code maintainability. For example:

define('CREATION_FLOW_PU_VISIT', 'pu-visit');
define('CREATION_FLOW_OFFICE_VISIT', 'office-visit');

// Then use them in the code:
'Individual_fields.Creation_Flow=%s',
CREATION_FLOW_PU_VISIT,

Line range hint 447-504: LGTM with a minor issue. Initialize $email and $phone variables.

The changes improve the flexibility of the redirection logic by adding new cases for 'office-visit' and 'office-visit-contribution'. The addition of 'Individual_fields.Source_Processing_Center' to the API query allows for more detailed tracking of individual registrations.

However, there's a potential issue in the new cases. The variables $email and $phone are used but not defined. To fix this, initialize these variables before using them:

 $creationFlow = $individual['Individual_fields.Creation_Flow'];
 $source = $individual['source'];
 $sourceProcessingCenter = $individual['Individual_fields.Source_Processing_Center'];
+$email = $individual['email.email'];
+$phone = $individual['phone.phone'];

 if ( ! $source ) {
     return;
 }

This will ensure that $email and $phone are properly defined before being used in the sprintf calls.

wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (3)

Line range hint 486-489: Check for null before accessing $stateField['id'] to prevent potential errors

In setIndianStateOptions, if $intentStateFields->first() returns NULL, accessing $stateField['id'] will result in a fatal error. To prevent this, add a null check for $stateField before accessing its properties.

Apply this diff to add the null check:

$stateField = $intentStateFields->first();

+ if (!$stateField) {
+     return;
+ }

$statefieldId = $stateField['id'];

92-93: Ensure consistent naming conventions for directive names

In the 'campOutcome' tab configuration, the directive name 'afform-admin-Camp-outcome-form' uses an uppercase 'C' in 'Camp'. For consistency with other directives and to prevent potential issues, consider changing it to use lowercase:

Apply this diff to update the directive name:

- 'directive' => 'afform-admin-Camp-outcome-form',
+ 'directive' => 'afform-admin-camp-outcome-form',

Line range hint 486-508: Handle potential empty results when fetching Indian states

In setIndianStateOptions, after fetching Indian states, it's possible that $indianStates could be empty. Consider adding a check to handle this scenario to prevent unexpected behavior.

Apply this diff to handle empty state results:

$indianStates = StateProvince::get(FALSE)
  ->addWhere('country_id.iso_code', '=', 'IN')
  ->addOrderBy('name', 'ASC')
  ->execute();

+ if ($indianStates->count() === 0) {
+     return;
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 50d4395 and ce7a827.

📒 Files selected for processing (2)
  • wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (1 hunks)
  • wp-content/themes/goonj-crm/functions.php (5 hunks)
🔇 Additional comments (2)
wp-content/civi-extensions/goonjcustom/Civi/CollectionCampService.php (2)

110-110: Ensure modules are correctly loaded in AngularJS

When adding modules using addModules($config['module']), ensure that the module names are accurately specified and that the corresponding AngularJS modules exist. This prevents potential errors during runtime due to missing or incorrectly named modules.


91-91: Verify that the module name is correctly registered

Ensure that the module 'afformAdminCampOutcomeForm' is correctly registered and loaded in the AngularJS application. Inconsistent naming or incorrect module registration can lead to runtime errors.

Run the following script to search for the module definition:


$creationFlow = $individual['Individual_fields.Creation_Flow'];
$source = $individual['source'];
$sourceProcessingCenter = $individual['Individual_fields.Source_Processing_Center'];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

let's move this variable inside the cases where we needed it (case 'office-visit' and case 'office-visit-contribution')

@nishant22029 nishant22029 force-pushed the fix/redirection-for-new-individual-signup-for-pu-visit branch from ce7a827 to e342662 Compare October 2, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants