fix: cache already-enabled feature opt-in status in local storage (#27393)
When the eligibility check returns "already_enabled", store this in local storage to prevent repeated API calls on subsequent page loads. Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.5
parent
1e048648ce
commit
b51a0b0847
@@ -3,8 +3,7 @@
|
||||
import type { OptInFeatureConfig } from "@calcom/features/feature-opt-in/config";
|
||||
import { getOptInFeatureConfig, shouldDisplayFeatureAt } from "@calcom/features/feature-opt-in/config";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
getFeatureOptInTimestamp,
|
||||
isFeatureDismissed,
|
||||
@@ -65,6 +64,15 @@ function useFeatureOptInBanner(featureId: string): UseFeatureOptInBannerResult {
|
||||
}
|
||||
);
|
||||
|
||||
// When the server reports the feature is already enabled, cache it locally
|
||||
// to avoid repeated API calls on subsequent page loads
|
||||
useEffect(() => {
|
||||
if (eligibilityQuery.data?.status === "already_enabled") {
|
||||
setFeatureOptedIn(featureId);
|
||||
setIsOptedIn(true);
|
||||
}
|
||||
}, [eligibilityQuery.data?.status, featureId]);
|
||||
|
||||
const setUserStateMutation = trpc.viewer.featureOptIn.setUserState.useMutation();
|
||||
const setTeamStateMutation = trpc.viewer.featureOptIn.setTeamState.useMutation();
|
||||
const setOrganizationStateMutation = trpc.viewer.featureOptIn.setOrganizationState.useMutation();
|
||||
|
||||
Reference in New Issue
Block a user