cleanup
This commit is contained in:
+23
-23
@@ -55,7 +55,7 @@ const api = axios.create({
|
||||
});
|
||||
|
||||
const storage = typeof window !== 'undefined' ? window.sessionStorage : undefined;
|
||||
const STORED_TOKEN = storage?.getItem('papercrate_token') || '';
|
||||
const STORED_TOKEN = storage?.getItem('papercrate_token') ?? '';
|
||||
let STORED_TENANT = null;
|
||||
if (storage) {
|
||||
try {
|
||||
@@ -192,7 +192,7 @@ const AppStateProvider = ({ children }) => {
|
||||
const [state, dispatch] = useReducer(appStateReducer, initialAppState);
|
||||
|
||||
useEffect(() => {
|
||||
const token = state.token || '';
|
||||
const token = state.token ?? '';
|
||||
if (token) {
|
||||
api.defaults.headers.common.Authorization = `Bearer ${token}`;
|
||||
storage?.setItem('papercrate_token', token);
|
||||
@@ -1952,7 +1952,7 @@ const AppLayout = () => {
|
||||
|
||||
const handleCorrespondentCreate = useCallback(
|
||||
async ({ name }) => {
|
||||
const trimmed = (name || '').trim();
|
||||
const trimmed = typeof name === 'string' ? name.trim() : '';
|
||||
if (!trimmed) {
|
||||
throw new Error('Correspondent name is required.');
|
||||
}
|
||||
@@ -2073,7 +2073,7 @@ const AppLayout = () => {
|
||||
if (!document?.id) {
|
||||
throw new Error('Missing document for correspondent assignment.');
|
||||
}
|
||||
const trimmed = (name || '').trim();
|
||||
const trimmed = typeof name === 'string' ? name.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Correspondent name is required.', 'error');
|
||||
return;
|
||||
@@ -2149,7 +2149,7 @@ const AppLayout = () => {
|
||||
|
||||
const handleDocumentTypeCreate = useCallback(
|
||||
async ({ name }) => {
|
||||
const trimmed = (name || '').trim();
|
||||
const trimmed = typeof name === 'string' ? name.trim() : '';
|
||||
if (!trimmed) {
|
||||
throw new Error('Document type name is required.');
|
||||
}
|
||||
@@ -2184,12 +2184,8 @@ const AppLayout = () => {
|
||||
}
|
||||
|
||||
const existingType = doc.document_type;
|
||||
const existingTypeId =
|
||||
doc.document_type_id ?? (typeof existingType === 'object' ? existingType?.id : null);
|
||||
const existingTypeName =
|
||||
typeof existingType === 'string'
|
||||
? existingType
|
||||
: existingType?.name || existingType?.label || '';
|
||||
const existingTypeId = doc.document_type_id ?? existingType?.id ?? null;
|
||||
const existingTypeName = typeof existingType?.name === 'string' ? existingType.name : undefined;
|
||||
|
||||
const shouldClear =
|
||||
existingTypeId === documentTypeId ||
|
||||
@@ -2223,7 +2219,7 @@ const AppLayout = () => {
|
||||
);
|
||||
|
||||
const handleDocumentTypeAssign = useCallback(
|
||||
async ({ documentId, documentTypeId }, { notify = true } = {}) => {
|
||||
async ({ documentId, documentTypeId, documentType }, { notify = true } = {}) => {
|
||||
if (!documentId) {
|
||||
throw new Error('Missing document identifier.');
|
||||
}
|
||||
@@ -2240,8 +2236,12 @@ const AppLayout = () => {
|
||||
|
||||
const next = { ...doc };
|
||||
if (documentTypeId) {
|
||||
const entry = documentTypeLookupById.get(documentTypeId);
|
||||
next.document_type = entry || { id: documentTypeId, name: entry?.name || '' };
|
||||
const entry =
|
||||
documentTypeLookupById.get(documentTypeId) ||
|
||||
(documentType?.name ? documentType : null);
|
||||
next.document_type = entry
|
||||
? { id: entry.id ?? documentTypeId, name: entry.name }
|
||||
: { id: documentTypeId, name: '' };
|
||||
} else {
|
||||
next.document_type = null;
|
||||
}
|
||||
@@ -2282,7 +2282,7 @@ const AppLayout = () => {
|
||||
if (!document?.id) {
|
||||
throw new Error('Missing document for document type assignment.');
|
||||
}
|
||||
const trimmed = (name || '').trim();
|
||||
const trimmed = typeof name === 'string' ? name.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Document type name is required.', 'error');
|
||||
return;
|
||||
@@ -2303,7 +2303,7 @@ const AppLayout = () => {
|
||||
}
|
||||
|
||||
const success = await handleDocumentTypeAssign(
|
||||
{ documentId: document.id, documentTypeId: target.id },
|
||||
{ documentId: document.id, documentTypeId: target.id, documentType: target },
|
||||
{ notify: true },
|
||||
);
|
||||
|
||||
@@ -2334,7 +2334,7 @@ const AppLayout = () => {
|
||||
|
||||
const handleBulkDocumentTypeSet = useCallback(
|
||||
async ({ name, input, documentIds }) => {
|
||||
const trimmed = (name || '').trim();
|
||||
const trimmed = typeof name === 'string' ? name.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Document type name is required.', 'error');
|
||||
return;
|
||||
@@ -2658,7 +2658,7 @@ const AppLayout = () => {
|
||||
|
||||
const handleBulkCorrespondentAdd = useCallback(
|
||||
async ({ name, input, documentIds }) => {
|
||||
const trimmed = (name || '').trim();
|
||||
const trimmed = typeof name === 'string' ? name.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Correspondent name is required.', 'error');
|
||||
return;
|
||||
@@ -2887,7 +2887,7 @@ const AppLayout = () => {
|
||||
|
||||
const handleBulkTagAddFromDetail = useCallback(
|
||||
async ({ label, input, documentIds }) => {
|
||||
const trimmed = (label || '').trim();
|
||||
const trimmed = typeof label === 'string' ? label.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Enter a tag label.', 'error');
|
||||
return;
|
||||
@@ -2920,7 +2920,7 @@ const AppLayout = () => {
|
||||
|
||||
const handleBulkTagRemoveFromDetail = useCallback(
|
||||
async ({ label, input, documentIds }) => {
|
||||
const trimmed = (label || '').trim();
|
||||
const trimmed = typeof label === 'string' ? label.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Enter a tag label to remove.', 'error');
|
||||
return;
|
||||
@@ -4190,7 +4190,7 @@ const AppLayout = () => {
|
||||
setStatusMessage('The root folder cannot be renamed.', 'error');
|
||||
return false;
|
||||
}
|
||||
const trimmed = (nextName || '').trim();
|
||||
const trimmed = typeof nextName === 'string' ? nextName.trim() : '';
|
||||
if (!trimmed) {
|
||||
setStatusMessage('Folder name cannot be empty.', 'error');
|
||||
return false;
|
||||
@@ -6157,7 +6157,7 @@ const LoginRoute = () => {
|
||||
|
||||
const handlePasskeyLogin = useCallback(
|
||||
async (rawUsername) => {
|
||||
const username = (rawUsername || '').trim();
|
||||
const username = typeof rawUsername === 'string' ? rawUsername.trim() : '';
|
||||
if (!username) {
|
||||
setStatusMessage('Enter your username before using a passkey.', 'error');
|
||||
return;
|
||||
@@ -6238,7 +6238,7 @@ const LoginRoute = () => {
|
||||
|
||||
const handleSignup = useCallback(
|
||||
async (rawUsername) => {
|
||||
const username = (rawUsername || '').trim();
|
||||
const username = typeof rawUsername === 'string' ? rawUsername.trim() : '';
|
||||
if (!username) {
|
||||
setStatusMessage('Choose a username to create your account.', 'error');
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user