Skip to content
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

Added commission settings sub-categories reset toggle. #2543

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Aunshon
Copy link
Collaborator

@Aunshon Aunshon commented Jan 29, 2025

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Enhanced category commission experience.

Related Pull Request(s)

Closes

Changelog entry

- **update:** Category commission experience in Dokan commission settings.

Summary by CodeRabbit

  • New Features

    • Introduced a new setting that lets you determine whether updating a parent category’s commission automatically resets subcategory commissions.
    • Added interactive confirmation dialogs and toggle switches to guide users through applying these commission settings.
  • UI Improvements

    • Enhanced commission and vendor management interfaces with clear tooltips and intuitive controls for a smoother configuration experience.

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as off-topic.

coderabbitai[bot]

This comment was marked as off-topic.

@Aunshon Aunshon self-assigned this Jan 30, 2025
@Aunshon Aunshon changed the title added commission sub-categories reset toggle. Added commission settings sub-categories reset toggle. Jan 30, 2025
@Aunshon Aunshon added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jan 30, 2025
<label class="!p-0 m-0 !mb-[6px] block" for="_subscription_product_admin_commission_type">
{{__( 'Apply Parent Category Commission to All Subcategories ', 'dokan-lite' )}}

<span class="dokan-tooltips-help tips" v-tooltip :title="__( 'When enabled, changing a parent category\'s commission rate will automatically update all its subscription. Disable this option to maintain independent commission rates for subcategories', 'dokan-lite' )">
Copy link
Member

Choose a reason for hiding this comment

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

subscription might be typo?

@mrabbani mrabbani added Needs: Author Reply and removed Needs: Dev Review It requires a developer review and approval labels Feb 7, 2025
@Aunshon Aunshon added Needs: Dev Review It requires a developer review and approval and removed Needs: Author Reply labels Feb 13, 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

🔭 Outside diff range comments (1)
src/admin/components/VendorCommissionFields.vue (1)

88-88: 🛠️ Refactor suggestion

Add error handling for external dependencies.

The code assumes window.dokanAdmin and SweetAlert are always available. Consider adding error handling:

 created() {
-    this.commissionTypes = window.dokanAdmin.commission_types ?? {};
+    try {
+        if (!window.dokanAdmin) {
+            throw new Error('dokanAdmin not initialized');
+        }
+        this.commissionTypes = window.dokanAdmin.commission_types ?? {};
+    } catch (error) {
+        console.error('Failed to initialize commission types:', error);
+        this.commissionTypes = {};
+    }
 }

 handleResetToggle(value) {
+    if (typeof Swal === 'undefined') {
+        console.error('SweetAlert not loaded');
+        this.resetSubCategory = value;
+        this.vendorInfo.reset_sub_category = value;
+        return;
+    }
     // ... rest of the method
 }

Also applies to: 126-139

♻️ Duplicate comments (1)
src/admin/components/VendorCommissionFields.vue (1)

19-20: ⚠️ Potential issue

Fix incorrect label attributes and text.

The label's for attribute references _subscription_product_admin_commission_type which seems incorrect for this context. This appears to be copied from another section.

Apply this diff to fix the label:

-<label class="!p-0 m-0 !mb-[6px] block" for="_subscription_product_admin_commission_type">
+<label class="!p-0 m-0 !mb-[6px] block" for="reset_sub_category_toggle">
🧹 Nitpick comments (3)
src/admin/components/VendorCommissionFields.vue (3)

39-39: Add prop validation for resetSubCategory.

Consider adding prop validation to ensure type safety.

 <category-based-commission
     :value="categoryCommission"
     @change="onCategoryUpdate"
     :resetSubCategory="resetSubCategory"
 />

In the CategoryBasedCommission component, add:

props: {
  resetSubCategory: {
    type: Boolean,
    required: true
  }
}

119-139: Improve code clarity and maintainability.

Consider the following improvements:

  1. Extract SweetAlert strings to constants
  2. Rename updatableValue to currentValue for clarity
  3. Remove unnecessary self variable since arrow functions preserve this
 handleResetToggle(value) {
-    const confirmTitle = value ? this.__("Enable Commission Inheritance Setting?", "dokan-lite") : this.__("Disable Commission Inheritance Setting?", "dokan-lite");
-    const htmlText = value ? this.__("Parent category commission changes will automatically update all subcategories. Existing rates will remain unchanged until parent category is modified.", "dokan-lite") : this.__("Subcategories will maintain their independent commission rates when parent category rates are changed.", "dokan-lite");
-    const confirmBtnText = value ? this.__("Enable", "dokan-lite") : this.__("Disable", "dokan-lite");
-    const updatableValue = !value;
-    const self = this;
+    const ALERT_TEXTS = {
+      enable: {
+        title: this.__("Enable Commission Inheritance Setting?", "dokan-lite"),
+        html: this.__("Parent category commission changes will automatically update all subcategories. Existing rates will remain unchanged until parent category is modified.", "dokan-lite"),
+        confirm: this.__("Enable", "dokan-lite")
+      },
+      disable: {
+        title: this.__("Disable Commission Inheritance Setting?", "dokan-lite"),
+        html: this.__("Subcategories will maintain their independent commission rates when parent category rates are changed.", "dokan-lite"),
+        confirm: this.__("Disable", "dokan-lite")
+      }
+    };
+    const currentValue = !value;
+    const texts = value ? ALERT_TEXTS.enable : ALERT_TEXTS.disable;

     Swal.fire({
         icon: "warning",
-        html: htmlText,
-        title: confirmTitle,
+        html: texts.html,
+        title: texts.title,
         showCancelButton: true,
         cancelButtonText: this.__("Cancel", "dokan-lite"),
-        confirmButtonText: confirmBtnText
-    }).then((response) => {
-        const status = response.isConfirmed ? value : updatableValue;
-        self.resetSubCategory = status;
-
-        self.vendorInfo.reset_sub_category = status;
+        confirmButtonText: texts.confirm
+    }).then(({ isConfirmed }) => {
+        const status = isConfirmed ? value : currentValue;
+        this.resetSubCategory = status;
+        this.vendorInfo.reset_sub_category = status;
     });
 }

111-113: Simplify initialization logic.

The current initialization uses a double negative and verbose property check.

-if ( this.vendorInfo.hasOwnProperty( 'reset_sub_category' ) ) {
-    this.resetSubCategory = this.vendorInfo.reset_sub_category !== false;
-}
+this.resetSubCategory = this.vendorInfo?.reset_sub_category ?? true;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 695bf30 and ad072ac.

📒 Files selected for processing (1)
  • src/admin/components/VendorCommissionFields.vue (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: e2e tests (3, 3)
  • GitHub Check: e2e tests (2, 3)
  • GitHub Check: e2e tests (1, 3)
  • GitHub Check: api tests (1, 1)
🔇 Additional comments (2)
src/admin/components/VendorCommissionFields.vue (2)

22-24: LGTM! Clear and informative tooltip.

The tooltip effectively explains the feature's behavior and implications.


66-165: Add unit tests for the new feature.

Consider adding tests to verify:

  1. Toggle initialization with different vendor info states
  2. Toggle interaction and state updates
  3. SweetAlert dialog interactions
  4. Error handling for missing dependencies

Would you like me to generate a test suite for this component?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants