IO-3166-Global-Notifications-Part-2: checkpoint
This commit is contained in:
@@ -452,7 +452,6 @@ const paymentCollectedCompletedBuilder = (data) => {
|
||||
* Builds notification data for changes to scheduled dates.
|
||||
*/
|
||||
const scheduledDatesChangedBuilder = (data) => {
|
||||
const momentFormat = "MM/DD/YYYY hh:mm a";
|
||||
const changedFields = data.changedFields;
|
||||
|
||||
// Define field configurations
|
||||
@@ -462,16 +461,38 @@ const scheduledDatesChangedBuilder = (data) => {
|
||||
scheduled_delivery: "Scheduled Delivery"
|
||||
};
|
||||
|
||||
// Helper function to format date and time with "at"
|
||||
const formatDateTime = (date) => {
|
||||
if (!date) return "unset";
|
||||
const formatted = moment(date).tz(data.bodyShopTimezone);
|
||||
const datePart = formatted.format("MM/DD/YYYY");
|
||||
const timePart = formatted.format("hh:mm a");
|
||||
return `${datePart} at ${timePart}`;
|
||||
};
|
||||
|
||||
// Build field messages dynamically
|
||||
const fieldMessages = Object.entries(fieldConfigs)
|
||||
.filter(([field]) => changedFields[field]) // Only include changed fields
|
||||
.map(([field, label]) => {
|
||||
const { old, new: newValue } = changedFields[field];
|
||||
const formatDate = (date) => (date ? moment(date).tz(data.bodyShopTimezone).format(momentFormat) : "unset");
|
||||
return `${label} changed from ${formatDate(old)} to ${formatDate(newValue)}`;
|
||||
});
|
||||
|
||||
const body = fieldMessages.length > 0 ? fieldMessages.join(", ") + "." : "Scheduled dates have been updated.";
|
||||
// Case 1: Scheduled date cancelled (from value to null)
|
||||
if (old && !newValue) {
|
||||
return `${label} was cancelled (previously ${formatDateTime(old)}).`;
|
||||
}
|
||||
// Case 2: Scheduled date set (from null to value)
|
||||
else if (!old && newValue) {
|
||||
return `${label} was set to ${formatDateTime(newValue)}.`;
|
||||
}
|
||||
// Case 3: Scheduled date changed (from value to value)
|
||||
else if (old && newValue) {
|
||||
return `${label} changed from ${formatDateTime(old)} to ${formatDateTime(newValue)}.`;
|
||||
}
|
||||
return ""; // Fallback, though this shouldn't happen with the filter
|
||||
})
|
||||
.filter(Boolean); // Remove any empty strings
|
||||
|
||||
const body = fieldMessages.length > 0 ? fieldMessages.join(" ") : "Scheduled dates have been updated.";
|
||||
|
||||
const result = {
|
||||
app: {
|
||||
|
||||
Reference in New Issue
Block a user