Skip to content

Open-source status page, incident response and uptime monitoring

1.1 KB
Raw Blame
import type { RouterOutputs } from "@openstatus/api";
import { Settings, Delete } from "@openstatus/icons";

export const actions = [
  {
    id: "edit",
    label: "Settings",
    icon: Settings,
    variant: "default" as const,
  },
  {
    id: "delete",
    label: "Delete",
    icon: Delete,
    variant: "destructive" as const,
  },
] as const;

export type MaintenanceAction = (typeof actions)[number];

export const getActions = (
  props: Partial<Record<MaintenanceAction["id"], () => Promise<void> | void>>,
): (MaintenanceAction & { onClick?: () => Promise<void> | void })[] => {
  return actions.map((action) => ({
    ...action,
    onClick: props[action.id as keyof typeof props],
  }));
};

type Maintenance = NonNullable<RouterOutputs["maintenance"]["get"]>;

/** `maintenance.update` requires every field: start from the current row. */
export function toUpdateInput(maintenance: Maintenance) {
  return {
    id: maintenance.id,
    title: maintenance.title,
    startDate: maintenance.from,
    endDate: maintenance.to,
    pageComponents: maintenance.pageComponentIds,
  };
}