2023-01-26 13:44:04 +01:00
|
|
|
import moment from "moment";
|
|
|
|
|
|
|
|
|
|
export const getExpirationPreview = (
|
2023-07-20 15:32:07 +02:00
|
|
|
messages: {
|
|
|
|
|
neverExpires: string;
|
|
|
|
|
expiresOn: string;
|
|
|
|
|
},
|
2023-01-26 13:44:04 +01:00
|
|
|
form: {
|
|
|
|
|
values: {
|
|
|
|
|
never_expires?: boolean;
|
|
|
|
|
expiration_num: number;
|
|
|
|
|
expiration_unit: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
) => {
|
|
|
|
|
const value = form.values.never_expires
|
|
|
|
|
? "never"
|
|
|
|
|
: form.values.expiration_num + form.values.expiration_unit;
|
2023-07-20 15:32:07 +02:00
|
|
|
if (value === "never") return messages.neverExpires;
|
2023-01-26 13:44:04 +01:00
|
|
|
|
|
|
|
|
const expirationDate = moment()
|
|
|
|
|
.add(
|
|
|
|
|
value.split("-")[0],
|
|
|
|
|
value.split("-")[1] as moment.unitOfTime.DurationConstructor
|
|
|
|
|
)
|
|
|
|
|
.toDate();
|
|
|
|
|
|
2023-07-20 15:32:07 +02:00
|
|
|
return messages.expiresOn.replace(
|
|
|
|
|
"{expiration}",
|
|
|
|
|
moment(expirationDate).format("LLL")
|
|
|
|
|
);
|
2023-01-26 13:44:04 +01:00
|
|
|
};
|