diff --git a/app/components/DocumentListItem.tsx b/app/components/DocumentListItem.tsx
index ba3243f76..5244a46a3 100644
--- a/app/components/DocumentListItem.tsx
+++ b/app/components/DocumentListItem.tsx
@@ -97,7 +97,7 @@ function DocumentListItem(
highlight={highlight}
dir={document.dir}
/>
- {document.isBadgedNew && document.createdBy.id !== user.id && (
+ {document.isBadgedNew && document.createdBy?.id !== user.id && (
{t("New")}
)}
{canStar && (
diff --git a/app/components/Sharing/OtherAccess.tsx b/app/components/Sharing/OtherAccess.tsx
index 46a820575..4a8151a22 100644
--- a/app/components/Sharing/OtherAccess.tsx
+++ b/app/components/Sharing/OtherAccess.tsx
@@ -81,7 +81,7 @@ export const OtherAccess = observer(({ document, children }: Props) => {
<>
}
- title={document.createdBy.name}
+ title={document.createdBy?.name}
actions={
{t("Can edit")}
diff --git a/app/models/Document.ts b/app/models/Document.ts
index 595c864f8..d71e88039 100644
--- a/app/models/Document.ts
+++ b/app/models/Document.ts
@@ -126,10 +126,10 @@ export default class Document extends ParanoidModel {
collaboratorIds: string[];
@observable
- createdBy: User;
+ createdBy: User | undefined;
@observable
- updatedBy: User;
+ updatedBy: User | undefined;
@observable
publishedAt: string | undefined;
diff --git a/app/scenes/Document/components/Document.tsx b/app/scenes/Document/components/Document.tsx
index 97ae33e9b..094c9dafb 100644
--- a/app/scenes/Document/components/Document.tsx
+++ b/app/scenes/Document/components/Document.tsx
@@ -123,7 +123,7 @@ class DocumentScene extends React.Component {
componentWillUnmount() {
if (
this.isEmpty &&
- this.props.document.createdBy.id === this.props.auth.user?.id &&
+ this.props.document.createdBy?.id === this.props.auth.user?.id &&
this.props.document.isDraft &&
this.props.document.isActive &&
this.props.document.hasEmptyTitle &&
diff --git a/app/scenes/Document/components/Insights.tsx b/app/scenes/Document/components/Insights.tsx
index 9f8de8307..cc499bb74 100644
--- a/app/scenes/Document/components/Insights.tsx
+++ b/app/scenes/Document/components/Insights.tsx
@@ -115,9 +115,9 @@ function Insights() {
title={model.name}
image={}
subtitle={
- model.id === document.createdBy.id
+ model.id === document.createdBy?.id
? t("Creator")
- : model.id === document.updatedBy.id
+ : model.id === document.updatedBy?.id
? t("Last edited")
: t("Previously edited")
}
diff --git a/app/scenes/Document/components/Notices.tsx b/app/scenes/Document/components/Notices.tsx
index 039ee1d18..6bb79c9ed 100644
--- a/app/scenes/Document/components/Notices.tsx
+++ b/app/scenes/Document/components/Notices.tsx
@@ -65,7 +65,7 @@ export default function Notices({ document, readOnly }: Props) {
{document.archivedAt && !document.deletedAt && (
}>
{t("Archived by {{userName}}", {
- userName: document.updatedBy.name,
+ userName: document.updatedBy?.name ?? t("Unknown"),
})}
@@ -77,7 +77,7 @@ export default function Notices({ document, readOnly }: Props) {
description={permanentlyDeletedDescription()}
>
{t("Deleted by {{userName}}", {
- userName: document.updatedBy.name,
+ userName: document.updatedBy?.name ?? t("Unknown"),
})}
diff --git a/app/stores/DocumentsStore.ts b/app/stores/DocumentsStore.ts
index 5c26509e0..0391b824b 100644
--- a/app/stores/DocumentsStore.ts
+++ b/app/stores/DocumentsStore.ts
@@ -109,7 +109,7 @@ export default class DocumentsStore extends Store {
createdByUser(userId: string): Document[] {
return orderBy(
- filter(this.all, (d) => d.createdBy.id === userId),
+ filter(this.all, (d) => d.createdBy?.id === userId),
"updatedAt",
"desc"
);