From fdfba0f7529ab44870e38442ecf1e0a26577ce30 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Mon, 16 Feb 2026 13:34:38 -0500 Subject: [PATCH] Clean up of the email notifications for Post, Post Comment, and Event create and update. --- ...idaa_comp__post_comment_obj_id_edit.svelte | 70 ++++++++++----- .../bb/ae_idaa_comp__post_obj_id_edit.svelte | 64 +++++++------- .../ae_idaa_comp__event_obj_id_edit.svelte | 85 ++++++++++--------- 3 files changed, 130 insertions(+), 89 deletions(-) diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte index de7c9550..d5ac551d 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_comment_obj_id_edit.svelte @@ -137,23 +137,47 @@ data_kv: post_comment_do, log_lvl: log_lvl }) + .then(function (post_comment_obj_create_result) { + if (!post_comment_obj_create_result) { + console.log('The result was null or false.'); + return false; + } else { + if (log_lvl) { + console.log('post_comment_obj_create_result:', post_comment_obj_create_result); + } + + $idaa_slct.post_comment_id = post_comment_obj_create_result.post_comment_id; + $idaa_slct.post_comment_obj = post_comment_obj_create_result; + + if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) { + send_staff_notification_email(post_comment_obj_create_result); + } + } + + return post_comment_obj_create_result; + }) .catch(function (error: any) { console.log('Something went wrong.'); console.log(error); return false; + }) + .finally(() => { + disable_submit_btn = false; + $idaa_sess.bb.show__inline_edit__post_comment_id = false; }); - if (prom_api__post_comment_obj) { - $idaa_slct.post_comment_id = prom_api__post_comment_obj.post_comment_id; - $idaa_slct.post_comment_obj = prom_api__post_comment_obj; - disable_submit_btn = false; - $idaa_sess.bb.show__inline_edit__post_comment_id = false; + if (prom_api__post_comment_obj) { + // $idaa_slct.post_comment_id = prom_api__post_comment_obj.post_comment_id; + // $idaa_slct.post_comment_obj = prom_api__post_comment_obj; + + // disable_submit_btn = false; + // $idaa_sess.bb.show__inline_edit__post_comment_id = false; // Send notification to staff - if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) { - send_staff_notification_email(); - } + // if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) { + // send_staff_notification_email(); + // } // Send notification to the original poster if ( @@ -197,9 +221,17 @@ if (!post_comment_obj_update_result) { console.log('The result was null or false.'); return false; - } + } else { + if (log_lvl) { + console.log('post_comment_obj_update_result:', post_comment_obj_update_result); + } - $idaa_slct.post_comment_obj = post_comment_obj_update_result; + $idaa_slct.post_comment_obj = post_comment_obj_update_result; + + if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) { + send_staff_notification_email(post_comment_obj_update_result); + } + } return post_comment_obj_update_result; }) @@ -215,9 +247,9 @@ $idaa_sess.bb.show__inline_edit__post_comment_id = false; // if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) { - if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) { - send_staff_notification_email(); - } + // if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) { + // send_staff_notification_email(); + // } // For now we are not going to send a notification to the poster when a post comment has been updated. // if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) { @@ -263,7 +295,7 @@ return prom_api__post_comment_obj; } - function send_staff_notification_email() { + function send_staff_notification_email(post_comment_do: key_val) { log_lvl = 1; if (log_lvl) { console.log( @@ -272,7 +304,7 @@ } if (log_lvl > 1) { console.log(`Selected Post Object:`, $idaa_slct.post_obj); - console.log(`Selected Post Comment Object:`, $idaa_slct.post_comment_obj); + console.log(`Selected Post Comment Object:`, post_comment_do); // console.log($lq__post_obj); // console.log($lq__post_obj?.title); @@ -290,9 +322,9 @@
-Commenter's Novi ID: ${$idaa_slct.post_comment_obj.external_person_id ?? '-- not set --'}
-Commenter's Name: ${$idaa_slct.post_comment_obj.full_name ?? '-- not set --'}
-Commenter's Email: ${$idaa_slct.post_comment_obj.email ?? '-- not set --'} +Commenter's Novi ID: ${post_comment_do.external_person_id ?? '-- not set --'}
+Commenter's Name: ${post_comment_do.full_name ?? '-- not set --'}
+Commenter's Email: ${post_comment_do.email ?? '-- not set --'}
@@ -313,7 +345,7 @@ Copy and paste link: ${ api_cfg: $ae_api, from_email: $ae_loc.site_cfg_json?.noreply_email ?? 'noreply+idaabb@oneskyit.com', from_name: $ae_loc.site_cfg_json?.noreply_name ?? 'IDAA BB NoReply', - to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email, + to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbcomment@oneskyit.com', // 'scott+idaabb@oneskyit.com', // post_comment_do.email, // to_email: 'scott+idaabbstaff@oneskyit.com', to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin', subject: subject, diff --git a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte index 72d01041..36791461 100644 --- a/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/bb/ae_idaa_comp__post_obj_id_edit.svelte @@ -5,7 +5,7 @@ obj_changed: boolean; } - let { log_lvl = $bindable(0), lq__post_obj, obj_changed = $bindable(false) }: Props = $props(); + let { log_lvl = $bindable(1), lq__post_obj, obj_changed = $bindable(false) }: Props = $props(); // *** Import Svelte specific // import { onDestroy, onMount } from 'svelte'; @@ -179,13 +179,18 @@ if (!post_obj_create_result) { console.log('The result was null or false.'); return false; - } + } else { + if (log_lvl) { + console.log('post_obj_create_result:', post_obj_create_result); + } - if (log_lvl) { - console.log('post_obj_create_result:', post_obj_create_result); + $idaa_slct.post_id = post_obj_create_result.post_id; + $idaa_slct.post_obj = post_obj_create_result; + + if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) { + send_staff_notification_email(prom_api__post_obj); + } } - $idaa_slct.post_id = post_obj_create_result.post_id; - $idaa_slct.post_obj = post_obj_create_result; return post_obj_create_result; }) @@ -197,11 +202,6 @@ .finally(() => { disable_submit_btn = false; $idaa_sess.bb.edit__post_obj = false; - - // if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) { - if ($ae_loc.site_cfg_json?.bb_send_staff_new_email) { - send_staff_notification_email(); - } }); return prom_api__post_obj; @@ -217,9 +217,17 @@ if (!post_obj_update_result) { console.log('The result was null or false.'); return false; - } + } else { + if (log_lvl) { + console.log('post_obj_update_result:', post_obj_update_result); + } - $idaa_slct.post_obj = post_obj_update_result; + $idaa_slct.post_obj = post_obj_update_result; + + if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) { + send_staff_notification_email(post_obj_update_result); + } + } return post_obj_update_result; }) @@ -229,16 +237,10 @@ return false; }) .finally(() => { - // We need to do this since the post has changed and the idaa_slct object does automatically update (yet...???). - // $idaa_slct.post_obj = $lq__post_obj; disable_submit_btn = false; $idaa_sess.bb.edit__post_obj = false; - - // if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) { - if ($ae_loc.site_cfg_json?.bb_send_staff_update_email) { - send_staff_notification_email(); - } }); + console.log(`prom_api__post_obj = `, prom_api__post_obj); return prom_api__post_obj; } @@ -324,33 +326,35 @@ }); } - function send_staff_notification_email() { + // Updated 2026-02-16 + // The post_do (Post Data Out) should be the new form data + function send_staff_notification_email(post_do: key_val) { if (log_lvl) { - console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`); + console.log(`*** send_staff_notification_email() *** Post ID: ${post_do.post_id}`); } let link_base_url = $ae_loc.site_cfg_json.novi_bb_base_url ?? `${$ae_loc.url_origin}/idaa/bb`; - let subject = `IDAA BB Post: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`; + let subject = `IDAA BB Post: ${post_do.title} (ID: ${post_do.post_id})`; let body_html = ` -
${$idaa_slct.post_obj.full_name ?? '-- not set --'}, -

A BB post has been created or updated named "${$idaa_slct.post_obj.title}".

+
${post_do.full_name ?? '-- not set --'}, +

A BB post has been created or updated named "${post_do.title}".

-Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id ?? '-- not set --'}
-Poster's Name: ${$idaa_slct.post_obj.full_name ?? '-- not set --'}
-Poster's Email: ${$idaa_slct.post_obj.email ?? '-- not set --'} +Poster's Novi ID: ${post_do.external_person_id ?? '-- not set --'}
+Poster's Name: ${post_do.full_name ?? '-- not set --'}
+Poster's Email: ${post_do.email ?? '-- not set --'}

-IDAA BB Post ID: ${$idaa_slct.post_id}
+IDAA BB Post ID: ${post_do.post_id}

Use this link to view the post.
-Copy and paste link:
${link_base_url}?post_id=${$idaa_slct.post_id}

+Copy and paste link: ${link_base_url}?post_id=${post_do.post_id}

`; api.send_email({ diff --git a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte index ba477d87..15487f70 100644 --- a/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte +++ b/src/routes/idaa/(idaa)/recovery_meetings/ae_idaa_comp__event_obj_id_edit.svelte @@ -661,17 +661,22 @@ if (!event_obj_create_result) { console.log('The result was null or false.'); return false; - } + } else { - if (log_lvl) { - console.log( - 'event_obj_create_result:', - event_obj_create_result - ); + if (log_lvl) { + console.log( + 'event_obj_create_result:', + event_obj_create_result + ); + } + $idaa_slct.event_id = + event_obj_create_result.event_id; + $idaa_slct.event_obj = event_obj_create_result; + + if ($ae_loc.site_cfg_json?.recovery_mtg_send_staff_new_email) { + send_staff_notification_email(event_obj_create_result); + } } - $idaa_slct.event_id = - event_obj_create_result.event_id; - $idaa_slct.event_obj = event_obj_create_result; return event_obj_create_result; }) @@ -685,23 +690,14 @@ $idaa_sess.recovery_meetings.show__modal_edit = false; $idaa_sess.recovery_meetings.show__modal_view = true; - log_lvl = 1; - if (log_lvl) { - console.log( - `Check if we should send staff update email...`, $ae_loc.site_cfg_json?.recovery_mtg_send_staff_new_email - ); - } - - if ( - // !$ae_loc.administrator_access && - $ae_loc.site_cfg_json?.recovery_mtg_send_staff_new_email - ) { - send_staff_notification_email(); - } + // log_lvl = 1; + // if (log_lvl) { + // console.log( + // `Check if we should send staff update email...`, $ae_loc.site_cfg_json?.recovery_mtg_send_staff_new_email + // ); + // } }); - // log_lvl = 0; - return prom_api__event_obj; } else { prom_api__event_obj = events_func @@ -715,9 +711,17 @@ if (!event_obj_update_result) { console.log('The result was null or false.'); return false; - } + } else { + if (log_lvl) { + console.log('event_obj_update_result:', event_obj_update_result); + } - $idaa_slct.event_obj = event_obj_update_result; + $idaa_slct.event_obj = event_obj_update_result; + + if ($ae_loc.site_cfg_json?.recovery_mtg_send_staff_update_email) { + send_staff_notification_email(event_obj_update_result); + } + } return event_obj_update_result; }) @@ -731,12 +735,12 @@ $idaa_sess.recovery_meetings.show__modal_edit = false; $idaa_sess.recovery_meetings.show__modal_view = true; - log_lvl = 1; - if (log_lvl) { - console.log( - `Check if we should send staff update email...`, $ae_loc.site_cfg_json?.recovery_mtg_send_staff_update_email - ); - } + // log_lvl = 1; + // if (log_lvl) { + // console.log( + // `Check if we should send staff update email...`, $ae_loc.site_cfg_json?.recovery_mtg_send_staff_update_email + // ); + // } // if ( // // !$ae_loc.administrator_access && @@ -746,7 +750,7 @@ // send_staff_notification_email(); // } - send_staff_notification_email(); + // send_staff_notification_email(event_do); }); // log_lvl = 0; @@ -795,11 +799,12 @@ return prom_api__event_obj; } - // Updated 2025-02-07 - function send_staff_notification_email() { + // Updated 2026-02-16 + // The event_do (Event (Recovery Meeting) Data Out) should be the new form data + function send_staff_notification_email(event_do: key_val) { if (log_lvl) { console.log( - `*** send_staff_notification_email() *** To: ${$ae_loc.site_cfg_json?.admin_email} From: ${$ae_loc.site_cfg_json?.noreply_email} Subject: IDAA Recovery Meeting: ${$idaa_slct.event_obj.name} (ID: ${$idaa_slct.event_id})` + `*** send_staff_notification_email() *** To: ${$ae_loc.site_cfg_json?.admin_email} From: ${$ae_loc.site_cfg_json?.noreply_email} Subject: IDAA Recovery Meeting: ${event_do.name} (ID: ${event_do.event_id})` ); } @@ -807,19 +812,19 @@ $ae_loc.site_cfg_json.novi_meetings_base_url ?? `${$ae_loc.url_origin}/idaa/recovery_meetings`; - let subject = `IDAA Recovery Meeting: ${$idaa_slct.event_obj.name} (ID: ${$idaa_slct.event_id})`; + let subject = `IDAA Recovery Meeting: ${event_do.name} (ID: ${event_do.event_id})`; let body_html = `
-

A recovery meeting has been created or updated named "${$idaa_slct.event_obj.name}".

+

A recovery meeting has been created or updated named "${event_do.name}".


- IDAA Recovery Meeting ID: ${$idaa_slct.event_id}
+ IDAA Recovery Meeting ID: ${event_do.event_id}

Use this link to view the meeting.
- Copy and paste link: ${link_base_url}?event_id=${$idaa_slct.event_id}

+ Copy and paste link: ${link_base_url}?event_id=${event_do.event_id}

`; api.send_email({