Refactor subscription logic and replace quill-sense references with ritor equivalents
- Updated `getCurrentSubscription` and related functions to reflect terminology changes. - Adjusted subscription levels and access checks to streamline logic. - Removed unused cases in `getSubLevel` and optimized conditionals for clarity.
This commit is contained in:
@@ -18,7 +18,7 @@ import Button from "@/components/ui/Button";
|
|||||||
import QSTextGeneratedPreview from "@/components/ui/QSTextGeneratedPreview";
|
import QSTextGeneratedPreview from "@/components/ui/QSTextGeneratedPreview";
|
||||||
import {EditorContext, EditorContextProps} from "@/context/EditorContext";
|
import {EditorContext, EditorContextProps} from "@/context/EditorContext";
|
||||||
import {useTranslations} from '@/lib/i18n';
|
import {useTranslations} from '@/lib/i18n';
|
||||||
import {getSubLevel, isOpenAIEnabled} from "@/lib/utils/quillsense";
|
import {getSubLevel, isAnthropicEnabled} from "@/lib/utils/quillsense";
|
||||||
import TextInput from "@/components/form/TextInput";
|
import TextInput from "@/components/form/TextInput";
|
||||||
import InputField from "@/components/form/InputField";
|
import InputField from "@/components/form/InputField";
|
||||||
import TextAreaInput from "@/components/form/TextAreaInput";
|
import TextAreaInput from "@/components/form/TextAreaInput";
|
||||||
@@ -93,9 +93,9 @@ export default function DraftCompanion() {
|
|||||||
const [useExplicit, setUseExplicit] = useState<boolean>(false);
|
const [useExplicit, setUseExplicit] = useState<boolean>(false);
|
||||||
const [useSmart, setUseSmart] = useState<boolean>(false);
|
const [useSmart, setUseSmart] = useState<boolean>(false);
|
||||||
|
|
||||||
const isGPTEnabled: boolean = isOpenAIEnabled(session);
|
const isAnthropicKey: boolean = isAnthropicEnabled(session);
|
||||||
const isSubTierTree: boolean = getSubLevel(session) === 3;
|
const isSubTierTwo: boolean = getSubLevel(session) >= 2;
|
||||||
const hasAccess: boolean = (isGPTEnabled || isSubTierTree) && !isCurrentlyOffline() && !book?.localBook;
|
const hasAccess: boolean = (isAnthropicKey || isSubTierTwo) && !isCurrentlyOffline() && !book?.localBook;
|
||||||
|
|
||||||
useEffect((): void => {
|
useEffect((): void => {
|
||||||
getDraftContent().then();
|
getDraftContent().then();
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import GhostWriterTags from "@/components/ghostwriter/GhostWriterTags";
|
|||||||
import {TiptapNode} from "@/lib/types/chapter";
|
import {TiptapNode} from "@/lib/types/chapter";
|
||||||
import {convertTiptapToHTML} from "@/lib/utils/tiptap";
|
import {convertTiptapToHTML} from "@/lib/utils/tiptap";
|
||||||
import {useTranslations} from '@/lib/i18n';
|
import {useTranslations} from '@/lib/i18n';
|
||||||
import {getSubLevel, isOpenAIEnabled} from "@/lib/utils/quillsense";
|
import {getSubLevel, isAnthropicEnabled} from "@/lib/utils/quillsense";
|
||||||
import {AIUsageContext, AIUsageContextProps} from "@/context/AIUsageContext";
|
import {AIUsageContext, AIUsageContextProps} from "@/context/AIUsageContext";
|
||||||
import {LangContext, LangContextProps} from "@/context/LangContext";
|
import {LangContext, LangContextProps} from "@/context/LangContext";
|
||||||
import {configs} from "@/lib/configs";
|
import {configs} from "@/lib/configs";
|
||||||
@@ -52,9 +52,9 @@ export default function GhostWriter() {
|
|||||||
const [useExplicit, setUseExplicit] = useState<boolean>(false);
|
const [useExplicit, setUseExplicit] = useState<boolean>(false);
|
||||||
const [useSmart, setUseSmart] = useState<boolean>(false);
|
const [useSmart, setUseSmart] = useState<boolean>(false);
|
||||||
|
|
||||||
const isGPTEnabled: boolean = isOpenAIEnabled(session);
|
const isAnthropicKey: boolean = isAnthropicEnabled(session);
|
||||||
const isSubTierTree: boolean = getSubLevel(session) === 3;
|
const isSubTierTwo: boolean = getSubLevel(session) >= 2;
|
||||||
const hasAccess: boolean = isGPTEnabled || isSubTierTree;
|
const hasAccess: boolean = isAnthropicKey || isSubTierTwo;
|
||||||
|
|
||||||
async function handleStopGeneration(): Promise<void> {
|
async function handleStopGeneration(): Promise<void> {
|
||||||
if (abortController) {
|
if (abortController) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export default function QuillSenseComponent(): React.JSX.Element {
|
|||||||
const subLevel: number = getSubLevel(session)
|
const subLevel: number = getSubLevel(session)
|
||||||
|
|
||||||
const isGPTEnabled: boolean = isOpenAIEnabled(session);
|
const isGPTEnabled: boolean = isOpenAIEnabled(session);
|
||||||
const isSubTierTwo: boolean = getSubLevel(session) >= 1;
|
const isSubTierTwo: boolean = getSubLevel(session) >= 2;
|
||||||
const hasAccess: boolean = isGPTEnabled || isSubTierTwo;
|
const hasAccess: boolean = isGPTEnabled || isSubTierTwo;
|
||||||
|
|
||||||
const qsOptions: QSOption[] = [
|
const qsOptions: QSOption[] = [
|
||||||
@@ -77,7 +77,7 @@ export default function QuillSenseComponent(): React.JSX.Element {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
isBYOK || subLevel >= 1 ? (
|
isBYOK || subLevel >= 2 ? (
|
||||||
<>
|
<>
|
||||||
{view === 'list' ? (
|
{view === 'list' ? (
|
||||||
<QuillList handleSelectConversation={handleSelectConversation}/>
|
<QuillList handleSelectConversation={handleSelectConversation}/>
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import {Subscription} from "@/lib/types/user";
|
|||||||
import {getCurrentSubscription} from "@/lib/utils/user";
|
import {getCurrentSubscription} from "@/lib/utils/user";
|
||||||
|
|
||||||
export function getSubLevel(session: SessionProps): number {
|
export function getSubLevel(session: SessionProps): number {
|
||||||
let currentSub: Subscription | null = getCurrentSubscription(session?.user, 'quill-sense');
|
let currentSub: Subscription | null = getCurrentSubscription(session?.user, 'ritor-subscription');
|
||||||
if (!currentSub) {
|
if (!currentSub) {
|
||||||
currentSub = getCurrentSubscription(session?.user, 'quill-trial');
|
currentSub = getCurrentSubscription(session?.user, 'ritor-trial');
|
||||||
if (!currentSub) {
|
if (!currentSub) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -15,8 +15,6 @@ export function getSubLevel(session: SessionProps): number {
|
|||||||
return 1;
|
return 1;
|
||||||
case 2:
|
case 2:
|
||||||
return 2;
|
return 2;
|
||||||
case 3:
|
|
||||||
return 3;
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -24,8 +22,7 @@ export function getSubLevel(session: SessionProps): number {
|
|||||||
|
|
||||||
export function isBringYourKeys(session: SessionProps): boolean {
|
export function isBringYourKeys(session: SessionProps): boolean {
|
||||||
if (!session?.user) return false;
|
if (!session?.user) return false;
|
||||||
const currentSub: Subscription | null = getCurrentSubscription(session?.user, 'use-your-keys');
|
return session.user.apiKeys.openai || session.user.apiKeys.anthropic || session.user.apiKeys.gemini;
|
||||||
return currentSub?.status || session.user.groupId <= 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isGeminiEnabled(session: SessionProps): boolean {
|
export function isGeminiEnabled(session: SessionProps): boolean {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {GuideTour, Subscription, UserProps} from "@/lib/types/user";
|
import {GuideTour, Subscription, UserProps} from "@/lib/types/user";
|
||||||
import {SessionProps} from "@/lib/types/session";
|
import {SessionProps} from "@/lib/types/session";
|
||||||
|
|
||||||
export function getCurrentSubscription(user: UserProps | null, type: "quill-sense" | "use-your-keys" | "quill-trial"): Subscription | null {
|
export function getCurrentSubscription(user: UserProps | null, type: "ritor-subscription" | "use-your-keys" | "ritor-trial"): Subscription | null {
|
||||||
if (!user || !user.subscription || user.subscription.length === 0) {
|
if (!user || !user.subscription || user.subscription.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user