Skip to content

Enhance/select email for customer without name - #177

Open
dev-shahed wants to merge 4 commits into
developfrom
enhance/select-email-for-customer-without-name
Open

Enhance/select email for customer without name#177
dev-shahed wants to merge 4 commits into
developfrom
enhance/select-email-for-customer-without-name

Conversation

@dev-shahed

@dev-shahed dev-shahed commented Jun 18, 2025

Copy link
Copy Markdown
Member

📄 Description

This PR improves the customer search input behavior by ensuring that:

  • If first name and last name are missing or empty, the customer’s email is used as a fallback.

  • This fallback works consistently when:

    • Selecting a customer from search results.
    • Creating a new customer.
    • Populating the input when an existing order is loaded.

A helper method getCustomerDisplayName is added to handle this logic in a single place, ensuring consistent formatting.


🔍 Changes

  • Added getCustomerDisplayName method.
  • Updated watch and selectCustomer to use the fallback.
  • Minor variable cleanup for better readability.
  • No changes to existing core logic.
  • After adding a customer successfully, a success message appears via an alert

🧪 Testing

  • Verified that when only email is present, it appears in the input.
  • Verified that when the first or last name is present, they appear properly.
  • Verified that fallback works when loading a saved order.

📌 Related Issue

https://github.com/getdokan/plugin-internal-tasks/issues/398


Checklist

  • Code follows existing conventions.
  • Tested locally in various scenarios.
  • Does not break existing customer selection flow.

Summary by CodeRabbit

  • New Features

    • Display name for customers now intelligently combines first name, last name, or email for improved clarity.
    • Success alert message is shown after creating a new customer.
  • Refactor

    • Customer display names are now consistently generated using a new method for improved formatting throughout the interface.

@dev-shahed dev-shahed added Enhancement Enhancement request Needs Dev Review This PR needs review by a developer labels Jun 18, 2025
@coderabbitai

coderabbitai Bot commented Jun 18, 2025

Copy link
Copy Markdown

Walkthrough

A new method, getCustomerDisplayName, was introduced in the CustomerSearch.vue component to standardize the formatting of customer display names. All previous instances of manually concatenating customer names were updated to use this method. Additionally, a success alert is now shown after creating a customer.

Changes

File Change Summary
assets/src/frontend/components/CustomerSearch.vue Added getCustomerDisplayName method; replaced name concatenations with this method; added alert after customer creation.

Poem

A bunny hopped through code today,
Tidying names the streamlined way.
With one new method, crisp and neat,
Customer display is now a treat!
And when a customer’s made anew,
A cheerful alert hops into view. 🐇✨


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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
assets/src/frontend/components/CustomerSearch.vue (3)

290-294: Helper looks good – tiny simplification available

The logic is sound and the ternary nicely handles trimming, but a small rewrite removes one optional–chaining edge case and reads a bit cleaner:

-return (first_name?.trim() || last_name?.trim())
-    ? `${(first_name || '').trim()} ${(last_name || '').trim()}`.trim()
-    : (email || '');
+const name = `${(first_name || '').trim()} ${(last_name || '').trim()}`.trim();
+return name ? name : (email || '');

326-331: Avoid blocking alert; use existing notification utility

window.alert freezes the UI and feels out of place in SPA flows.
If wepos already has a toast / notice component (as it does elsewhere), leverage that instead.

- alert( this.__( 'Customer created successfully', 'wepos' ) );
+ this.$notify?.success?.(
+     this.__( 'Customer created successfully', 'wepos' )
+ );

33-37: Search-result label can reuse the new helper

To keep the fallback logic identical between the input field and the dropdown list, consider:

- <span class="name wepos-left">{{ customer.first_name + ' ' + customer.last_name }}
+ <span class="name wepos-left">{{ getCustomerDisplayName(customer.first_name, customer.last_name, customer.email) }}

This avoids rendering an empty space when both names are absent.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between babdb26 and c5a75a9.

📒 Files selected for processing (1)
  • assets/src/frontend/components/CustomerSearch.vue (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: e2e_api tests
🔇 Additional comments (1)
assets/src/frontend/components/CustomerSearch.vue (1)

297-299: Consistent usage – nice!

Replacing the previous manual concatenation with getCustomerDisplayName keeps the behaviour in one place and prevents future drift.

Comment on lines 381 to 384
var orderdata = JSON.parse( localStorage.getItem( 'orderdata' ) );

if ( orderdata.customer_id != 'undefined' && orderdata.customer_id != 0 ) {
this.serachInput = orderdata.billing.first_name + ' ' + orderdata.billing.last_name;
this.serachInput = this.getCustomerDisplayName(orderdata.billing.first_name, orderdata.billing.last_name, orderdata.billing.email);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Same undefined-billing guard needed here

orderdata.billing is accessed directly in created(). Mirror the defensive guard added to the watcher to prevent a startup crash.

🤖 Prompt for AI Agents
In assets/src/frontend/components/CustomerSearch.vue around lines 381 to 384,
the code accesses orderdata.billing directly without checking if
orderdata.billing is defined, which can cause a startup crash. Add a defensive
check to ensure orderdata.billing exists before accessing its properties,
similar to the guard used in the watcher, to prevent errors when billing is
undefined.

Comment on lines 228 to 232
'orderdata.customer_id'(newVal) {
this.serachInput = newVal ? this.orderdata.billing.first_name + ' ' + this.orderdata.billing.last_name : '';
this.serachInput = newVal ? this.getCustomerDisplayName(this.orderdata.billing.first_name, this.orderdata.billing.last_name, this.orderdata.billing.email) : '';
}

},

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

Potential TypeError when orderdata.billing is missing

this.orderdata.billing is dereferenced without a null-check.
When the order arrives from an endpoint where the billing object is not yet populated, the watcher will throw (Cannot read property 'first_name' of undefined) and break reactivity.

- this.serachInput = newVal ? this.getCustomerDisplayName(this.orderdata.billing.first_name, this.orderdata.billing.last_name, this.orderdata.billing.email) : '';
+const billing = this.orderdata.billing || {};
+this.serachInput = newVal
+    ? this.getCustomerDisplayName(billing.first_name, billing.last_name, billing.email)
+    : '';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'orderdata.customer_id'(newVal) {
this.serachInput = newVal ? this.orderdata.billing.first_name + ' ' + this.orderdata.billing.last_name : '';
this.serachInput = newVal ? this.getCustomerDisplayName(this.orderdata.billing.first_name, this.orderdata.billing.last_name, this.orderdata.billing.email) : '';
}
},
'orderdata.customer_id'(newVal) {
const billing = this.orderdata.billing || {};
this.serachInput = newVal
? this.getCustomerDisplayName(billing.first_name, billing.last_name, billing.email)
: '';
}
},
🤖 Prompt for AI Agents
In assets/src/frontend/components/CustomerSearch.vue around lines 228 to 232,
the watcher accesses this.orderdata.billing without checking if billing exists,
which can cause a TypeError if billing is undefined. To fix this, add a
null-check to ensure this.orderdata.billing is defined before accessing its
properties. If billing is missing, set this.serachInput to an empty string or a
safe default to prevent errors and maintain reactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Enhancement request Needs Dev Review This PR needs review by a developer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant