Files
klz-cables.com/.pnpm-store/v10/files/92/47242f702d715a106f72c3588381cc40250f5815554c7fbbfdc2a76f1b89980ea6e3955a4c4b48c4c282e6ada555d4b2441fdb8c32325ef16b9773a0a28710
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

105 lines
2.8 KiB
Plaintext

'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { formatAdminURL } from 'payload/shared';
import React, { useCallback, useRef } from 'react';
import { useForm, useFormModified } from '../../forms/Form/context.js';
import { FormSubmit } from '../../forms/Submit/index.js';
import { useHotkey } from '../../hooks/useHotkey.js';
import { useConfig } from '../../providers/Config/index.js';
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
import { useEditDepth } from '../../providers/EditDepth/index.js';
import { useLocale } from '../../providers/Locale/index.js';
import { useOperation } from '../../providers/Operation/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
const baseClass = 'save-draft';
export function SaveDraftButton(props) {
const {
config: {
routes: {
api
}
}
} = useConfig();
const {
id,
collectionSlug,
globalSlug,
setUnpublishedVersionCount,
uploadStatus
} = useDocumentInfo();
const modified = useFormModified();
const {
code: locale
} = useLocale();
const ref = useRef(null);
const editDepth = useEditDepth();
const {
t
} = useTranslation();
const {
submit
} = useForm();
const operation = useOperation();
const disabled = operation === 'update' && !modified || uploadStatus === 'uploading';
const saveDraft = useCallback(async () => {
if (disabled) {
return;
}
const search = `?locale=${locale}&depth=0&fallback-locale=null&draft=true`;
let action;
let method = 'POST';
if (collectionSlug) {
action = formatAdminURL({
apiRoute: api,
path: `/${collectionSlug}${id ? `/${id}` : ''}${search}`
});
if (id) {
method = 'PATCH';
}
}
if (globalSlug) {
action = formatAdminURL({
apiRoute: api,
path: `/globals/${globalSlug}${search}`
});
}
await submit({
action,
method,
overrides: {
_status: 'draft'
},
skipValidation: true
});
setUnpublishedVersionCount(count => count + 1);
}, [submit, collectionSlug, globalSlug, api, locale, id, disabled, setUnpublishedVersionCount]);
useHotkey({
cmdCtrlKey: true,
editDepth,
keyCodes: ['s']
}, e => {
if (disabled) {
// absorb the event
}
e.preventDefault();
e.stopPropagation();
if (ref?.current) {
ref.current.click();
}
});
return /*#__PURE__*/_jsx(FormSubmit, {
buttonId: "action-save-draft",
buttonStyle: "secondary",
className: baseClass,
disabled: disabled,
onClick: () => {
return void saveDraft();
},
ref: ref,
size: "medium",
type: "button",
children: t('version:saveDraft')
});
}
//# sourceMappingURL=index.js.map