mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Extract isUserSubscribed check from Agents page to make it resusable
This commit is contained in:
@@ -11,7 +11,7 @@ import {
|
|||||||
UserProfile,
|
UserProfile,
|
||||||
ModelOptions,
|
ModelOptions,
|
||||||
useUserConfig,
|
useUserConfig,
|
||||||
SubscriptionStates,
|
isUserSubscribed,
|
||||||
} from "../common/auth";
|
} from "../common/auth";
|
||||||
|
|
||||||
import { Lightning, Plus } from "@phosphor-icons/react";
|
import { Lightning, Plus } from "@phosphor-icons/react";
|
||||||
@@ -267,14 +267,7 @@ export default function Agents() {
|
|||||||
|
|
||||||
const modelOptions: ModelOptions[] = userConfig?.chat_model_options || [];
|
const modelOptions: ModelOptions[] = userConfig?.chat_model_options || [];
|
||||||
const selectedChatModelOption: number = userConfig?.selected_chat_model_config || 0;
|
const selectedChatModelOption: number = userConfig?.selected_chat_model_config || 0;
|
||||||
const isSubscribed: boolean =
|
const isSubscribed: boolean = isUserSubscribed(userConfig);
|
||||||
(userConfig?.subscription_state &&
|
|
||||||
[
|
|
||||||
SubscriptionStates.SUBSCRIBED.valueOf(),
|
|
||||||
SubscriptionStates.TRIAL.valueOf(),
|
|
||||||
SubscriptionStates.UNSUBSCRIBED.valueOf(),
|
|
||||||
].includes(userConfig.subscription_state)) ||
|
|
||||||
false;
|
|
||||||
|
|
||||||
// The default model option should map to the item in the modelOptions array that has the same id as the selectedChatModelOption
|
// The default model option should map to the item in the modelOptions array that has the same id as the selectedChatModelOption
|
||||||
const defaultModelOption = modelOptions.find(
|
const defaultModelOption = modelOptions.find(
|
||||||
|
|||||||
@@ -93,3 +93,15 @@ export function useUserConfig(detailed: boolean = false) {
|
|||||||
|
|
||||||
return { userConfig, isLoadingUserConfig };
|
return { userConfig, isLoadingUserConfig };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isUserSubscribed(userConfig: UserConfig | null): boolean {
|
||||||
|
return (
|
||||||
|
(userConfig?.subscription_state &&
|
||||||
|
[
|
||||||
|
SubscriptionStates.SUBSCRIBED.valueOf(),
|
||||||
|
SubscriptionStates.TRIAL.valueOf(),
|
||||||
|
SubscriptionStates.UNSUBSCRIBED.valueOf(),
|
||||||
|
].includes(userConfig.subscription_state)) ||
|
||||||
|
false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user