All files / utils announcementUtils.js

100% Statements 12/12
100% Branches 8/8
100% Functions 4/4
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42    7x       24x       15x   9x         30x   27x 27x 24x     6x       2x 2x       2x                
import { toast } from "react-toastify";
 
export const ANNOUNCEMENT_TEXT_MAX_LENGTH = 255;
 
// datetime-local inputs use "YYYY-MM-DDTHH:mm"; Spring ISO.DATE_TIME expects seconds.
export function datetimeLocalToIsoDateTime(value) {
  if (
    typeof value === "string" &&
    /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}$/.test(value)
  ) {
    return `${value}:00`;
  }
  return value;
}
 
// Convert ISO datetime to datetime-local format (YYYY-MM-DDTHH:mm)
export function isoDateTimeToDatetimeLocal(value) {
  if (typeof value === "string") {
    // Handle ISO format: "YYYY-MM-DDTHH:mm:ss" or "YYYY-MM-DDTHH:mm:ss.SSS"
    const match = value.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})/);
    if (match) {
      return match[1];
    }
  }
  return value;
}
 
export function onDeleteSuccess(message) {
  console.log(message);
  toast(message);
}
 
export function cellToAxiosParamsDelete(cell) {
  return {
    url: "/api/announcements/delete",
    method: "DELETE",
    params: {
      id: cell.row.values.id,
    },
  };
}