fix: Account for createdBy, updatedBy being undefined. closes #6578

This commit is contained in:
Tom Moor
2024-02-26 21:55:06 -05:00
parent 7e4b60df4d
commit edae1c6ee1
7 changed files with 10 additions and 10 deletions

View File

@@ -97,7 +97,7 @@ function DocumentListItem(
highlight={highlight} highlight={highlight}
dir={document.dir} dir={document.dir}
/> />
{document.isBadgedNew && document.createdBy.id !== user.id && ( {document.isBadgedNew && document.createdBy?.id !== user.id && (
<Badge yellow>{t("New")}</Badge> <Badge yellow>{t("New")}</Badge>
)} )}
{canStar && ( {canStar && (

View File

@@ -81,7 +81,7 @@ export const OtherAccess = observer(({ document, children }: Props) => {
<> <>
<StyledListItem <StyledListItem
image={<Avatar model={document.createdBy} showBorder={false} />} image={<Avatar model={document.createdBy} showBorder={false} />}
title={document.createdBy.name} title={document.createdBy?.name}
actions={ actions={
<AccessTooltip content={t("Created the document")}> <AccessTooltip content={t("Created the document")}>
{t("Can edit")} {t("Can edit")}

View File

@@ -126,10 +126,10 @@ export default class Document extends ParanoidModel {
collaboratorIds: string[]; collaboratorIds: string[];
@observable @observable
createdBy: User; createdBy: User | undefined;
@observable @observable
updatedBy: User; updatedBy: User | undefined;
@observable @observable
publishedAt: string | undefined; publishedAt: string | undefined;

View File

@@ -123,7 +123,7 @@ class DocumentScene extends React.Component<Props> {
componentWillUnmount() { componentWillUnmount() {
if ( if (
this.isEmpty && 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.isDraft &&
this.props.document.isActive && this.props.document.isActive &&
this.props.document.hasEmptyTitle && this.props.document.hasEmptyTitle &&

View File

@@ -115,9 +115,9 @@ function Insights() {
title={model.name} title={model.name}
image={<Avatar model={model} size={32} />} image={<Avatar model={model} size={32} />}
subtitle={ subtitle={
model.id === document.createdBy.id model.id === document.createdBy?.id
? t("Creator") ? t("Creator")
: model.id === document.updatedBy.id : model.id === document.updatedBy?.id
? t("Last edited") ? t("Last edited")
: t("Previously edited") : t("Previously edited")
} }

View File

@@ -65,7 +65,7 @@ export default function Notices({ document, readOnly }: Props) {
{document.archivedAt && !document.deletedAt && ( {document.archivedAt && !document.deletedAt && (
<Notice icon={<ArchiveIcon />}> <Notice icon={<ArchiveIcon />}>
{t("Archived by {{userName}}", { {t("Archived by {{userName}}", {
userName: document.updatedBy.name, userName: document.updatedBy?.name ?? t("Unknown"),
})} })}
&nbsp; &nbsp;
<Time dateTime={document.updatedAt} addSuffix /> <Time dateTime={document.updatedAt} addSuffix />
@@ -77,7 +77,7 @@ export default function Notices({ document, readOnly }: Props) {
description={permanentlyDeletedDescription()} description={permanentlyDeletedDescription()}
> >
{t("Deleted by {{userName}}", { {t("Deleted by {{userName}}", {
userName: document.updatedBy.name, userName: document.updatedBy?.name ?? t("Unknown"),
})} })}
&nbsp; &nbsp;
<Time dateTime={document.deletedAt} addSuffix /> <Time dateTime={document.deletedAt} addSuffix />

View File

@@ -109,7 +109,7 @@ export default class DocumentsStore extends Store<Document> {
createdByUser(userId: string): Document[] { createdByUser(userId: string): Document[] {
return orderBy( return orderBy(
filter(this.all, (d) => d.createdBy.id === userId), filter(this.all, (d) => d.createdBy?.id === userId),
"updatedAt", "updatedAt",
"desc" "desc"
); );