From 0e9bbd296534ae88bd9e019a6e7e7a4847f5f7eb Mon Sep 17 00:00:00 2001 From: gasp Date: Sat, 3 Feb 2024 10:19:23 +0100 Subject: [PATCH] fix: use VITE_ prefix --- .env.example | 3 +- modules/web/web-app/App.tsx | 1 - modules/web/web-app/hooks/useFlags.tsx | 11 ---- modules/web/web-app/lib/env.ts | 8 +-- .../web/web-app/providers/FlagsProvider.tsx | 52 ------------------- 5 files changed, 3 insertions(+), 72 deletions(-) delete mode 100644 modules/web/web-app/hooks/useFlags.tsx delete mode 100644 modules/web/web-app/providers/FlagsProvider.tsx diff --git a/.env.example b/.env.example index 430fbd50..bf0f070a 100644 --- a/.env.example +++ b/.env.example @@ -19,8 +19,7 @@ DATABASE_NAME=meteroid DATABASE_URL=postgres://${DATABASE_USER}:${DATABASE_PASSWORD}@localhost:5432/${DATABASE_NAME}?sslmode=disable ## Web front -VITE_DEBUG_MODE=${DEBUG} -VITE_API_URL=http://127.0.0.1:${WEB_API_PORT} +VITE_METEROID_API_EXTERNAL_URL=${METEROID_API_EXTERNAL_URL} ## Kafka KAFKA_BOOTSTRAP_SERVERS=127.0.0.1:9092 diff --git a/modules/web/web-app/App.tsx b/modules/web/web-app/App.tsx index 7761bc98..6d229f58 100644 --- a/modules/web/web-app/App.tsx +++ b/modules/web/web-app/App.tsx @@ -1,7 +1,6 @@ import { TransportProvider } from '@connectrpc/connect-query' import { createGrpcWebTransport } from '@connectrpc/connect-web' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' -import { ReactQueryDevtools } from '@tanstack/react-query-devtools' import { RouterProvider } from 'react-router-dom' import { authInterceptor, errorInterceptor, loggingInterceptor } from '@/lib/connectrpc' diff --git a/modules/web/web-app/hooks/useFlags.tsx b/modules/web/web-app/hooks/useFlags.tsx deleted file mode 100644 index e433531a..00000000 --- a/modules/web/web-app/hooks/useFlags.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { useContext } from 'react' - -import { FlagContext } from 'providers/FlagsProvider' - -export const useFlags = () => { - const { flags } = useContext(FlagContext) - - if (!flags) throw new Error('Flags context was not initialized') - - return flags -} diff --git a/modules/web/web-app/lib/env.ts b/modules/web/web-app/lib/env.ts index 20c7b545..c8831ac8 100644 --- a/modules/web/web-app/lib/env.ts +++ b/modules/web/web-app/lib/env.ts @@ -2,13 +2,9 @@ import { parseEnv } from '@md/common' import { z } from 'zod' const _env = parseEnv(import.meta.env, { - VITE_DEBUG_MODE: z.boolean().default(false), - VITE_API_URL: z.string().default('http://127.0.0.1:8000'), - METEROID_API_EXTERNAL_URL: z.string().default('http://127.0.0.1:50061'), + VITE_METEROID_API_EXTERNAL_URL: z.string().default('http://127.0.0.1:50061'), }) export const env = { - isDebug: _env.VITE_DEBUG_MODE, - apiUrl: _env.VITE_API_URL, - meteroidApiUri: _env.METEROID_API_EXTERNAL_URL, + meteroidApiUri: _env.VITE_METEROID_API_EXTERNAL_URL, } diff --git a/modules/web/web-app/providers/FlagsProvider.tsx b/modules/web/web-app/providers/FlagsProvider.tsx deleted file mode 100644 index c41d981b..00000000 --- a/modules/web/web-app/providers/FlagsProvider.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import { useQuery } from '@tanstack/react-query' -import { createContext, useContext } from 'react' - -import PageLoader from '@/components/atoms/PageLoader/PageLoader' -import { env } from '@/lib/env' - -interface FlagProviderProps { - children?: React.ReactNode -} - -interface FlagData { - orySdkUrl: string -} - -export const FlagContext = createContext<{ - flags: FlagData | null -}>({ flags: null }) - -const FLAGS_API_URL = `${env.apiUrl}/.flags` - -async function fetchConfigFromBackend() { - try { - const response = await fetch(FLAGS_API_URL) - const config = await response.json() - return config as FlagData - } catch (error) { - console.error('Error fetching configuration from backend:', error) - return null - } -} - -export const FlagsProvider: React.FC = ({ children }) => { - const query = useQuery({ - queryKey: ['todos'], - queryFn: fetchConfigFromBackend, - }) - // TODO handle errors - - return query.data ? ( - {children} - ) : ( - - ) -} - -export const useFlags = () => { - const { flags } = useContext(FlagContext) - - if (!flags) throw new Error('Flags context was not initialized') - - return flags -}