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

dialog-subscription #152

Merged
merged 2 commits into from
Feb 25, 2025
Merged

dialog-subscription #152

merged 2 commits into from
Feb 25, 2025

Conversation

huynhlephcvinh
Copy link
Collaborator

@huynhlephcvinh huynhlephcvinh commented Feb 24, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an interactive subscription dialog that appears when a building is activated. The dialog displays building details and offers an intuitive form for selecting subscription duration and device limits with proper validation.
  • Documentation
    • Enhanced multilingual support for subscription interactions with updated texts displayed in English, Vietnamese, and Chinese.

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

The pull request introduces a building subscription feature. A new click event in the enterprise buildings component triggers a method that opens a subscription dialog. A dedicated modal component, along with accompanying TypeScript logic and HTML template, is implemented to handle user input for subscription details. Additionally, a new Subscription interface is added; the shared module is updated to include PrimeNG components; minor comments in a building service hint at future improvements; and multi-language support is provided via updated i18n JSON files.

Changes

File(s) Change Summary
.../components/buildings/buildings.component.html
.../components/buildings/buildings.component.ts
Added a new click event (click)="openDialog(building)", integrated the openDialog(building) method for dialog interactions, and updated component properties to manage subscription details.
.../models/enterprise.dto.ts Introduced a new Subscription interface extending BaseDTO with properties: numberOfMonths, numberOfDevices, and idBuilding.
.../dialog/building-subcription-dialog/building-subcription-dialog.component.html
.../dialog/building-subcription-dialog/building-subcription-dialog.component.ts
Created a new modal dialog component for managing building subscriptions, including form inputs, validations, open/close methods, and API interactions.
.../shared/shared.module.ts Updated module declarations and exports to include the new subscription dialog component; added PrimeNG modules (InputNumber, Checkbox).
.../services/building.service.ts Included comment lines suggesting the future addition of address handling via Goong Maps.
.../assets/i18n/en.json
.../assets/i18n/vi.json
.../assets/i18n/zh.json
Added new "dialog" sections with subscription-related UI text for English, Vietnamese, and Chinese localizations.

Suggested labels

user story

Suggested reviewers

  • thongdanghoang
  • GiaBaorr
  • nganntqe170236

Poem

I'm a hopping rabbit, full of cheer,
A new subscription dialog is finally here.
Clicks and modals dance in code's light,
Forms and validations taking flight.
In Angular meadows, our changes bloom,
Bouncing with joy in every room!
🐰🌟

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

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

🧹 Nitpick comments (5)
sep490-frontend/src/app/modules/enterprise/models/enterprise.dto.ts (1)

26-30: LGTM! Consider adding JSDoc comments.

The Subscription interface is well-structured with appropriate field types. Consider adding JSDoc comments to document the purpose of each field and any constraints (e.g., valid ranges for numbers).

+/**
+ * Represents a building subscription.
+ */
 export interface Subscription extends BaseDTO {
+  /** Number of months for the subscription (must be positive) */
   numberOfMonths: number;
+  /** Maximum number of devices allowed (must be positive) */
   numberOfDevices: number;
+  /** UUID of the associated building */
   idBuilding: UUID;
 }
sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.html (1)

9-13: Replace hardcoded avatar URL with a configurable value.

The avatar image URL is hardcoded, which is not maintainable. Consider moving it to a configuration file or service.

sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.ts (1)

93-95: Add error handling to dialog opening.

The showDialog method should handle potential errors when opening the dialog. Also, consider making the building parameter non-nullable for type safety.

-showDialog(building: Building): void {
+showDialog(building: Building): void {
+  try {
     this.subscriptionDialog.openDialog(building);
+  } catch (error) {
+    console.error('Failed to open subscription dialog:', error);
+    // Handle error appropriately
+  }
 }
sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.ts (2)

32-44: Enhance form structure with type safety and comprehensive validation.

The form structure could be improved with:

  1. Type-safe form controls using TypeScript's strict typing
  2. More comprehensive validation rules
  3. Custom error messages for validation failures

Consider applying these improvements:

  protected readonly formStructure = {
-   id: new FormControl(''),
-   version: new FormControl(null),
+   id: new FormControl<string>(''),
+   version: new FormControl<number | null>(null),
    numberOfMonths: new FormControl(0, {
      nonNullable: true,
-     validators: [Validators.min(1), Validators.max(100), Validators.required]
+     validators: [
+       Validators.min(1),
+       Validators.max(100),
+       Validators.required,
+       Validators.pattern(/^\d+$/)
+     ]
    }),
    numberOfDevices: new FormControl(0, {
      nonNullable: true,
-     validators: [Validators.min(100), Validators.required]
+     validators: [
+       Validators.min(100),
+       Validators.required,
+       Validators.pattern(/^\d+$/)
+     ]
    }),
-   idBuilding: new FormControl('')
+   idBuilding: new FormControl<string>('', [Validators.required])
  };

Add validation error messages in the template:

getErrorMessage(controlName: string): string {
  const control = this.formGroup.get(controlName);
  if (!control?.errors) return '';

  if (control.errors['required']) return 'This field is required';
  if (control.errors['min']) return `Minimum value is ${control.errors['min'].min}`;
  if (control.errors['max']) return `Maximum value is ${control.errors['max'].max}`;
  if (control.errors['pattern']) return 'Please enter a valid number';
  
  return 'Invalid value';
}

45-56: Maintain consistency in service declarations.

Some services are marked as readonly while others aren't. Consider applying readonly consistently to all injected services for better immutability guarantees.

  constructor(
-   httpClient: HttpClient,
-   formBuilder: FormBuilder,
-   notificationService: MessageService,
+   private readonly httpClient: HttpClient,
+   private readonly formBuilder: FormBuilder,
+   private readonly notificationService: MessageService,
    private readonly buildingService: BuildingService,
    private readonly walletService: WalletService,
-   translate: TranslateService,
+   private readonly translate: TranslateService,
    private readonly router: Router,
    private readonly activatedRoute: ActivatedRoute
  ) {
    super(httpClient, formBuilder, notificationService, translate);
  }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8f89909 and 48b4c23.

📒 Files selected for processing (10)
  • sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.html (2 hunks)
  • sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.ts (4 hunks)
  • sep490-frontend/src/app/modules/enterprise/models/enterprise.dto.ts (2 hunks)
  • sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.html (1 hunks)
  • sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.ts (1 hunks)
  • sep490-frontend/src/app/modules/shared/shared.module.ts (3 hunks)
  • sep490-frontend/src/app/services/building.service.ts (1 hunks)
  • sep490-frontend/src/assets/i18n/en.json (1 hunks)
  • sep490-frontend/src/assets/i18n/vi.json (1 hunks)
  • sep490-frontend/src/assets/i18n/zh.json (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • sep490-frontend/src/app/services/building.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build Java Modules (sep490-enterprise)
🔇 Additional comments (6)
sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.html (1)

130-131: LGTM! Clean integration of subscription dialog.

The subscription dialog is well-integrated into the building component template. The click handler and dialog component are properly implemented.

Also applies to: 139-141

sep490-frontend/src/app/modules/shared/shared.module.ts (2)

102-103: LGTM! Component properly declared and exported.

The BuildingSubcriptionDialogComponent is correctly declared and exported in the SharedModule.

Also applies to: 116-117


105-105: LGTM! PrimeNG modules properly imported.

The InputNumber and Checkbox modules are correctly imported and added to the module's imports array.

sep490-frontend/src/assets/i18n/en.json (1)

237-257: LGTM! Well-structured i18n translations.

The subscription dialog translations are:

  • Well-organized with clear sections (header, body, footer)
  • Using consistent naming conventions
  • Properly implementing dynamic placeholders
sep490-frontend/src/assets/i18n/vi.json (1)

237-257: LGTM! Consistent Vietnamese translations.

The Vietnamese translations for the subscription dialog:

  • Match the structure of the English translations
  • Maintain proper placeholder usage
  • Use culturally appropriate language
sep490-frontend/src/assets/i18n/zh.json (1)

237-257: LGTM! Consistent Chinese translations.

The Chinese translations for the subscription dialog:

  • Match the structure of other language files
  • Maintain proper placeholder usage
  • Use appropriate Chinese characters and terminology

Copy link

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

🧹 Nitpick comments (1)
sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.html (1)

100-110: Add null checks for form control values.

The string interpolation could fail if form controls are null. Use the nullish coalescing operator or safe navigation operator.

-  numberOfMonths: formGroup.get("numberOfMonths")?.value,
-  numberOfDevices: formGroup.get("numberOfDevices")?.value,
+  numberOfMonths: formGroup.get("numberOfMonths")?.value ?? 0,
+  numberOfDevices: formGroup.get("numberOfDevices")?.value ?? 0,
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 48b4c23 and 7bb0339.

📒 Files selected for processing (4)
  • sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.html (1 hunks)
  • sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.ts (4 hunks)
  • sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.html (1 hunks)
  • sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • sep490-frontend/src/app/modules/enterprise/components/buildings/buildings.component.html
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build Java Modules (sep490-enterprise)
🔇 Additional comments (3)
sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.html (1)

42-59: Add min/max validation for number inputs.

The number inputs lack constraints. Add min/max validation to prevent invalid values.

Also applies to: 70-87

sep490-frontend/src/app/modules/shared/components/dialog/building-subcription-dialog/building-subcription-dialog.component.ts (2)

16-21: Fix typo in component name and selector.

The component name contains a typo: "Subcription" should be "Subscription".


58-68: Implement required abstract methods.

The abstract methods are incomplete and need proper implementation.

@huynhlephcvinh huynhlephcvinh merged commit 4ddb062 into main Feb 25, 2025
8 checks passed
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.

2 participants