fix(plugin-search): gets api route from useConfig (#10632)
This fixes #10631. Originally the api basepath for the reindex button is resolved during plugin initialization. Looks like this happens before payload overrides the config with the `basePath `from the next config. I've changed it so that it uses the `useConfig` hook, and manually tested that it works. 
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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<ReindexButtonProps> = ({
|
||||
apiBasePath,
|
||||
collectionLabels,
|
||||
searchCollections,
|
||||
searchSlug,
|
||||
}) => {
|
||||
const apiBasePath = useConfig().config.routes.api
|
||||
const { closeModal, openModal } = useModal()
|
||||
const {
|
||||
i18n: { t },
|
||||
|
||||
@@ -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 (
|
||||
<ReindexButtonClient
|
||||
apiBasePath={apiBasePath}
|
||||
collectionLabels={getStaticLocalizedPluralLabels()}
|
||||
searchCollections={searchCollections}
|
||||
searchSlug={searchSlug}
|
||||
|
||||
@@ -3,7 +3,6 @@ import type { CustomComponent, PayloadServerReactComponent, StaticLabel } from '
|
||||
import type { CollectionLabels } from '../../../types.js'
|
||||
|
||||
export type ReindexButtonProps = {
|
||||
apiBasePath: string
|
||||
collectionLabels: Record<string, StaticLabel>
|
||||
searchCollections: string[]
|
||||
searchSlug: string
|
||||
|
||||
Reference in New Issue
Block a user