mirror of
https://github.com/khoj-ai/khoj.git
synced 2025-02-17 08:04:21 +00:00
Extract isUserSubscribed check from Agents page to make it resusable
This commit is contained in:
parent
bdbe8f003e
commit
54b92eaf73
2 changed files with 14 additions and 9 deletions
|
@ -11,7 +11,7 @@ import {
|
|||
UserProfile,
|
||||
ModelOptions,
|
||||
useUserConfig,
|
||||
SubscriptionStates,
|
||||
isUserSubscribed,
|
||||
} from "../common/auth";
|
||||
|
||||
import { Lightning, Plus } from "@phosphor-icons/react";
|
||||
|
@ -267,14 +267,7 @@ export default function Agents() {
|
|||
|
||||
const modelOptions: ModelOptions[] = userConfig?.chat_model_options || [];
|
||||
const selectedChatModelOption: number = userConfig?.selected_chat_model_config || 0;
|
||||
const isSubscribed: boolean =
|
||||
(userConfig?.subscription_state &&
|
||||
[
|
||||
SubscriptionStates.SUBSCRIBED.valueOf(),
|
||||
SubscriptionStates.TRIAL.valueOf(),
|
||||
SubscriptionStates.UNSUBSCRIBED.valueOf(),
|
||||
].includes(userConfig.subscription_state)) ||
|
||||
false;
|
||||
const isSubscribed: boolean = isUserSubscribed(userConfig);
|
||||
|
||||
// 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(
|
||||
|
|
|
@ -93,3 +93,15 @@ export function useUserConfig(detailed: boolean = false) {
|
|||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue