From cdf846131211e7f295f3d4bf1e1858e6ad47cc36 Mon Sep 17 00:00:00 2001 From: Yassine Sallemi Date: Fri, 20 Sep 2024 16:21:30 +0100 Subject: [PATCH] fix: config fetched on runtime --- frontend/next.config.mjs | 20 ---------------- .../tables/columns/renderPicture.tsx | 4 ++++ .../src/components/inbox/components/Chat.tsx | 10 ++++++-- .../inbox/components/ChatActions.tsx | 4 +++- .../inbox/components/ConversationsList.tsx | 3 +++ .../components/inbox/helpers/mapMessages.tsx | 12 ++++------ .../components/nlp/components/NlpSample.tsx | 6 ++--- frontend/src/components/users/index.tsx | 11 ++++----- frontend/src/hooks/useApiClient.tsx | 7 +++--- frontend/src/hooks/useConfig.tsx | 9 +++---- frontend/src/layout/Header.tsx | 9 ++++--- frontend/src/layout/VerticalMenu.tsx | 11 +++++---- frontend/src/pages/api/config.ts | 2 +- frontend/src/pages/visual-editor.tsx | 9 +++---- frontend/src/websocket/SocketIoClient.ts | 9 ++----- frontend/src/websocket/socket-hooks.tsx | 24 ++++++++++++------- 16 files changed, 70 insertions(+), 80 deletions(-) diff --git a/frontend/next.config.mjs b/frontend/next.config.mjs index f1c7e508..6d0080df 100644 --- a/frontend/next.config.mjs +++ b/frontend/next.config.mjs @@ -1,8 +1,6 @@ /** @type {import('next').NextConfig} */ import withTM from "next-transpile-modules"; -const apiUrl = process.env.NEXT_PUBLIC_API_ORIGIN || "http://localhost:4000/"; -const url = new URL(apiUrl); const nextConfig = withTM(["hexabot-widget"])({ async rewrites() { return [ @@ -16,29 +14,11 @@ const nextConfig = withTM(["hexabot-widget"])({ return config; }, publicRuntimeConfig: { - apiUrl, - ssoEnabled: process.env.NEXT_PUBLIC_SSO_ENABLED === "true", lang: { default: "en", }, }, output: "standalone", - images: { - remotePatterns: [ - { - protocol: "https", - hostname: url.hostname, - port: url.port, - pathname: "/attachment/**", - }, - { - protocol: "http", - hostname: url.hostname, - port: url.port, - pathname: "/attachment/**", - }, - ], - }, }); export default nextConfig; diff --git a/frontend/src/app-components/tables/columns/renderPicture.tsx b/frontend/src/app-components/tables/columns/renderPicture.tsx index 33af1740..3684a00a 100644 --- a/frontend/src/app-components/tables/columns/renderPicture.tsx +++ b/frontend/src/app-components/tables/columns/renderPicture.tsx @@ -11,12 +11,15 @@ import { Grid } from "@mui/material"; import { GridRenderCellParams } from "@mui/x-data-grid"; import { getAvatarSrc } from "@/components/inbox/helpers/mapMessages"; +import { useConfig } from "@/hooks/useConfig"; import { EntityType } from "@/services/types"; export const buildRenderPicture = ( entityType: EntityType.USER | EntityType.SUBSCRIBER, ) => function RenderPicture(params: GridRenderCellParams) { + const { apiUrl } = useConfig(); + return ( @@ -118,6 +123,7 @@ export function Chat() { i18n.language, )}`} src={getAvatarSrc( + apiUrl, message.sender ? EntityType.SUBSCRIBER : EntityType.USER, diff --git a/frontend/src/components/inbox/components/ChatActions.tsx b/frontend/src/components/inbox/components/ChatActions.tsx index b91f5cc9..605ab2e4 100644 --- a/frontend/src/components/inbox/components/ChatActions.tsx +++ b/frontend/src/components/inbox/components/ChatActions.tsx @@ -18,12 +18,14 @@ import { Input } from "@/app-components/inputs/Input"; import { useFind } from "@/hooks/crud/useFind"; import { useUpdate } from "@/hooks/crud/useUpdate"; import { useAuth } from "@/hooks/useAuth"; +import { useConfig } from "@/hooks/useConfig"; import { EntityType } from "@/services/types"; import { getAvatarSrc } from "../helpers/mapMessages"; import { useChat } from "../hooks/ChatContext"; export const ChatActions = () => { + const { apiUrl } = useConfig(); const { t } = useTranslation(); const { subscriber: activeChat } = useChat(); const [takeoverBy, setTakeoverBy] = useState( @@ -57,7 +59,7 @@ export const ChatActions = () => { diff --git a/frontend/src/components/inbox/components/ConversationsList.tsx b/frontend/src/components/inbox/components/ConversationsList.tsx index b032f514..666cadd4 100644 --- a/frontend/src/components/inbox/components/ConversationsList.tsx +++ b/frontend/src/components/inbox/components/ConversationsList.tsx @@ -16,6 +16,7 @@ import InboxIcon from "@mui/icons-material/MoveToInbox"; import { Chip, debounce, Grid } from "@mui/material"; import { useTranslation } from "react-i18next"; +import { useConfig } from "@/hooks/useConfig"; import { Title } from "@/layout/content/Title"; import { EntityType } from "@/services/types"; @@ -29,6 +30,7 @@ export const SubscribersList = (props: { searchPayload: any; assignedTo: AssignedTo; }) => { + const { apiUrl } = useConfig(); const { t, i18n } = useTranslation(); const chat = useChat(); const { fetchNextPage, isFetching, subscribers, hasNextPage } = @@ -58,6 +60,7 @@ export const SubscribersList = (props: { > } diff --git a/frontend/src/components/users/index.tsx b/frontend/src/components/users/index.tsx index a77391bf..6cde7a77 100644 --- a/frontend/src/components/users/index.tsx +++ b/frontend/src/components/users/index.tsx @@ -11,7 +11,6 @@ import { faUsers } from "@fortawesome/free-solid-svg-icons"; import PersonAddAlt1Icon from "@mui/icons-material/PersonAddAlt1"; import { Button, Grid, Paper } from "@mui/material"; import { GridColDef } from "@mui/x-data-grid"; -import getConfig from "next/config"; import { useTranslation } from "react-i18next"; import { ChipEntity } from "@/app-components/displays/ChipEntity"; @@ -25,6 +24,7 @@ import { buildRenderPicture } from "@/app-components/tables/columns/renderPictur import { DataGrid } from "@/app-components/tables/DataGrid"; import { useFind } from "@/hooks/crud/useFind"; import { useUpdate } from "@/hooks/crud/useUpdate"; +import { useConfig } from "@/hooks/useConfig"; import { getDisplayDialogs, useDialog } from "@/hooks/useDialog"; import { useHasPermission } from "@/hooks/useHasPermission"; import { useSearch } from "@/hooks/useSearch"; @@ -39,9 +39,8 @@ import { getDateTimeFormatter } from "@/utils/date"; import { EditUserDialog } from "./EditUserDialog"; import { InvitationDialog } from "./InvitationDialog"; -const { publicRuntimeConfig } = getConfig(); - export const Users = () => { + const { ssoEnabled } = useConfig(); const { t } = useTranslation(); const { toast } = useToast(); const { mutateAsync: updateUser } = useUpdate(EntityType.USER, { @@ -157,7 +156,7 @@ export const Users = () => { }, }); }} - disabled={publicRuntimeConfig.ssoEnabled} + disabled={ssoEnabled} > {t(params.row.state ? "label.enabled" : "label.disabled")} @@ -188,7 +187,7 @@ export const Users = () => { valueGetter: (params) => t("datetime.updated_at", getDateTimeFormatter(params)), }, - ...(!publicRuntimeConfig.ssoEnabled ? [actionColumns] : []), + ...(!ssoEnabled ? [actionColumns] : []), ]; return ( @@ -207,7 +206,7 @@ export const Users = () => { - {!publicRuntimeConfig.ssoEnabled && + {!ssoEnabled && hasPermission(EntityType.USER, PermissionAction.CREATE) ? (