Files
klz-cables.com/.pnpm-store/v10/files/5c/feb9c10d77bdfed4631d270d67c3b03016a95cab2fd87c3525cec3525f7ab2e90ceb02e485fd94b3811352f459b548a3b1b66f9ea1e68a848a53cddde1ba12
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

155 lines
4.5 KiB
Plaintext

import { jsx as _jsx } from "react/jsx-runtime";
import { getTranslation } from '@payloadcms/translations';
import { useRouter, useSearchParams } from 'next/navigation.js';
import { combineWhereConstraints, formatAdminURL, mergeListSearchAndWhere } from 'payload/shared';
import * as qs from 'qs-esm';
import React, { useCallback } from 'react';
import { toast } from 'sonner';
import { useConfig } from '../../providers/Config/index.js';
import { useLocale } from '../../providers/Locale/index.js';
import { useRouteCache } from '../../providers/RouteCache/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { requests } from '../../utilities/api.js';
import { parseSearchParams } from '../../utilities/parseSearchParams.js';
import { ConfirmationModal } from '../ConfirmationModal/index.js';
export function PublishManyDrawerContent(props) {
const {
collection,
collection: {
slug,
labels: {
plural,
singular
}
} = {},
drawerSlug,
ids,
onSuccess,
selectAll,
where
} = props;
const {
clearRouteCache
} = useRouteCache();
const {
config: {
routes: {
api
}
}
} = useConfig();
const {
code: locale
} = useLocale();
const router = useRouter();
const searchParams = useSearchParams();
const {
i18n,
t
} = useTranslation();
const addDefaultError = useCallback(() => {
toast.error(t('error:unknown'));
}, [t]);
const queryString = React.useMemo(() => {
const whereConstraints = [{
_status: {
not_equals: 'published'
}
}];
if (where) {
whereConstraints.push(where);
}
const queryWithSearch = mergeListSearchAndWhere({
collectionConfig: collection,
search: searchParams.get('search')
});
if (queryWithSearch) {
whereConstraints.push(queryWithSearch);
}
if (selectAll) {
// Match the current filter/search, or default to all docs
whereConstraints.push(parseSearchParams(searchParams)?.where || {
id: {
not_equals: ''
}
});
} else {
// If we're not selecting all, we need to select specific docs
whereConstraints.push({
id: {
in: ids || []
}
});
}
return qs.stringify({
locale,
select: {},
where: combineWhereConstraints(whereConstraints)
}, {
addQueryPrefix: true
});
}, [collection, searchParams, selectAll, ids, locale, where]);
const handlePublish = useCallback(async () => {
const url = formatAdminURL({
apiRoute: api,
path: `/${slug}${queryString}&draft=true`
});
await requests.patch(url, {
body: JSON.stringify({
_status: 'published'
}),
headers: {
'Accept-Language': i18n.language,
'Content-Type': 'application/json'
}
}).then(async res => {
try {
const json = await res.json();
const deletedDocs = json?.docs.length || 0;
const successLabel = deletedDocs > 1 ? plural : singular;
if (res.status < 400 || deletedDocs > 0) {
toast.success(t('general:updatedCountSuccessfully', {
count: deletedDocs,
label: getTranslation(successLabel, i18n)
}));
if (json?.errors.length > 0) {
toast.error(json.message, {
description: json.errors.map(error => error.message).join('\n')
});
}
router.replace(qs.stringify({
...parseSearchParams(searchParams),
page: selectAll ? '1' : undefined
}, {
addQueryPrefix: true
}));
clearRouteCache();
if (typeof onSuccess === 'function') {
onSuccess();
}
return null;
}
if (json.errors) {
json.errors.forEach(error => toast.error(error.message));
} else {
addDefaultError();
}
return false;
} catch (_err) {
return addDefaultError();
}
});
}, [api, slug, queryString, i18n, plural, singular, t, router, searchParams, selectAll, clearRouteCache, addDefaultError, onSuccess]);
return /*#__PURE__*/_jsx(ConfirmationModal, {
body: t('version:aboutToPublishSelection', {
label: getTranslation(plural, i18n)
}),
cancelLabel: t('general:cancel'),
confirmingLabel: t('version:publishing'),
confirmLabel: t('general:confirm'),
heading: t('version:confirmPublish'),
modalSlug: drawerSlug,
onConfirm: handlePublish
});
}
//# sourceMappingURL=DrawerContent.js.map