From ecb873c488daf2913769583df5deff1e430c83a7 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 30 Jul 2024 18:17:45 +0530 Subject: [PATCH] Only allow search model to be updated without being subscribed Do not make fetch request to server if user is not subscribed --- src/interface/web/app/common/utils.ts | 2 ++ src/interface/web/app/settings/page.tsx | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/interface/web/app/common/utils.ts b/src/interface/web/app/common/utils.ts index 6dde9d4f..fef8300e 100644 --- a/src/interface/web/app/common/utils.ts +++ b/src/interface/web/app/common/utils.ts @@ -13,6 +13,8 @@ export interface LocationData { const locationFetcher = () => window.fetch("https://ipapi.co/json").then((res) => res.json()).catch((err) => console.log(err)); +export const toTitleCase = (str: string) => str.replace(/\w\S*/g, (txt) => txt.charAt(0).toUpperCase() + txt.slice(1).toLowerCase()); + export function welcomeConsole() { console.log(`%c %s`, "font-family:monospace", ` __ __ __ __ ______ __ _____ __ diff --git a/src/interface/web/app/settings/page.tsx b/src/interface/web/app/settings/page.tsx index 2cee580e..6d51ffd4 100644 --- a/src/interface/web/app/settings/page.tsx +++ b/src/interface/web/app/settings/page.tsx @@ -6,6 +6,7 @@ import { Suspense, useEffect, useState } from "react"; import { useToast } from "@/components/ui/use-toast" import { useUserConfig, ModelOptions, UserConfig } from "../common/auth"; +import { toTitleCase } from "../common/utils"; import { isValidPhoneNumber } from 'libphonenumber-js'; @@ -449,7 +450,7 @@ export default function SettingsView() { title: "💳 Subscription", description: state === "cancel" ? "Failed to cancel subscription. Try again or contact us at team@khoj.dev" : "Failed to renew subscription. Try again or contact us at team@khoj.dev", }); - } + } }; const saveName = async () => { @@ -485,6 +486,7 @@ export default function SettingsView() { } const updateModel = (name: string) => async (id: string) => { + if (!userConfig?.is_active && name !== "search") return; try { const response = await fetch(`/api/model/${name}?id=` + id, { method: 'POST', @@ -496,12 +498,12 @@ export default function SettingsView() { if (!response.ok) throw new Error('Failed to update model'); toast({ - description: `${name} model updated succesfully`, + title: `✅ Updated ${toTitleCase(name)} Model`, }); } catch (error) { console.error(`Failed to update ${name} model:`, error); toast({ - description: `Failed to update ${name} model. Try again.`, + description: `❌ Failed to update ${toTitleCase(name)} model. Try again.`, variant: "destructive", }); } @@ -601,7 +603,6 @@ export default function SettingsView() { description: `Your ${type} integration to Khoj has been disconnected.`, }); } - } catch (error) { console.error(`Error disconnecting ${type}:`, error); toast({ @@ -853,9 +854,6 @@ export default function SettingsView() { /> - {!userConfig.is_active && ( -

Subscribe to switch model

- )}
)}