Last active
August 21, 2024 13:34
-
-
Save zzzarius/e11c36ca5825b77acf14dd3913960ce8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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