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
95 lines
2.9 KiB
Plaintext
95 lines
2.9 KiB
Plaintext
'use client';
|
|
|
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
import { formatAdminURL } from 'payload/shared';
|
|
import React, { useEffect } from 'react';
|
|
// eslint-disable-next-line payload/no-imports-from-exports-dir
|
|
import { MoveDocToFolderButton, useConfig, useTranslation } from '../../../exports/client/index.js';
|
|
export const FolderTableCellClient = ({
|
|
collectionSlug,
|
|
data,
|
|
docTitle,
|
|
folderCollectionSlug,
|
|
folderFieldName,
|
|
viewType
|
|
}) => {
|
|
const docID = data.id;
|
|
const intialFolderID = data?.[folderFieldName];
|
|
const {
|
|
config
|
|
} = useConfig();
|
|
const {
|
|
t
|
|
} = useTranslation();
|
|
const [fromFolderName, setFromFolderName] = React.useState(() => intialFolderID ? `${t('general:loading')}...` : t('folder:noFolder'));
|
|
const [fromFolderID, setFromFolderID] = React.useState(intialFolderID);
|
|
const hasLoadedFolderName = React.useRef(false);
|
|
const onConfirm = React.useCallback(async ({
|
|
id,
|
|
name
|
|
}) => {
|
|
try {
|
|
await fetch(formatAdminURL({
|
|
apiRoute: config.routes.api,
|
|
path: `/${collectionSlug}/${docID}`
|
|
}), {
|
|
body: JSON.stringify({
|
|
[folderFieldName]: id
|
|
}),
|
|
credentials: 'include',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
method: 'PATCH'
|
|
});
|
|
setFromFolderID(id);
|
|
setFromFolderName(name || t('folder:noFolder'));
|
|
} catch (error) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('Error moving document to folder', error);
|
|
}
|
|
}, [config.routes.api, collectionSlug, docID, folderFieldName, t]);
|
|
useEffect(() => {
|
|
const loadFolderName = async () => {
|
|
try {
|
|
const req = await fetch(formatAdminURL({
|
|
apiRoute: config.routes.api,
|
|
path: `/${folderCollectionSlug}${intialFolderID ? `/${intialFolderID}` : ''}`
|
|
}), {
|
|
credentials: 'include',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
method: 'GET'
|
|
});
|
|
const res = await req.json();
|
|
setFromFolderName(res?.name || t('folder:noFolder'));
|
|
} catch (error_0) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('Error moving document to folder', error_0);
|
|
}
|
|
};
|
|
if (!hasLoadedFolderName.current) {
|
|
void loadFolderName();
|
|
hasLoadedFolderName.current = true;
|
|
}
|
|
}, [config.routes.api, folderCollectionSlug, intialFolderID, t]);
|
|
return /*#__PURE__*/_jsx(MoveDocToFolderButton, {
|
|
buttonProps: {
|
|
disabled: viewType === 'trash',
|
|
size: 'small'
|
|
},
|
|
collectionSlug: collectionSlug,
|
|
docData: data,
|
|
docID: docID,
|
|
docTitle: docTitle,
|
|
folderCollectionSlug: folderCollectionSlug,
|
|
folderFieldName: folderFieldName,
|
|
fromFolderID: fromFolderID,
|
|
fromFolderName: fromFolderName,
|
|
modalSlug: `move-doc-to-folder-cell--${docID}`,
|
|
onConfirm: onConfirm,
|
|
skipConfirmModal: false
|
|
});
|
|
};
|
|
//# sourceMappingURL=index.client.js.map |