This commit is contained in:
2025-11-12 17:02:27 +01:00
parent d2e27c12a2
commit b812d748ea
44 changed files with 221 additions and 356 deletions
@@ -68,7 +68,7 @@ const useAuthManager = ({
}
const status = response.status;
const url = typeof config.url === 'string' ? config.url : '';
const url = String(config?.url ?? '');
const isAuthRoute = url.includes('/auth/login') || url.includes('/auth/refresh');
if (status === 401 && !config._retry && !isAuthRoute) {
@@ -32,7 +32,7 @@ const useCorrespondents = ({
}
const payload = {};
if (typeof changes.name === 'string') {
if (typeof changes?.name?.trim === 'function') {
const trimmed = changes.name.trim();
if (!trimmed) {
throw new Error('Correspondent name cannot be empty.');
@@ -60,7 +60,7 @@ const useCorrespondents = ({
const handleCorrespondentCreate = useCallback(
async ({ name }) => {
const trimmed = typeof name === 'string' ? name.trim() : '';
const trimmed = name?.trim?.() || '';
if (!trimmed) {
throw new Error('Correspondent name is required.');
}
@@ -72,7 +72,7 @@ const useDocumentCorrespondentActions = ({
if (!document?.id) {
throw new Error('Missing document for correspondent assignment.');
}
const trimmed = typeof name === 'string' ? name.trim() : '';
const trimmed = name?.trim?.() || '';
if (!trimmed) {
setStatusMessage('Correspondent name is required.', 'error');
return;
@@ -29,10 +29,6 @@ const useDocumentDragHandlers = ({
({ documents = [], folders = [] } = {}) => {
destroyDragPreview();
if (typeof document === 'undefined') {
return null;
}
const docEntries = (documents || []).filter(Boolean);
const folderEntries = (folders || []).filter(Boolean);
const totalCount = docEntries.length + folderEntries.length;
@@ -108,7 +104,7 @@ const useDocumentDragHandlers = ({
}
} else {
const payload = item.payload;
const folderId = typeof payload === 'string' ? payload : payload?.id;
const folderId = payload?.id ?? (typeof payload?.trim === 'function' ? payload : null);
const rowEl = folderId
? document.getElementById(`folder-row-${folderId}`)
|| document.getElementById(`folder-card-${folderId}`)
@@ -160,7 +156,7 @@ const useDocumentDragHandlers = ({
const handleDocumentDragStart = useCallback(
(event, documentOrId) => {
const documentId = typeof documentOrId === 'string' ? documentOrId : documentOrId?.id;
const documentId = documentOrId?.id ?? (typeof documentOrId?.trim === 'function' ? documentOrId : null);
if (!documentId) {
return;
}
@@ -313,7 +313,7 @@ const useDocumentMutations = ({
const handleDocumentTitleUpdate = useCallback(
async (documentId, nextTitle) => {
const trimmed = typeof nextTitle === 'string' ? nextTitle.trim() : '';
const trimmed = nextTitle?.trim?.() || '';
if (!trimmed) {
setStatusMessage('Document title cannot be empty.', 'error');
return false;
@@ -418,7 +418,7 @@ const useDocumentMutations = ({
const resolveTagForCache = () => {
const lookupTag = tagLookupById.get(tagId);
const source = lookupTag ?? tagData;
if (!source || source.id == null || typeof source.label !== 'string') {
if (!source || source.id == null || typeof source.label?.trim !== 'function') {
return null;
}
return {
@@ -98,7 +98,7 @@ const useDocumentTagging = ({
const handleBulkTagAddFromDetail = useCallback(
async ({ label, input, documentIds }) => {
const trimmed = typeof label === 'string' ? label.trim() : '';
const trimmed = label?.trim?.() || '';
if (!trimmed) {
setStatusMessage('Enter a tag label.', 'error');
return;
@@ -131,7 +131,7 @@ const useDocumentTagging = ({
const handleBulkTagRemoveFromDetail = useCallback(
async ({ label, input, documentIds }) => {
const trimmed = typeof label === 'string' ? label.trim() : '';
const trimmed = label?.trim?.() || '';
if (!trimmed) {
setStatusMessage('Enter a tag label to remove.', 'error');
return;
@@ -201,4 +201,3 @@ const useDocumentTagging = ({
};
export default useDocumentTagging;
@@ -10,8 +10,7 @@ const mapFilesToEntries = (filesInput) => {
return files
.filter(Boolean)
.map((file) => {
const relativePath =
typeof file.webkitRelativePath === 'string' ? file.webkitRelativePath : '';
const relativePath = file?.webkitRelativePath ?? '';
const segments = relativePath
? relativePath
.split('/')
@@ -213,10 +212,7 @@ const useDocumentUploads = ({
const fileFromItem = typeof item.getAsFile === 'function' ? item.getAsFile() : null;
if (fileFromItem) {
const relativePath =
typeof fileFromItem.webkitRelativePath === 'string'
? fileFromItem.webkitRelativePath
: '';
const relativePath = fileFromItem?.webkitRelativePath ?? '';
const segments = relativePath
? relativePath
.split('/')
@@ -246,8 +242,7 @@ const useDocumentUploads = ({
Array.from(dataTransfer.files || []).forEach((file) => {
if (!file) return;
const relativePath =
typeof file.webkitRelativePath === 'string' ? file.webkitRelativePath : '';
const relativePath = file?.webkitRelativePath ?? '';
const segments = relativePath
? relativePath
.split('/')
@@ -135,9 +135,6 @@ const useDocumentsWorkspace = ({
const tenantIdRef = useRef(currentTenantId);
const detailPanelControlRef = useRef({ open: () => {}, close: () => {} });
const setTagRemovalCursor = useCallback((active) => {
if (typeof document === 'undefined') {
return;
}
if (tagRemovalCursorActiveRef.current === active) {
return;
}
@@ -201,7 +201,7 @@ const useFolderTreeActions = ({
setStatusMessage('Log in to rename folders.', 'error');
return false;
}
const trimmed = typeof nextName === 'string' ? nextName.trim() : '';
const trimmed = nextName?.trim?.() || '';
if (!trimmed) {
setStatusMessage('Folder name cannot be empty.', 'error');
return false;
+1 -1
View File
@@ -34,7 +34,7 @@ const useTags = ({
}
const payload = {};
if (typeof changes.label === 'string') {
if (typeof changes?.label?.trim === 'function') {
payload.label = changes.label;
}
if (Object.prototype.hasOwnProperty.call(changes, 'color')) {