43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import Swal from "sweetalert2";
|
|
|
|
|
|
export const formatCreatedAtWithEnd = (createdAt: string, plan?: string): string => {
|
|
if (!createdAt) return 'N/A';
|
|
|
|
const created = new Date(createdAt);
|
|
const end = new Date(created);
|
|
|
|
// ✅ Check plan type
|
|
if (plan === 'pro_yearly' || plan === 'growth_yearly' || plan === "starter_yearly") {
|
|
end.setFullYear(created.getFullYear() + 1); // add 1 year
|
|
} else {
|
|
end.setMonth(created.getMonth() + 1); // add 1 month
|
|
}
|
|
|
|
const options: Intl.DateTimeFormatOptions = {
|
|
day: '2-digit',
|
|
month: 'short',
|
|
year: 'numeric',
|
|
};
|
|
|
|
const createdFormatted = created.toLocaleDateString('en-GB', options);
|
|
const endFormatted = end.toLocaleDateString('en-GB', options);
|
|
|
|
return `${createdFormatted} - ${endFormatted}`;
|
|
};
|
|
|
|
|
|
export const showMessage = (msg = "", type = "success") => {
|
|
const toast: any = Swal.mixin({
|
|
toast: true,
|
|
position: "top",
|
|
showConfirmButton: false,
|
|
timer: 2500,
|
|
customClass: { container: "toast" },
|
|
});
|
|
toast.fire({
|
|
icon: type,
|
|
title: msg,
|
|
padding: "10px 20px",
|
|
});
|
|
}; |