Skip to content

Instantly share code, notes, and snippets.

@zzzarius
Last active August 21, 2024 13:34
Show Gist options
  • Save zzzarius/e11c36ca5825b77acf14dd3913960ce8 to your computer and use it in GitHub Desktop.
Save zzzarius/e11c36ca5825b77acf14dd3913960ce8 to your computer and use it in GitHub Desktop.
import { EntrySys } from "@contentful/app-sdk";
import { EntryMetaSysProps } from "contentful-management";
export const EntryStatus = {
ARCHIVED: "archived",
PUBLISHED: "published",
CHANGED: "changed",
DRAFT: "draft",
} as const;
export type EntryStatusKeys = keyof typeof EntryStatus;
export type EntryStatusValues = (typeof EntryStatus)[EntryStatusKeys];
export const getEntryStatus = (
entrySys: EntryMetaSysProps | EntrySys
): EntryStatusValues => {
if (entrySys.archivedVersion) {
return EntryStatus.ARCHIVED;
} else if (
!!entrySys.publishedVersion &&
entrySys.version == entrySys.publishedVersion + 1
) {
return EntryStatus.PUBLISHED;
} else if (
!!entrySys.publishedVersion &&
entrySys.version >= entrySys.publishedVersion + 2
) {
return EntryStatus.CHANGED;
}
return EntryStatus.DRAFT;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment