From 922b440d58c972801b3447ff85bf535fe70c2107 Mon Sep 17 00:00:00 2001 From: Eliezer Steinbock <3090527+elie222@users.noreply.github.com> Date: Sun, 11 Jan 2026 19:58:44 +0200 Subject: [PATCH] refactor: replace provider === 'google' with isGoogleProvider helper Replace all direct comparisons of provider === 'google' with the isGoogleProvider helper function for consistency and maintainability. - Updated 8 files to use isGoogleProvider(provider) instead of direct comparison - Added imports for isGoogleProvider where needed - Improves code consistency and makes provider checks easier to maintain --- apps/web/__tests__/helpers.ts | 3 ++- .../assistant/settings/PersonalSignatureSetting.tsx | 3 ++- .../[emailAccountId]/settings/SignatureSectionForm.tsx | 3 ++- apps/web/app/(app)/accounts/AddAccount.tsx | 8 +++++--- apps/web/utils/account-linking.ts | 3 ++- apps/web/utils/calendar/event-provider.ts | 3 ++- apps/web/utils/calendar/unified-availability.ts | 5 +++-- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/apps/web/__tests__/helpers.ts b/apps/web/__tests__/helpers.ts index 89e3112b7b..b05653e9b1 100644 --- a/apps/web/__tests__/helpers.ts +++ b/apps/web/__tests__/helpers.ts @@ -2,6 +2,7 @@ import type { EmailAccountWithAI } from "@/utils/llms/types"; import type { EmailForLLM } from "@/utils/types"; import { ActionType, LogicalOperator } from "@/generated/prisma/enums"; import type { Action, Prisma } from "@/generated/prisma/client"; +import { isGoogleProvider } from "@/utils/email/provider-types"; type EmailAccountSelect = { id: string; @@ -283,7 +284,7 @@ export function getCalendarConnection({ return { id: `conn-${provider}`, provider, - email: `test@${provider === "google" ? "gmail" : "outlook"}.com`, + email: `test@${isGoogleProvider(provider) ? "gmail" : "outlook"}.com`, accessToken: "token", refreshToken: "refresh", expiresAt: new Date(), diff --git a/apps/web/app/(app)/[emailAccountId]/assistant/settings/PersonalSignatureSetting.tsx b/apps/web/app/(app)/[emailAccountId]/assistant/settings/PersonalSignatureSetting.tsx index 042c206faa..3b75d942f8 100644 --- a/apps/web/app/(app)/[emailAccountId]/assistant/settings/PersonalSignatureSetting.tsx +++ b/apps/web/app/(app)/[emailAccountId]/assistant/settings/PersonalSignatureSetting.tsx @@ -30,6 +30,7 @@ import { } from "@/components/ui/dialog"; import { Textarea } from "@/components/ui/textarea"; import { Label } from "@/components/ui/label"; +import { isGoogleProvider } from "@/utils/email/provider-types"; export function PersonalSignatureSetting() { const { data, isLoading, error } = useEmailAccountFull(); @@ -71,7 +72,7 @@ function SignatureDialog({ const [selectedSignature, setSelectedSignature] = useState(""); const [manualSignature, setManualSignature] = useState(currentSignature); - const isGmail = provider === "google"; + const isGmail = isGoogleProvider(provider); const { execute: executeSave, isExecuting: isSaving } = useAction( saveSignatureAction.bind(null, emailAccountId), diff --git a/apps/web/app/(app)/[emailAccountId]/settings/SignatureSectionForm.tsx b/apps/web/app/(app)/[emailAccountId]/settings/SignatureSectionForm.tsx index c357d4f866..b9c3640cd3 100644 --- a/apps/web/app/(app)/[emailAccountId]/settings/SignatureSectionForm.tsx +++ b/apps/web/app/(app)/[emailAccountId]/settings/SignatureSectionForm.tsx @@ -20,6 +20,7 @@ import { useAccount } from "@/providers/EmailAccountProvider"; import { zodResolver } from "@hookform/resolvers/zod"; import { getActionErrorMessage } from "@/utils/error"; import { saveSignatureBody } from "@/utils/actions/user.validation"; +import { isGoogleProvider } from "@/utils/email/provider-types"; export const SignatureSectionForm = ({ signature, @@ -36,7 +37,7 @@ export const SignatureSectionForm = ({ const editorRef = useRef(null); const { emailAccountId, provider } = useAccount(); - const isGmail = provider === "google"; + const isGmail = isGoogleProvider(provider); const { execute, isExecuting } = useAction( saveSignatureAction.bind(null, emailAccountId), diff --git a/apps/web/app/(app)/accounts/AddAccount.tsx b/apps/web/app/(app)/accounts/AddAccount.tsx index 913b436691..9c95257f2f 100644 --- a/apps/web/app/(app)/accounts/AddAccount.tsx +++ b/apps/web/app/(app)/accounts/AddAccount.tsx @@ -6,14 +6,16 @@ import { toastError } from "@/components/Toast"; import Image from "next/image"; import { TypographyP } from "@/components/Typography"; import { getAccountLinkingUrl } from "@/utils/account-linking"; +import { isGoogleProvider } from "@/utils/email/provider-types"; export function AddAccount() { const [isLoadingGoogle, setIsLoadingGoogle] = useState(false); const [isLoadingMicrosoft, setIsLoadingMicrosoft] = useState(false); const handleAddAccount = async (provider: "google" | "microsoft") => { - const setLoading = - provider === "google" ? setIsLoadingGoogle : setIsLoadingMicrosoft; + const setLoading = isGoogleProvider(provider) + ? setIsLoadingGoogle + : setIsLoadingMicrosoft; setLoading(true); try { @@ -22,7 +24,7 @@ export function AddAccount() { } catch (error) { console.error(`Error initiating ${provider} link:`, error); toastError({ - title: `Error initiating ${provider === "google" ? "Google" : "Microsoft"} link`, + title: `Error initiating ${isGoogleProvider(provider) ? "Google" : "Microsoft"} link`, description: "Please try again or contact support", }); setLoading(false); diff --git a/apps/web/utils/account-linking.ts b/apps/web/utils/account-linking.ts index 4f69243d4d..880b567838 100644 --- a/apps/web/utils/account-linking.ts +++ b/apps/web/utils/account-linking.ts @@ -1,5 +1,6 @@ import type { GetAuthLinkUrlResponse } from "@/app/api/google/linking/auth-url/route"; import type { GetOutlookAuthLinkUrlResponse } from "@/app/api/outlook/linking/auth-url/route"; +import { isGoogleProvider } from "@/utils/email/provider-types"; /** * Initiates the OAuth account linking flow for Google or Microsoft. @@ -18,7 +19,7 @@ export async function getAccountLinkingUrl( if (!response.ok) { throw new Error( - `Failed to initiate ${provider === "google" ? "Google" : "Microsoft"} account linking`, + `Failed to initiate ${isGoogleProvider(provider) ? "Google" : "Microsoft"} account linking`, ); } diff --git a/apps/web/utils/calendar/event-provider.ts b/apps/web/utils/calendar/event-provider.ts index e751533433..caa5e8f919 100644 --- a/apps/web/utils/calendar/event-provider.ts +++ b/apps/web/utils/calendar/event-provider.ts @@ -3,6 +3,7 @@ import type { Logger } from "@/utils/logger"; import type { CalendarEventProvider } from "@/utils/calendar/event-types"; import { GoogleCalendarEventProvider } from "@/utils/calendar/providers/google-events"; import { MicrosoftCalendarEventProvider } from "@/utils/calendar/providers/microsoft-events"; +import { isGoogleProvider } from "@/utils/email/provider-types"; /** * Create calendar event providers for all connected calendars. @@ -37,7 +38,7 @@ export async function createCalendarEventProviders( if (!connection.refreshToken) continue; try { - if (connection.provider === "google") { + if (isGoogleProvider(connection.provider)) { providers.push( new GoogleCalendarEventProvider( { diff --git a/apps/web/utils/calendar/unified-availability.ts b/apps/web/utils/calendar/unified-availability.ts index d62c7064e8..27e2a88377 100644 --- a/apps/web/utils/calendar/unified-availability.ts +++ b/apps/web/utils/calendar/unified-availability.ts @@ -5,6 +5,7 @@ import prisma from "@/utils/prisma"; import type { BusyPeriod } from "./availability-types"; import { createGoogleAvailabilityProvider } from "./providers/google-availability"; import { createMicrosoftAvailabilityProvider } from "./providers/microsoft-availability"; +import { isGoogleProvider } from "@/utils/email/provider-types"; /** * Fetch calendar availability across all connected calendars (Google and Microsoft) @@ -61,8 +62,8 @@ export async function getUnifiedCalendarAvailability({ } // Group calendars by provider - const googleConnections = calendarConnections.filter( - (conn) => conn.provider === "google", + const googleConnections = calendarConnections.filter((conn) => + isGoogleProvider(conn.provider), ); const microsoftConnections = calendarConnections.filter( (conn) => conn.provider === "microsoft",