refactor: Delete isPlainObject type guard and replace its usages with direct typeof checks.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { isPlainObject } from '../../utils/typeGuards';
|
||||
|
||||
|
||||
type ApiClient = {
|
||||
post: (path: string, body?: unknown) => Promise<{ data: unknown }>;
|
||||
@@ -124,16 +124,14 @@ const useDocumentCorrespondentActions = ({
|
||||
if (!option) {
|
||||
return null;
|
||||
}
|
||||
if (isPlainObject(option) && 'id' in option) {
|
||||
return option as CorrespondentOption;
|
||||
}
|
||||
if (typeof option === 'string') {
|
||||
const trimmed = option.trim();
|
||||
if (trimmed) {
|
||||
return { id: null, name: trimmed };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
return option;
|
||||
};
|
||||
|
||||
const handleCorrespondentAdd = useCallback(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useCallback } from 'react';
|
||||
import { isPlainObject } from '../../utils/typeGuards';
|
||||
|
||||
import type { Dispatch, MutableRefObject, SetStateAction } from 'react';
|
||||
import { DEFAULT_FOLDER_NAME, getRowId, isDocumentRowKey } from '../../app/appLayoutUtils';
|
||||
import {
|
||||
@@ -66,7 +66,7 @@ interface DocumentLike {
|
||||
|
||||
interface FolderContents {
|
||||
documents?: DocumentLike[];
|
||||
subfolders?: Array<{ id?: FolderId; [key: string]: unknown }>;
|
||||
subfolders?: Array<{ id?: FolderId;[key: string]: unknown }>;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ interface UseDocumentMutationsResult {
|
||||
|
||||
const normalizeDocumentId = (value: unknown): DocumentId | null => {
|
||||
if (!value) return null;
|
||||
if (isPlainObject(value) && 'id' in value && value.id != null) {
|
||||
if (value && typeof value === 'object' && 'id' in value && value.id != null) {
|
||||
return value.id as DocumentId;
|
||||
}
|
||||
return value as DocumentId;
|
||||
@@ -446,7 +446,7 @@ const useDocumentMutations = ({
|
||||
},
|
||||
[
|
||||
token,
|
||||
documentLookup,
|
||||
|
||||
removeDocumentsFromCaches,
|
||||
previewDocumentId,
|
||||
closeDocumentPreview,
|
||||
@@ -495,7 +495,8 @@ const useDocumentMutations = ({
|
||||
);
|
||||
|
||||
const handleDocumentIssuedUpdate = useCallback(
|
||||
async (documentId: DocumentId, nextIssuedDate: number | null) => {const payload = { issued_at: nextIssuedDate || null };
|
||||
async (documentId: DocumentId, nextIssuedDate: number | null) => {
|
||||
const payload = { issued_at: nextIssuedDate || null };
|
||||
try {
|
||||
const data = await updateDocument(documentId, payload);
|
||||
const updatedDocument = extractDocumentFromResponse?.(data);
|
||||
|
||||
Reference in New Issue
Block a user