From d12c60a2343608abfb73b000f55ddf7f4937ca93 Mon Sep 17 00:00:00 2001 From: Suphon Thanakornpakapong <8080853+suphon-t@users.noreply.github.com> Date: Fri, 17 Jan 2025 15:55:01 +0700 Subject: [PATCH] fix(search): get api route from useConfig --- packages/plugin-search/src/Search/index.ts | 2 -- .../plugin-search/src/Search/ui/ReindexButton/index.client.tsx | 3 ++- packages/plugin-search/src/Search/ui/ReindexButton/index.tsx | 3 +-- packages/plugin-search/src/Search/ui/ReindexButton/types.ts | 1 - 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/plugin-search/src/Search/index.ts b/packages/plugin-search/src/Search/index.ts index 47769c17d8b..2135f91364b 100644 --- a/packages/plugin-search/src/Search/index.ts +++ b/packages/plugin-search/src/Search/index.ts @@ -8,7 +8,6 @@ import { generateReindexHandler } from '../utilities/generateReindexHandler.js' export const generateSearchCollection = ( pluginConfig: SearchPluginConfigWithLocales, ): CollectionConfig => { - const apiBasePath = pluginConfig?.apiBasePath || '/api' const searchSlug = pluginConfig?.searchOverrides?.slug || 'search' const searchCollections = pluginConfig?.collections || [] const collectionLabels = pluginConfig?.labels @@ -71,7 +70,6 @@ export const generateSearchCollection = ( { path: '@payloadcms/plugin-search/client#ReindexButton', serverProps: { - apiBasePath, collectionLabels, searchCollections, searchSlug, diff --git a/packages/plugin-search/src/Search/ui/ReindexButton/index.client.tsx b/packages/plugin-search/src/Search/ui/ReindexButton/index.client.tsx index 5d6c22368a7..9e660aee344 100644 --- a/packages/plugin-search/src/Search/ui/ReindexButton/index.client.tsx +++ b/packages/plugin-search/src/Search/ui/ReindexButton/index.client.tsx @@ -5,6 +5,7 @@ import { Popup, PopupList, toast, + useConfig, useLocale, useModal, useTranslation, @@ -20,11 +21,11 @@ import { ReindexConfirmModal } from './ReindexConfirmModal/index.js' const confirmReindexModalSlug = 'confirm-reindex-modal' export const ReindexButtonClient: React.FC = ({ - apiBasePath, collectionLabels, searchCollections, searchSlug, }) => { + const apiBasePath = useConfig().config.routes.api const { closeModal, openModal } = useModal() const { i18n: { t }, diff --git a/packages/plugin-search/src/Search/ui/ReindexButton/index.tsx b/packages/plugin-search/src/Search/ui/ReindexButton/index.tsx index 05d465a7b7c..fbc341a75ce 100644 --- a/packages/plugin-search/src/Search/ui/ReindexButton/index.tsx +++ b/packages/plugin-search/src/Search/ui/ReindexButton/index.tsx @@ -3,7 +3,7 @@ import type { SearchReindexButtonServerComponent } from './types.js' import { ReindexButtonClient } from './index.client.js' export const ReindexButton: SearchReindexButtonServerComponent = (props) => { - const { apiBasePath, collectionLabels, i18n, searchCollections, searchSlug } = props + const { collectionLabels, i18n, searchCollections, searchSlug } = props const getStaticLocalizedPluralLabels = () => { return Object.fromEntries( @@ -26,7 +26,6 @@ export const ReindexButton: SearchReindexButtonServerComponent = (props) => { return ( searchCollections: string[] searchSlug: string