Files
pedwfrontend/components/case/summary/utils/helpers.js
T

77 lines
2.5 KiB
JavaScript

export function capitalizeFirstLetter(val) {
return String(val).charAt(0).toUpperCase() + String(val).slice(1);
}
export function formatDates(dateObj, showTime) {
const d = new Date(dateObj);
const dd = String(d.getDate()).padStart(2, "0");
const mm = String(d.getMonth() + 1).padStart(2, "0");
const yyyy = d.getFullYear();
const hh = String(d.getHours()).padStart(2, "0");
const mins = String(d.getMinutes()).padStart(2, "0");
return showTime && !(hh === "00" && mins === "00")
? `${hh}:${mins}`
: `${dd}/${mm}/${yyyy}`;
}
export function hasValidKey(obj, key) {
return obj?.hasOwnProperty(key) && obj[key] !== null && obj[key] !== "";
}
export function showReps(startDate, endDate) {
const now = new Date();
const start = new Date(startDate);
const end = new Date(endDate);
return now >= start && now <= end;
}
export function showRepsEnded(startDate, endDate) {
const now = new Date();
const start = new Date(startDate);
const end = new Date(endDate);
return now > start && now > end;
}
export function isObjectNotEmpty(obj, key) {
return obj.hasOwnProperty(key) && Object.keys(obj[key]).length > 0;
}
export function hasOwnPropertyAndNotNull(obj, property) {
return obj.hasOwnProperty(property) && obj[property] !== null;
}
export function linkedCasesList(linkedCasesReference) {
//console.log(linkedCasesReference);
linkedCasesReference = linkedCasesReference.value || [];
return (
<>
<ul className="govuk-list govuk-!-font-size-16">
{linkedCasesReference.map((item, key) => {
return (
<li key={key}>
<Link
href={
router.locale == "cy"
? "/canlyniadauchwilio?q=" +
item.title +
"&lk=1"
: "/searchresults?q=" +
item.title +
"&lk=1"
}
className=""
>
{item.title}
</Link>
</li>
);
//console.log(item.incidentid, item.title);
})}
</ul>
</>
);
}