mirror of
https://github.com/coder/coder.git
synced 2026-10-16 06:37:58 +08:00
29 lines
876 B
TypeScript
29 lines
876 B
TypeScript
import type { Workspace } from "api/typesGenerated";
|
|
|
|
// This const dictates how far out we alert the user that a workspace
|
|
// has an impending deletion (due to template.InactivityTTL being set)
|
|
const IMPENDING_DELETION_DISPLAY_THRESHOLD = 14; // 14 days
|
|
|
|
/**
|
|
* Returns a boolean indicating if an impending deletion indicator should be
|
|
* displayed in the UI. Impending deletions are configured by setting the
|
|
* Template.InactivityTTL
|
|
* @param {TypesGen.Workspace} workspace
|
|
* @returns {boolean}
|
|
*/
|
|
export const displayDormantDeletion = (
|
|
workspace: Workspace,
|
|
allowAdvancedScheduling: boolean,
|
|
) => {
|
|
const today = new Date();
|
|
if (!workspace.deleting_at || !allowAdvancedScheduling) {
|
|
return false;
|
|
}
|
|
return (
|
|
new Date(workspace.deleting_at) <=
|
|
new Date(
|
|
today.setDate(today.getDate() + IMPENDING_DELETION_DISPLAY_THRESHOLD),
|
|
)
|
|
);
|
|
};
|