Files
klz-cables.com/.pnpm-store/v10/files/f5/cd5fc5267717ca00fbb2cfd9034acae0c2f09aad02ddc0a7a20c192ec4f1b464af35b09c0094f12c0b61f29ef94ba0e5e84419a2593a831671464bcd84ebc4
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
5.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useModal } from '@faceless-ui/modal';
import { formatAdminURL } from 'payload/shared';
import React, { useCallback } from 'react';
import { toast } from 'sonner';
import { useForm } from '../../forms/Form/context.js';
import { useConfig } from '../../providers/Config/index.js';
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
import { useLocale } from '../../providers/Locale/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { requests } from '../../utilities/api.js';
import { Button } from '../Button/index.js';
import { ConfirmationModal } from '../ConfirmationModal/index.js';
import './index.scss';
const baseClass = 'status';
export const Status = () => {
const {
id,
collectionSlug,
docPermissions,
globalSlug,
hasPublishedDoc,
incrementVersionCount,
isTrashed,
setMostRecentVersionIsAutosaved,
setUnpublishedVersionCount,
unpublishedVersionCount
} = useDocumentInfo();
const {
toggleModal
} = useModal();
const {
config: {
routes: {
api
}
}
} = useConfig();
const {
reset: resetForm
} = useForm();
const {
code: locale
} = useLocale();
const {
i18n,
t
} = useTranslation();
const revertModalSlug = `confirm-revert-${id}`;
let statusToRender;
if (unpublishedVersionCount > 0 && hasPublishedDoc) {
statusToRender = 'changed';
} else if (!hasPublishedDoc) {
statusToRender = 'draft';
} else if (hasPublishedDoc && unpublishedVersionCount <= 0) {
statusToRender = 'published';
}
const displayStatusKey = isTrashed ? hasPublishedDoc ? 'previouslyPublished' : 'previouslyDraft' : statusToRender;
const performAction = useCallback(async () => {
let url;
let method;
if (collectionSlug) {
url = formatAdminURL({
apiRoute: api,
path: `/${collectionSlug}/${id}?locale=${locale}&fallback-locale=null&depth=0`
});
method = 'patch';
}
if (globalSlug) {
url = formatAdminURL({
apiRoute: api,
path: `/globals/${globalSlug}?locale=${locale}&fallback-locale=null&depth=0`
});
method = 'post';
}
const publishedDoc = await requests.get(url, {
headers: {
'Accept-Language': i18n.language,
'Content-Type': 'application/json'
}
}).then(res => res.json());
const body = publishedDoc;
const res_0 = await requests[method](url, {
body: JSON.stringify(body),
headers: {
'Accept-Language': i18n.language,
'Content-Type': 'application/json'
}
});
if (res_0.status === 200) {
let data;
const json = await res_0.json();
if (globalSlug) {
data = json.result;
} else if (collectionSlug) {
data = json.doc;
}
// eslint-disable-next-line @typescript-eslint/no-floating-promises
resetForm(data);
toast.success(json.message);
incrementVersionCount();
setMostRecentVersionIsAutosaved(false);
setUnpublishedVersionCount(0);
} else {
try {
const json_0 = await res_0.json();
if (json_0.errors?.[0]?.message) {
toast.error(json_0.errors[0].message);
} else if (json_0.error) {
toast.error(json_0.error);
} else {
toast.error(t('error:revertingDocument'));
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
toast.error(t('error:revertingDocument'));
}
}
}, [api, collectionSlug, globalSlug, id, i18n.language, incrementVersionCount, locale, resetForm, setUnpublishedVersionCount, setMostRecentVersionIsAutosaved, t]);
const canUpdate = docPermissions?.update;
if (statusToRender) {
return /*#__PURE__*/_jsx("div", {
className: baseClass,
title: `${t('version:status')}: ${t(`version:${displayStatusKey}`)}`,
children: /*#__PURE__*/_jsxs("div", {
className: `${baseClass}__value-wrap`,
children: [/*#__PURE__*/_jsxs("span", {
className: `${baseClass}__label`,
children: [t('version:status'), ": "]
}), /*#__PURE__*/_jsx("span", {
className: `${baseClass}__value`,
children: t(`version:${displayStatusKey}`)
}), !isTrashed && canUpdate && hasPublishedDoc && statusToRender === 'changed' && /*#__PURE__*/_jsxs(React.Fragment, {
children: [" — ", /*#__PURE__*/_jsx(Button, {
buttonStyle: "none",
className: `${baseClass}__action`,
id: "action-revert-to-published",
onClick: () => toggleModal(revertModalSlug),
children: t('version:revertToPublished')
}), /*#__PURE__*/_jsx(ConfirmationModal, {
body: t('version:aboutToRevertToPublished'),
confirmingLabel: t('version:reverting'),
heading: t('version:confirmRevertToSaved'),
modalSlug: revertModalSlug,
onConfirm: () => performAction()
})]
})]
})
});
}
return null;
};
//# sourceMappingURL=index.js.map