From edae1c6ee14a6d9b43ee2c1867ff9d4cd98cbae8 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 26 Feb 2024 21:55:06 -0500 Subject: [PATCH] fix: Account for createdBy, updatedBy being undefined. closes #6578 --- app/components/DocumentListItem.tsx | 2 +- app/components/Sharing/OtherAccess.tsx | 2 +- app/models/Document.ts | 4 ++-- app/scenes/Document/components/Document.tsx | 2 +- app/scenes/Document/components/Insights.tsx | 4 ++-- app/scenes/Document/components/Notices.tsx | 4 ++-- app/stores/DocumentsStore.ts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) 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"), })}