Skip to content

Conversation

sunilsabatp
Copy link
Contributor

Utilize the useApi() hook for api call.
pages covered :

  1. /profile/donation-link
  2. /profile/edit
  3. /profile/history

Copy link

vercel bot commented Mar 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
planet-webapp-multi-tenancy-setup ✅ Ready (Inspect) Visit Preview Apr 4, 2025 5:48am

Copy link
Contributor

coderabbitai bot commented Mar 25, 2025

Walkthrough

This pull request updates several components by replacing older API functions with new counterparts from the useApi hook. In the Account History component, the obsolete logoutUser parameter and the getAuthenticatedRequest function are removed in favor of the streamlined getApiAuthenticated function. Similarly, the Edit Profile form now includes new type definitions and uses putApiAuthenticated for profile updates. The Donation Link component is updated to replace getRequest with getApi for fetching project data. These changes simplify API call parameters and enhance type safety in user-related functionalities.

Changes

Files Change Summary
pages/.../profile/history.tsx Removed logoutUser from useUserProps; replaced getAuthenticatedRequest with getApiAuthenticated for payment history API calls
src/features/.../EditProfileForm.tsx Added new types (UserType, UserProfileImage, UpdateProfileApiPayload); updated function signatures to use putApiAuthenticated for updates
src/features/.../DonationLink/index.tsx Replaced getRequest with getApi; updated import to use the useApi hook for fetching and filtering the project list

Sequence Diagram(s)

sequenceDiagram
    participant AH as AccountHistory Component
    participant UA as useApi Hook
    participant API as Backend API

    AH->>UA: Call getApiAuthenticated(url)
    UA->>API: Request Payment History Data
    API-->>UA: Return Payment History Data
    UA-->>AH: Deliver Payment History Data
Loading
sequenceDiagram
    participant EP as EditProfileForm Component
    participant UA as useApi Hook
    participant API as Backend API

    EP->>UA: Call putApiAuthenticated(payload) for profile update/image
    UA->>API: Send profile update request
    API-->>UA: Return update confirmation
    UA-->>EP: Deliver update confirmation
Loading
sequenceDiagram
    participant DL as DonationLink Component
    participant UA as useApi Hook
    participant API as Backend API

    DL->>UA: Call getApi('/app/projects', queryParams)
    UA->>API: Request Projects List
    API-->>UA: Return Projects List
    UA-->>DL: Deliver Projects List
Loading

Poem

I'm a rabbit with a skip and a hop,
Wandering code paths that twist and flop.
API calls twirl in a rhythmic beat,
Every change makes the code so neat.
With fresh hooks leading the way,
I celebrate these changes today!
🐇🚀


📜 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 22215b4 and 5785c96.

📒 Files selected for processing (1)
  • pages/sites/[slug]/[locale]/profile/history.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • pages/sites/[slug]/[locale]/profile/history.tsx
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: ESLint on Ubuntu

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

@sunilsabatp sunilsabatp changed the base branch from feature/api to feature/use-server-api-hook March 25, 2025 10:55
Base automatically changed from feature/use-server-api-hook to develop April 1, 2025 11:12
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 (2)
src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx (1)

18-18: Fix empty object type

The event type is using {} which is not recommended.

-  const handleChange = (e: React.ChangeEvent<{}>) => {
+  const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
🧰 Tools
🪛 Biome (1.9.4)

[error] 18-18: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

pages/sites/[slug]/[locale]/profile/history.tsx (1)

139-142: Remove commented code

There's commented-out code that seems to be a TODO item. Since it's marked as "TODO - remove this", it should probably be removed entirely.

-  // // TODO - remove this
-  // if (typeof window !== 'undefined') {
-  //   router.push('/');
-  // }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2117c45 and 4e3979b.

📒 Files selected for processing (7)
  • pages/sites/[slug]/[locale]/claim/[type]/[code].tsx (3 hunks)
  • pages/sites/[slug]/[locale]/profile/history.tsx (4 hunks)
  • src/features/user/CompleteSignup/index.tsx (3 hunks)
  • src/features/user/Settings/ApiKey/ApiKeyForm.tsx (4 hunks)
  • src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx (1 hunks)
  • src/features/user/Settings/EditProfile/EditProfileForm.tsx (5 hunks)
  • src/features/user/Widget/DonationLink/index.tsx (1 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/features/user/Settings/EditProfile/EditProfileForm.tsx (1)
src/hooks/useApi.ts (1)
  • useApi (93-320)
🪛 Biome (1.9.4)
src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx

[error] 18-18: Don't use '{}' as a type.

Prefer explicitly define the object shape. '{}' means "any non-nullable value".

(lint/complexity/noBannedTypes)

🔇 Additional comments (22)
src/features/user/CompleteSignup/index.tsx (2)

41-41: Good refactoring to use the useApi hook

Adding the useApi hook improves the code organization and centralizes API call logic.

Also applies to: 64-64


180-182: Type-safe API call implementation

The refactoring from postRequest to postApi improves type safety with explicit generics and simplifies the request structure. The approach removes the dependency on tenantConfig which was previously needed.

src/features/user/Widget/DonationLink/index.tsx (2)

14-14: Good implementation of useApi hook

Adding the useApi hook centralizes API call handling and provides a cleaner interface.

Also applies to: 22-22


26-33: Improved API call structure

Refactoring to use getApi simplifies the code while maintaining the same functionality. The queryParams structure is more explicit and follows REST API patterns more closely.

src/features/user/Settings/DeleteProfile/DeleteProfileForm.tsx (2)

13-13: Simplified dependency management

Good job removing the unnecessary token dependency from useUserProps and adding the useApi hook. This refactoring reduces the component's responsibilities.

Also applies to: 16-16, 22-22


30-30: Cleaner API call

The refactoring to use deleteApiAuthenticated simplifies the delete operation by removing the need to pass token and tenant parameters.

pages/sites/[slug]/[locale]/profile/history.tsx (3)

34-34: Good reduction of dependencies

Removing the unused logoutUser parameter and adding the useApi hook improves code cleanliness and reduces unnecessary dependencies.

Also applies to: 42-42, 45-45


69-77: Simplified authenticated API call

The refactoring to use getApiAuthenticated removes the need to manually handle authentication tokens and tenant configuration, which simplifies the code while maintaining the same functionality.


93-95: Consistent API call pattern

All API calls now follow the same pattern using getApiAuthenticated, making the code more consistent and easier to maintain.

Also applies to: 107-113

pages/sites/[slug]/[locale]/claim/[type]/[code].tsx (3)

32-32: Appropriate hook import for API calls.

The new import of useApi hook aligns with the PR objective of standardizing API calls across components.


42-43: Good API call refactoring to use the useApi hook.

The code properly removes the no-longer-needed token and logoutUser parameters from useUserProps while correctly implementing the useApi hook. This simplifies the component's dependencies since authentication is now handled internally by the hook.


86-89: Successfully refactored API call implementation.

The code has been properly migrated from the previous API call pattern to the new one using postApiAuthenticated. The payload structure has been appropriately simplified, maintaining the same functionality while reducing complexity.

src/features/user/Settings/ApiKey/ApiKeyForm.tsx (4)

15-15: Appropriate API hook import added.

The import of useApi hook aligns with the PR's goal to standardize API calls.


34-34: Successfully refactored user props and API methods.

The code appropriately removes the logoutUser from the user props destructuring, as it's now handled by the useApi hook internally. The hook-provided API methods are also correctly extracted.

Also applies to: 37-37


49-51: Simplified API call implementation for getApiKey.

The GET request has been successfully refactored to use the getApiAuthenticated method from the hook, which improves code clarity by removing the need to manually pass tenant config, token and logout handler.


67-69: Simplified API call implementation for regenerateApiKey.

The PUT request has been successfully refactored to use the putApiAuthenticated method from the hook, which improves code clarity and consistency with other API calls.

src/features/user/Settings/EditProfile/EditProfileForm.tsx (6)

3-3: Enhanced type imports for better type safety.

Adding the UserType import improves type safety in the component.


32-32: Appropriate API hook import added.

The import of useApi hook aligns with the PR's goal to standardize API calls.


61-68: Added explicit types for improved type safety.

The new types UserProfileImage and ProfileUpdatePayload provide better type definitions for API requests, which enhances code clarity and reduces potential runtime errors.


73-73: Successfully refactored user props and API methods.

The code appropriately manages the user props by retaining only the needed properties while adding the required API method from the hook.

Also applies to: 78-78


171-176: Improved handleUserProfileImage with strong typing.

The refactoring to use putApiAuthenticated with proper type parameters (User as the response type and UserProfileImage as the payload type) enhances type safety and code clarity.


242-245: Properly typed API call in saveProfile.

The code correctly uses the new ProfileUpdatePayload type with the putApiAuthenticated method, ensuring type safety for the profile update request.

Copy link
Collaborator

@mohitb35 mohitb35 left a comment

Choose a reason for hiding this comment

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

@sunilsabatp Please go through my feedback.

…ility.

-Extracted query parameters from next URL using URL object.
-Standardized query parameter handling using Record<string, string>.
-Removed redundant if blocks for better readability.
-Centralized setProgress and setIsDataLoading updates.
Copy link
Collaborator

@mohitb35 mohitb35 left a comment

Choose a reason for hiding this comment

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

LGTM

@mohitb35 mohitb35 merged commit 5ca8bbb into develop Apr 7, 2025
6 checks passed
@mohitb35 mohitb35 deleted the feature/use-api-hook1 branch April 7, 2025 08:38
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.

2 participants