Files
klz-cables.com/.pnpm-store/v10/files/f4/7213e4d30ef6fdc72bbcea86df206c7983f943019ddb7cd0ef24a7426396c15477f3d04673cbfb82ab25dc00631be3a948601251572deceeb34715b4abedee
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

146 lines
4.2 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 UnpublishManyDrawerContent(props) {
const {
collection,
collection: {
slug,
labels: {
plural,
singular
}
} = {},
drawerSlug,
ids,
onSuccess,
selectAll,
where
} = props;
const {
config: {
routes: {
api
}
}
} = useConfig();
const {
code: locale
} = useLocale();
const {
i18n,
t
} = useTranslation();
const searchParams = useSearchParams();
const router = useRouter();
const {
clearRouteCache
} = useRouteCache();
const addDefaultError = useCallback(() => {
toast.error(t('error:unknown'));
}, [t]);
const queryString = React.useMemo(() => {
const whereConstraints = [{
_status: {
not_equals: 'draft'
}
}];
if (where) {
whereConstraints.push(where);
}
const queryWithSearch = mergeListSearchAndWhere({
collectionConfig: collection,
search: searchParams.get('search')
});
if (queryWithSearch) {
whereConstraints.push(queryWithSearch);
}
if (!selectAll) {
// 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 handleUnpublish = useCallback(async () => {
const url = formatAdminURL({
apiRoute: api,
path: `/${slug}${queryString}`
});
await requests.patch(url, {
body: JSON.stringify({
_status: 'draft'
}),
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:aboutToUnpublishSelection', {
label: getTranslation(plural, i18n)
}),
confirmingLabel: t('version:unpublishing'),
heading: t('version:confirmUnpublish'),
modalSlug: drawerSlug,
onConfirm: handleUnpublish
});
}
//# sourceMappingURL=DrawerContent.js.map