-
Notifications
You must be signed in to change notification settings - Fork 18
Feature/use api hook1 #2469
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
Feature/use api hook1 #2469
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request updates several components by replacing older API functions with new counterparts from the Changes
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
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
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
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 typeThe 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 codeThere'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
📒 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 hookAdding the useApi hook improves the code organization and centralizes API call logic.
Also applies to: 64-64
180-182
: Type-safe API call implementationThe refactoring from
postRequest
topostApi
improves type safety with explicit generics and simplifies the request structure. The approach removes the dependency ontenantConfig
which was previously needed.src/features/user/Widget/DonationLink/index.tsx (2)
14-14
: Good implementation of useApi hookAdding the useApi hook centralizes API call handling and provides a cleaner interface.
Also applies to: 22-22
26-33
: Improved API call structureRefactoring 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 managementGood job removing the unnecessary
token
dependency fromuseUserProps
and adding the useApi hook. This refactoring reduces the component's responsibilities.Also applies to: 16-16, 22-22
30-30
: Cleaner API callThe 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 dependenciesRemoving 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 callThe 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 patternAll 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
andlogoutUser
parameters fromuseUserProps
while correctly implementing theuseApi
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 theuseApi
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
andProfileUpdatePayload
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 andUserProfileImage
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 theputApiAuthenticated
method, ensuring type safety for the profile update request.
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Utilize the useApi() hook for api call.
pages covered :
/profile/donation-link
/profile/edit
/profile/history