-
Notifications
You must be signed in to change notification settings - Fork 20
feat: subscription #875
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
feat: subscription #875
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughReplaces hosting-plan centered flows with a subscription-centric model across components and hooks: adds subscription APIs/types, switches UI and state to subscriptions (create/lookup/unsubscribe), removes hosting-plan pricing/plan-selection logic, and adapts tables/conditional rendering to subscription semantics. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Component as GetEndpoint
participant Hook as useConsumerHostServices
participant API as Backend
Note over Component,API: New Subscription-centric flow
User->>Component: Click "Subscribe to Project"
Component->>Hook: getUserSubscriptionByProject(projectId)
alt Subscription exists
Hook->>API: GET /subscriptions/:projectId
API-->>Hook: 200 IGetUserSubscription
else No subscription found
Hook->>API: GET /subscriptions/:projectId
API-->>Hook: 404 NotFound
Hook->>API: POST /subscriptions {projectId, params}
API-->>Hook: 201 IGetUserSubscription
end
Hook-->>Component: subscription data
Component->>Hook: fetchSubscriptionAndApiKeys(projectId)
Hook->>API: GET subscription + GET apiKeys
API-->>Hook: {subscription, apiKeys}
Hook-->>Component: combined state
Component->>User: Render endpoint UI based on subscription.is_active
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
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.
Pull Request Overview
This pull request refactors the Flex Plan system to introduce a project subscription model. Instead of managing individual hosting plans per deployment, users now subscribe to projects and can view/manage multiple hosting plans under each subscription.
- Replaced deployment-based hosting plan management with a project subscription model
- Introduced nested table structure displaying subscriptions with expandable hosting plans
- Simplified the Flex Plan creation flow by removing custom pricing options and focusing on project subscription
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| src/pages/consumer/MyFlexPlans/MyHostedPlan/MyHostedPlan.tsx | Refactored to display subscriptions with nested expandable hosting plans; replaced single table with parent-child table structure |
| src/hooks/useConsumerHostServices.tsx | Added new API methods for subscription management (getUserSubscriptions, createSubscription, unsubscribeProject, getUserHostingPlansByProject) |
| src/components/GetEndpoint/index.tsx | Updated to use subscription-based approach instead of hosting plan checks; automatically creates subscription if needed |
| src/components/DeploymentInfo/DeploymentInfo.tsx | Made deploymentId conditional to support project-only display without deployment information |
| src/components/CreateFlexPlan/index.tsx | Simplified Flex Plan creation by removing custom pricing step and focusing on subscription; removed economy/performance plan options |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 新增: 创建订阅 | ||
| const createSubscription = useCallback( |
Copilot
AI
Nov 3, 2025
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.
Comments are in Chinese ('新增: 创建订阅' means 'New: Create subscription'). All code comments should be in English for consistency with the rest of the codebase. This applies to similar comments at lines 475, 491, 508, 697, and 705.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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/components/DeploymentInfo/DeploymentInfo.tsx (2)
69-73: Consider moving inline styles to CSS module.The inline flex styles work correctly but could be extracted to the existing CSS module (
styles) for better maintainability and consistency with the rest of the component.Example refactor:
<div className={styles.projectTextInfo} onClick={() => { onClick && onClick(); }} - style={{ - display: 'flex', - flexDirection: 'column', - justifyContent: 'center', - }} + className={clsx(styles.projectTextInfo, styles.flexColumn)} >Then add to
DeploymentInfo.module.css:.flexColumn { display: flex; flex-direction: column; justify-content: center; }
96-110: Conditional rendering looks good, but simplify the redundant check.The conditional rendering of the deployment section aligns well with the PR's objective of making deployment optional in the subscription model. However, the ternary check on lines 104-106 is redundant.
Apply this diff to remove the redundant check:
<Copy value={deploymentId} position="flex-start"> <Typography variant="small" className={styles.text}> - {deploymentId - ? `${deploymentId.slice(0, 5)}...${deploymentId.slice(deploymentId.length - 5, deploymentId.length)}` - : '-'} + {`${deploymentId.slice(0, 5)}...${deploymentId.slice(deploymentId.length - 5, deploymentId.length)}`} </Typography> </Copy>Since this code is already inside
{deploymentId && (...)},deploymentIdis guaranteed to be truthy.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/components/CreateFlexPlan/index.tsx(16 hunks)src/components/DeploymentInfo/DeploymentInfo.tsx(2 hunks)src/components/GetEndpoint/index.tsx(11 hunks)src/hooks/useConsumerHostServices.tsx(3 hunks)src/pages/consumer/MyFlexPlans/MyHostedPlan/MyHostedPlan.tsx(8 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/components/CreateFlexPlan/index.tsx (1)
src/hooks/useConsumerHostServices.tsx (3)
IGetUserSubscription(682-695)useConsumerHostServices(40-560)isConsumerHostError(22-25)
src/pages/consumer/MyFlexPlans/MyHostedPlan/MyHostedPlan.tsx (5)
src/hooks/useConsumerHostServices.tsx (3)
IGetUserSubscription(682-695)IGetHostingPlans(625-651)isConsumerHostError(22-25)src/pages/explorer/FlexPlans/CreateHostingPlan/CreateHostingPlan.tsx (1)
CreateHostingFlexPlanRef(29-31)src/utils/index.tsx (2)
bytes32ToCid(63-70)numToHex(296-301)src/utils/parseError.ts (1)
parseError(220-350)src/components/DeploymentInfo/DeploymentInfo.tsx (1)
DeploymentMeta(118-141)
src/components/GetEndpoint/index.tsx (2)
src/hooks/useConsumerHostServices.tsx (5)
IGetUserSubscription(682-695)GetUserApiKeys(653-661)useConsumerHostServices(40-560)isConsumerHostError(22-25)isNotSubscribed(706-710)src/utils/parseError.ts (1)
parseError(220-350)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (14)
src/components/CreateFlexPlan/index.tsx (3)
35-41: LGTM: Props signature updated for subscription model.The component props have been correctly updated to use
prevSubscription?: IGetUserSubscriptioninstead of the previous hosting plan prop, aligning with the PR's subscription-centric architecture.
231-253: LGTM: Subscribe transaction step properly implemented.The new subscribe transaction DOM rendering is consistent with other transaction steps and provides clear user communication about the subscription action.
388-401: Project ID format is hex with '0x' prefix - assumption is valid.The
project.idis consistently stored as a hex string with '0x' prefix across the codebase. This is confirmed by comparisons likeprojectId === '0x30' || projectId === '0x31'in GetEndpoint. The conversion in CreateFlexPlan (line 391) correctly handles this format and aligns with usage in GetEndpoint (line 293). No format mismatch exists, and the code handles the conversion appropriately.However, the assumption remains implicit rather than explicitly documented. Consider adding a comment or type guard to clarify the expected format if the codebase will be maintained long-term or if
project.idmay originate from multiple sources.src/hooks/useConsumerHostServices.tsx (2)
453-521: LGTM: Subscription API functions well-implemented.The five new subscription-related API functions follow consistent patterns with existing functions, properly handle authentication headers, and include appropriate error types in their return signatures.
682-710: LGTM: Subscription types properly defined.The new subscription-related types and type guard are well-structured:
IGetUserSubscriptioncaptures all necessary subscription dataIGetUserSubscriptionNotFoundprovides clear not-found semanticsisNotSubscribedtype guard is correctly implemented for discriminating subscription statussrc/pages/consumer/MyFlexPlans/MyHostedPlan/MyHostedPlan.tsx (4)
148-178: LGTM: Efficient per-project hosting plan fetching with metadata enrichment.The
fetchHostingPlansfunction properly:
- Handles CID format conversion for metadata (both Qm-prefixed and bytes32)
- Uses
Promise.allSettledto handle metadata fetching failures gracefully- Enriches plans with project names for UI display
- Caches results in a Map for efficient lookups
180-189: LGTM: Efficient expand handler with caching.The expand handler properly checks if hosting plans are already cached before fetching, avoiding unnecessary API calls while maintaining correct expandedRowKeys state.
191-207: LGTM: Proper cleanup in unsubscribe handler.The unsubscribe handler correctly:
- Calls the API to unsubscribe
- Refreshes the subscriptions list
- Clears cached hosting plans for the unsubscribed project
- Provides user feedback with success message
346-346: The empty deploymentId is intentionally handled and requires no changes.The code already gracefully handles empty
deploymentIdthrough falsy checks:
- Line 43 in useDeploymentMetadata:
if (deploymentId)prevents fetching for empty strings- Line 96 in DeploymentInfo:
{deploymentId && (...)}skips rendering the deployment section for empty valuesFor subscription-level data without an associated deployment, the component correctly displays only project information while omitting deployment-specific UI elements.
src/components/GetEndpoint/index.tsx (5)
89-100: LGTM: State and derived values properly structured.The subscription state and
hasActiveSubscriptionderived value are correctly implemented, with proper typing and memoization.
290-324: Auto-creates subscription on first fetch—confirm intentional behavior.The
fetchSubscriptionfunction automatically creates a new subscription if one doesn't exist. While this simplifies the flow, verify this is the intended behavior, as it means simply fetching subscription data will create one as a side effect.Consider if subscription creation should be:
- Explicit user action (current implementation auto-creates)
- Confirmed via user interaction before creation
If auto-creation is intentional, consider adding a comment explaining this design decision.
326-356: LGTM: Proper orchestration of subscription and API key setup.The
fetchSubscriptionAndApiKeysfunction correctly sequences the setup: fetch/create subscription, then ensure API key exists. Error handling and loading states are properly managed.
365-380: LGTM: Proper flow control based on subscription state.The next step logic correctly determines the user's path based on:
- Subscription existence and active status
- API key existence
- Proper routing to either endpoint display or creation flow
106-119: LGTM: Button text properly reflects subscription flow.The next step button text correctly updates based on subscription state and current step, providing clear user guidance throughout the flow.
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: 1
♻️ Duplicate comments (2)
src/components/GetEndpoint/index.tsx (2)
298-298: Chinese comment should be in English.This was already flagged in a previous review.
309-309: Chinese comment should be in English.This was already flagged in a previous review.
🧹 Nitpick comments (4)
src/components/DeploymentInfo/DeploymentInfo.tsx (1)
69-73: Consider moving inline styles to the CSS module.The inline flex styles are functional but could be consolidated into the existing
styles.projectTextInfoclass for better maintainability and consistency with the rest of the component's styling approach.Apply this change to move styles to the CSS module:
- style={{ - display: 'flex', - flexDirection: 'column', - justifyContent: 'center', - }}Then add to
DeploymentInfo.module.css:.projectTextInfo { /* existing styles */ display: flex; flex-direction: column; justify-content: center; }src/components/CreateFlexPlan/index.tsx (3)
391-391: Specify radix explicitly in parseInt.The radix parameter should be explicitly specified as
16for clarity and safety, even though it's implied by the '0x' prefix removal.Apply this diff:
- const projectIdNumber = parseInt(project.id.replace('0x', ''), 16); + const projectIdNumber = parseInt(project.id.replace('0x', ''), 16);Wait, that's the same. Let me check the actual code - it already has radix 16! So this is actually correct. Let me reconsider.
308-309: Address TypeScript type assertion.The
@ts-ignorecomment suppresses type errors. Consider using proper TypeScript typing instead of ignoring type errors.The type should be explicitly cast or the
displayTransactionsarray should be typed to accept the union type properly:- // @ts-ignore - setDisplayTransactions(newDisplayTransactions); + setDisplayTransactions(newDisplayTransactions as ('allowance' | 'deposit' | 'createApiKey' | 'subscribe')[]);
328-329: Address TypeScript type assertion.The
@ts-ignorecomment suppresses type errors. Use proper TypeScript casting instead.Apply this diff:
- // @ts-ignore - setTransactionStep(displayTransactions[index]); + setTransactionStep(displayTransactions[index] as 'allowance' | 'deposit' | 'createApiKey' | 'subscribe');
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/components/CreateFlexPlan/index.tsx(16 hunks)src/components/DeploymentInfo/DeploymentInfo.tsx(2 hunks)src/components/GetEndpoint/index.tsx(11 hunks)src/hooks/useConsumerHostServices.tsx(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/hooks/useConsumerHostServices.tsx
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/CreateFlexPlan/index.tsx (2)
src/hooks/useConsumerHostServices.tsx (3)
IGetUserSubscription(682-695)useConsumerHostServices(40-560)isConsumerHostError(22-25)src/containers/Web3.tsx (1)
useAccount(33-42)
src/components/GetEndpoint/index.tsx (2)
src/hooks/useConsumerHostServices.tsx (5)
IGetUserSubscription(682-695)GetUserApiKeys(653-661)useConsumerHostServices(40-560)isConsumerHostError(22-25)isNotSubscribed(706-710)src/utils/parseError.ts (1)
parseError(220-350)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
src/components/DeploymentInfo/DeploymentInfo.tsx (1)
96-108: Conditional rendering correctly addresses the past review concern.The deployment information block is now properly guarded by checking if
deploymentIdexists before rendering. This resolves the previous issue where the deploymentId variable evaluation always returned true, and ensures the block only renders when deployment data is actually available.
| const fetchSubscription = async () => { | ||
| try { | ||
| setNextBtnLoading(true); | ||
| const hostingPlan = await getHostingPlanApi({ | ||
| account, | ||
| }); | ||
| const projectIdNumber = parseInt(project.id.replace('0x', ''), 16); | ||
| const subscriptionRes = await getUserSubscriptionByProject(projectIdNumber); | ||
|
|
||
| if (!isConsumerHostError(hostingPlan.data)) { | ||
| setUserHostingPlan(hostingPlan.data); | ||
| if (!isConsumerHostError(subscriptionRes.data)) { | ||
| if (isNotSubscribed(subscriptionRes.data)) { | ||
| // No subscription found, create new subscription | ||
| const newSubscription = await createSubscription({ project_id: projectIdNumber }); | ||
|
|
||
| // no hosting plan then skip fetch api key, | ||
| if (!hostingPlan.data.find((i) => i.deployment.deployment === deploymentId && i.is_actived)) | ||
| return { | ||
| data: [], | ||
| }; | ||
| if (!isConsumerHostError(newSubscription.data)) { | ||
| setCurrentSubscription(newSubscription.data); | ||
| return { data: newSubscription.data }; | ||
| } else { | ||
| setCurrentSubscription(null); | ||
| return { data: null }; | ||
| } | ||
| } else { | ||
| // Subscription already exists | ||
| setCurrentSubscription(subscriptionRes.data); | ||
| return { data: subscriptionRes.data }; | ||
| } | ||
| } else { | ||
| return { | ||
| data: [], | ||
| }; | ||
| setCurrentSubscription(null); | ||
| return { data: null }; | ||
| } | ||
|
|
||
| return hostingPlan; | ||
| } catch (e) { | ||
| parseError(e, { alert: true }); | ||
| setCurrentSubscription(null); | ||
| return { data: null }; | ||
| } finally { | ||
| setNextBtnLoading(false); | ||
| } | ||
| }; |
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.
Misleading function name with side effects.
The fetchSubscription function name suggests a read-only operation, but it automatically creates a new subscription if one doesn't exist (lines 299-307). This side effect is unexpected and could lead to confusion or unintended resource creation.
Consider one of the following approaches:
-
Separate read and write operations (recommended):
- Rename to
fetchOrCreateSubscriptionto make the side effect explicit - Or better yet, split into separate
fetchSubscriptionandcreateSubscriptionfunctions, and call them explicitly where needed
- Rename to
-
Add a parameter to control behavior:
const fetchSubscription = async (options?: { autoCreate?: boolean }) => { // ... if (isNotSubscribed(subscriptionRes.data)) { if (options?.autoCreate) { // create subscription } else { return { data: null }; } } }
This makes the API more predictable and prevents accidental resource creation.
🤖 Prompt for AI Agents
In src/components/GetEndpoint/index.tsx around lines 290-324, the function
fetchSubscription is misleading because it performs a create side-effect when no
subscription exists; refactor so intent is explicit: either (A) split into a
pure read function fetchSubscription that only calls
getUserSubscriptionByProject and returns subscription or null, and move creation
logic into a separate createSubscription flow which callers invoke explicitly,
or (B) rename to fetchOrCreateSubscription to make the side-effect explicit, or
(C) add an options parameter (e.g. autoCreate: boolean = false) so creation only
occurs when callers opt-in; update all call sites to use the new API and ensure
UI loading/error handling remains the same.
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: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/components/CreateFlexPlan/index.tsx(16 hunks)src/components/DeploymentInfo/DeploymentInfo.tsx(2 hunks)src/components/GetEndpoint/index.tsx(11 hunks)src/hooks/useConsumerHostServices.tsx(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- src/hooks/useConsumerHostServices.tsx
- src/components/DeploymentInfo/DeploymentInfo.tsx
🧰 Additional context used
🧬 Code graph analysis (2)
src/components/CreateFlexPlan/index.tsx (3)
src/hooks/useConsumerHostServices.tsx (3)
IGetUserSubscription(682-695)useConsumerHostServices(40-560)isConsumerHostError(22-25)src/containers/Web3.tsx (1)
useAccount(33-42)src/hooks/useAddAllowance.ts (1)
useAddAllowance(9-47)
src/components/GetEndpoint/index.tsx (2)
src/hooks/useConsumerHostServices.tsx (5)
IGetUserSubscription(682-695)GetUserApiKeys(653-661)useConsumerHostServices(40-560)isConsumerHostError(22-25)isNotSubscribed(706-710)src/utils/parseError.ts (1)
parseError(220-350)
| <CreateFlexPlan | ||
| prevHostingPlan={createdHostingPlan} | ||
| prevApiKey={createdApiKey} | ||
| deploymentId={deploymentId} | ||
| project={project} | ||
| onSuccess={async () => { | ||
| await checkIfHasLogin(); | ||
| await fetchHostingPlanAndApiKeys(); | ||
| await fetchSubscriptionAndApiKeys(); | ||
| setCurrentStep('checkEndpointWithApiKey'); |
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.
Pass the fetched subscription into CreateFlexPlan.
CreateFlexPlan relies on its prevSubscription prop to decide whether it still needs to call createSubscription. Since we never pass currentSubscription here, that prop is always undefined, so the component always schedules the “Subscribe” transaction and hits /users/subscriptions again. For anyone who already has a subscription but still needs to deposit or create an API key, the subscribe step now fails with “already subscribed” and blocks the workflow. Please pass the fetched subscription down:
<CreateFlexPlan
prevApiKey={createdApiKey}
+ prevSubscription={currentSubscription}
deploymentId={deploymentId}
project={project}
onSuccess={async () => {📝 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.
| <CreateFlexPlan | |
| prevHostingPlan={createdHostingPlan} | |
| prevApiKey={createdApiKey} | |
| deploymentId={deploymentId} | |
| project={project} | |
| onSuccess={async () => { | |
| await checkIfHasLogin(); | |
| await fetchHostingPlanAndApiKeys(); | |
| await fetchSubscriptionAndApiKeys(); | |
| setCurrentStep('checkEndpointWithApiKey'); | |
| <CreateFlexPlan | |
| prevApiKey={createdApiKey} | |
| prevSubscription={currentSubscription} | |
| deploymentId={deploymentId} | |
| project={project} | |
| onSuccess={async () => { | |
| await checkIfHasLogin(); | |
| await fetchSubscriptionAndApiKeys(); | |
| setCurrentStep('checkEndpointWithApiKey'); |
🤖 Prompt for AI Agents
In src/components/GetEndpoint/index.tsx around lines 268 to 275, CreateFlexPlan
is rendered without passing the fetched currentSubscription as prevSubscription,
causing CreateFlexPlan to always attempt to create a subscription and trigger
"already subscribed" errors; update the JSX to pass
prevSubscription={currentSubscription} (or the correct state variable name
holding the fetched subscription) into CreateFlexPlan so it can skip
createSubscription when a subscription already exists.
| // No subscription found, create new subscription | ||
| const newSubscription = await createSubscription({ project_id: projectIdNumber }); | ||
|
|
||
| // no hosting plan then skip fetch api key, | ||
| if (!hostingPlan.data.find((i) => i.deployment.deployment === deploymentId && i.is_actived)) | ||
| return { | ||
| data: [], | ||
| }; | ||
| if (!isConsumerHostError(newSubscription.data)) { | ||
| setCurrentSubscription(newSubscription.data); | ||
| return { data: newSubscription.data }; | ||
| } else { | ||
| setCurrentSubscription(null); | ||
| return { data: null }; | ||
| } |
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.
Stop auto-subscribing inside the fetch helper.
fetchSubscription should only read the current state, but right now it posts to /users/subscriptions whenever the project has no subscription. Because fetchSubscription() is invoked when opening the modal or progressing from the selection step, users get force-subscribed before they approve any transactions or deposits. It also duplicates the create call that still lives in CreateFlexPlan, so you end up creating the subscription twice. Please remove the implicit POST from this fetch path and only trigger createSubscription during the explicit subscribe step. Example fix:
if (isNotSubscribed(subscriptionRes.data)) {
- // No subscription found, create new subscription
- const newSubscription = await createSubscription({ project_id: projectIdNumber });
-
- if (!isConsumerHostError(newSubscription.data)) {
- setCurrentSubscription(newSubscription.data);
- return { data: newSubscription.data };
- } else {
- setCurrentSubscription(null);
- return { data: null };
- }
+ setCurrentSubscription(null);
+ return { data: null };
} else {
// Subscription already exists
setCurrentSubscription(subscriptionRes.data);
return { data: subscriptionRes.data };
}📝 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.
| // No subscription found, create new subscription | |
| const newSubscription = await createSubscription({ project_id: projectIdNumber }); | |
| // no hosting plan then skip fetch api key, | |
| if (!hostingPlan.data.find((i) => i.deployment.deployment === deploymentId && i.is_actived)) | |
| return { | |
| data: [], | |
| }; | |
| if (!isConsumerHostError(newSubscription.data)) { | |
| setCurrentSubscription(newSubscription.data); | |
| return { data: newSubscription.data }; | |
| } else { | |
| setCurrentSubscription(null); | |
| return { data: null }; | |
| } | |
| setCurrentSubscription(null); | |
| return { data: null }; |
🤖 Prompt for AI Agents
In src/components/GetEndpoint/index.tsx around lines 298 to 307, the
fetchSubscription helper is creating a subscription when none exists; remove
that POST side-effect so this function only reads state. Replace the
createSubscription call and its branch with logic that sets current subscription
to null (or leaves it unchanged) and returns { data: null } when no subscription
is found; ensure callers rely on the explicit subscribe flow (e.g.,
CreateFlexPlan) to create subscriptions and handle the null result accordingly.
Description
Type of change
Summary by CodeRabbit
New Features
Refactor