Work on post and comment email notifications.

This commit is contained in:
Scott Idem
2024-11-22 13:13:44 -05:00
parent 6a79cb165d
commit 1868adad99
5 changed files with 151 additions and 31 deletions

View File

@@ -703,14 +703,14 @@ export function db_save_ae_obj_li__post(
// post_comment_kv: obj.post_comment_kv,
// post_comment_li: obj.post_comment_li,
});
// console.log(`Put obj with ID: ${obj.post_id_random} or ${id_random}`);
if (log_lvl) {
console.log(`Put obj with ID: ${obj.post_id_random} or ${id_random}`);
}
} catch (error) {
let status = `Failed to put ${obj.post_id_random}: ${error}`;
console.log(status);
return false;
}
// const id_random = await db_posts.post.put(obj);
// console.log(`Put obj with ID: ${obj.post_id_random}`);
});
return true;

View File

@@ -41,7 +41,8 @@ export async function load_ae_obj_id__post_comment(
// This is expecting a list
db_save_ae_obj_li__post_comment({
obj_type: 'post_comment',
obj_li: [post_comment_obj_get_result]
obj_li: [post_comment_obj_get_result],
log_lvl: log_lvl
});
}
@@ -121,7 +122,9 @@ export async function load_ae_obj_li__post_comment(
if (post_comment_obj_li_get_result) {
if (try_cache) {
db_save_ae_obj_li__post_comment({
obj_type: 'post_comment', obj_li: post_comment_obj_li_get_result
obj_type: 'post_comment',
obj_li: post_comment_obj_li_get_result,
log_lvl: log_lvl
});
}
return post_comment_obj_li_get_result;
@@ -181,7 +184,8 @@ export async function create_ae_obj__post_comment(
db_save_ae_obj_li__post_comment(
{
obj_type: 'post_comment',
obj_li: [post_comment_obj_create_result]
obj_li: [post_comment_obj_create_result],
log_lvl: log_lvl
});
}
return post_comment_obj_create_result;
@@ -288,7 +292,8 @@ export async function update_ae_obj__post_comment(
if (post_comment_obj_update_result) {
if (try_cache) {
db_save_ae_obj_li__post_comment({
obj_type: 'post_comment', obj_li: [post_comment_obj_update_result]
obj_type: 'post_comment', obj_li: [post_comment_obj_update_result],
log_lvl: log_lvl
});
}
return post_comment_obj_update_result;
@@ -315,7 +320,7 @@ export function db_save_ae_obj_li__post_comment(
{
obj_type,
obj_li,
log_lvl=0
log_lvl = 0
}: {
obj_type: string,
obj_li: any,
@@ -365,14 +370,14 @@ export function db_save_ae_obj_li__post_comment(
// From SQL view
});
// console.log(`Put obj with ID: ${obj.post_comment_id_random} or ${id_random}`);
if (log_lvl) {
console.log(`Put obj with ID: ${obj.post_comment_id_random} or ${id_random}`);
}
} catch (error) {
let status = `Failed to put ${obj.post_comment_id_random}: ${error}`;
console.log(status);
return false;
}
// const id_random = await db_posts.comment.put(obj);
// console.log(`Put obj with ID: ${obj.post_comment_id_random}`);
});
return true;

View File

@@ -6,7 +6,7 @@ import { fade } from 'svelte/transition';
import type { key_val } from '$lib/ae_stores';
import { ae_util } from '$lib/ae_utils/ae_utils';
// import { core_func } from '$lib/ae_core/ae_core_functions';
// import { api } from '$lib/api';
import { api } from '$lib/api';
import { ae_snip, ae_loc, ae_sess, ae_api, ae_trig, slct, slct_trigger } from '$lib/ae_stores';
import { idaa_loc, idaa_sess, idaa_slct } from '$lib/ae_idaa_stores';
import { posts_func } from '$lib/ae_posts/ae_posts_functions';
@@ -21,8 +21,7 @@ let disable_submit_btn = false;
async function handle_submit_form(event: any) {
if (log_lvl > 1) {
console.log('*** handle_submit_form() ***');
console.log(event.target);
console.log('*** handle_submit_form() ***', event.target);
}
disable_submit_btn = true;
@@ -40,7 +39,7 @@ async function handle_submit_form(event: any) {
let post_comment_do: key_val = {};
if (!$idaa_slct.post_comment_id) {
post_comment_do['post_id_random'] = $ae_loc.post_id;
post_comment_do['post_id_random'] = $idaa_slct.post_id;
post_comment_do['enable'] = true;
}
@@ -60,6 +59,7 @@ async function handle_submit_form(event: any) {
post_comment_do['external_person_id'] = post_comment_di.external_person_id;
post_comment_do['full_name'] = post_comment_di.full_name;
post_comment_do['email'] = post_comment_di.email;
post_comment_do['notify'] = post_comment_do.notify;
post_comment_do['hide'] = post_comment_di.hide;
post_comment_do['priority'] = post_comment_di.priority;
@@ -97,7 +97,7 @@ async function handle_submit_form(event: any) {
api_cfg: $ae_api,
post_id: $idaa_slct.post_id,
data_kv: post_comment_do,
log_lvl: log_lvl
log_lvl: 2
})
.then(function (post_comment_obj_create_result) {
if (!post_comment_obj_create_result) {
@@ -106,6 +106,7 @@ async function handle_submit_form(event: any) {
}
$idaa_slct.post_comment_id = post_comment_obj_create_result.obj_id_random;
$idaa_slct.post_comment_obj = post_comment_obj_create_result;
return post_comment_obj_create_result;
})
@@ -114,10 +115,17 @@ async function handle_submit_form(event: any) {
console.log(error);
return false;
})
.finally(() => {
$idaa_slct.post_comment_obj = $lq__post_comment_obj;
.finally(async () => {
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email();
}
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
send_poster_notification_email();
}
});
return prom_api__post_comment_obj;
@@ -126,7 +134,7 @@ async function handle_submit_form(event: any) {
api_cfg: $ae_api,
post_comment_id: $idaa_slct.post_comment_id,
data_kv: post_comment_do,
log_lvl: log_lvl
log_lvl: 1
})
.then(function (post_comment_obj_update_result) {
if (!post_comment_obj_update_result) {
@@ -134,6 +142,8 @@ async function handle_submit_form(event: any) {
return false;
}
$idaa_slct.post_comment_obj = post_comment_obj_update_result;
return post_comment_obj_update_result;
})
.catch(function (error) {
@@ -146,6 +156,14 @@ async function handle_submit_form(event: any) {
$idaa_slct.post_comment_obj = $lq__post_comment_obj;
disable_submit_btn = false;
$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) {
send_staff_notification_email();
}
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_poster_email && $idaa_slct.post_obj.notify) {
send_poster_notification_email();
}
});
return prom_api__post_comment_obj;
@@ -188,6 +206,81 @@ async function handle_delete_post_comment_obj(
return prom_api__post_comment_obj;
}
function send_staff_notification_email() {
if (log_lvl) {
console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name},
<p>A BB post comment has been created or updated.</p>
</div>
<div>
Commenter's Novi ID: ${$idaa_slct.post_comment_obj.external_person_id}<br>
Commenter's Name: ${$idaa_slct.post_comment_obj.full_name}<br>
Commenter's Email: ${$idaa_slct.post_comment_obj.email}
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}">${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
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_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject,
body_html: body_html,
});
}
function send_poster_notification_email() {
if (log_lvl) {
console.log(`*** send_poster_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let subject = `IDAA BB Post Comment on: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`;
let body_html = `
<div>${$idaa_slct.post_obj.full_name},
<p>Your BB post has been commented on.</p>
</div>
<div>
Poster's Novi ID: ${$idaa_slct.post_obj.external_person_id}<br>
Poster's Name: ${$idaa_slct.post_obj.full_name}<br>
Poster's Email: ${$idaa_slct.post_obj.email}
</div>
<br>
<div>
IDAA BB Post ID: ${$idaa_slct.post_id}<br>
<p>Use this link to view the post.<br>
Copy and paste link: <a href="${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}">${$ae_loc.url_origin}/idaa/bb?post_id=${$idaa_slct.post_id}</a></p>
</div>`;
api.send_email({
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+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_comment_obj.email,
to_name: $idaa_slct.post_obj.full_name ?? 'IDAA BB Poster',
subject: subject,
body_html: body_html,
});
}
</script>
@@ -216,7 +309,7 @@ async function handle_delete_post_comment_obj(
$idaa_sess.bb.show__inline_edit__post_comment_id = false;
}}
class="btn btn-sm variant-ghost-warning hover:variant-filled-warning transition"
title="Cancel editing of post comment for {$idaa_slct.post_comment_obj.full_name} (ID: {$idaa_slct.post_comment_obj.post_id}"
title="Cancel editing of post comment for {$idaa_slct.post_comment_obj?.full_name} (ID: {$idaa_slct.post_comment_obj?.post_id}"
>
<span class="fas fa-edit m-1"></span> Cancel Edit
</button>
@@ -329,7 +422,9 @@ async function handle_delete_post_comment_obj(
readonly={!$ae_loc.trusted_access}
class="input w-96"
>
<span class="ae_highlight">Secondary link using the Novi email address</span>
<span class="text-xs text-gray-600 dark:text-gray-400 italic">
Secondary link using the Novi email address
</span>
</label>
{/if}

View File

@@ -29,9 +29,8 @@ let disable_submit_btn = false;
async function handle_submit_form(event: any) {
console.log('*** handle_submit_form() ***');
if (log_lvl > 1) {
console.log(event.target);
console.log('*** handle_submit_form() ***', event.target);
}
disable_submit_btn = true;
@@ -125,7 +124,7 @@ async function handle_submit_form(event: any) {
}
$idaa_slct.post_id = post_obj_create_result.post_id_random;
// $idaa_slct.post_obj = post_obj_create_result;
$idaa_slct.post_obj = post_obj_create_result;
return post_obj_create_result;
})
@@ -137,7 +136,8 @@ async function handle_submit_form(event: any) {
.finally(() => {
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_obj = false;
if (!$ae_loc.trusted_access) {
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_new_email) {
send_staff_notification_email();
}
});
@@ -156,6 +156,8 @@ async function handle_submit_form(event: any) {
return false;
}
$idaa_slct.post_obj = post_obj_update_result;
return post_obj_update_result;
})
.catch(function (error) {
@@ -168,7 +170,8 @@ async function handle_submit_form(event: any) {
$idaa_slct.post_obj = $lq__post_obj;
disable_submit_btn = false;
$idaa_sess.bb.show__inline_edit__post_obj = false;
if (!$ae_loc.trusted_access) {
if (!$ae_loc.administrator_access && $ae_loc.site_cfg_json?.bb_send_staff_update_email) {
send_staff_notification_email();
}
});
@@ -257,6 +260,10 @@ async function handle_hosted_files_uploaded(hosted_file_id_li: string[], hosted_
function send_staff_notification_email() {
if (log_lvl) {
console.log(`*** send_staff_notification_email() *** Post ID: ${$idaa_slct.post_id}`);
}
let subject = `IDAA BB Post: ${$idaa_slct.post_obj.title} (ID: ${$idaa_slct.post_id})`;
let body_html = `
@@ -282,7 +289,7 @@ function send_staff_notification_email() {
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+bb@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_obj.email,
to_email: $ae_loc.site_cfg_json?.admin_email ?? 'admin+bbpost@oneskyit.com', // 'scott+idaabb@oneskyit.com', // $idaa_slct.post_obj.email,
to_name: $ae_loc.site_cfg_json?.admin_name ?? 'IDAA BB Admin',
subject: subject,
body_html: body_html,

View File

@@ -212,9 +212,13 @@ onDestroy(() => {
{/if}
{#if ($ae_loc.trusted_access && $ae_loc.edit_mode) || $idaa_loc.novi_uuid}
<button
type="button"
on:click={() => {
if (confirm('Are you sure you want to add a new comment?')) {
$idaa_sess.bb.show_edit__post_comment = true;
$idaa_slct.post_comment_id = null;
$idaa_slct.post_comment_obj = {};
$idaa_sess.bb.show__inline_edit__post_comment_id = true;
}
}}
class="btn btn-md variant-ghost-secondary hover:variant-filled-secondary transition"
@@ -226,6 +230,7 @@ onDestroy(() => {
{#if ($ae_loc.trusted_access && $ae_loc.edit_mode) || $lq__post_obj?.external_person_id === $idaa_loc.novi_uuid}
<button
type="button"
on:click={() => {
// $idaa_slct.post_id = $idaa_slct.post_obj.post_id_random;
$idaa_slct.post_obj = $lq__post_obj; // In case things changed
@@ -250,6 +255,12 @@ onDestroy(() => {
{/if}
{#if $idaa_sess.bb.show__inline_edit__post_comment_id === true}
<Comp__post_comment_obj_id_edit
lq__post_comment_obj={lq__post_comment_obj}
/>
{/if}
{#if $lq__post_comment_obj_li?.length}
<section class="post_comment_obj_li space-y-2 border border-1 p-0 border-y-0">
{#each $lq__post_comment_obj_li as post_comment_obj, index}
@@ -296,7 +307,9 @@ onDestroy(() => {
{#if ($ae_loc.trusted_access && $ae_loc.edit_mode) || post_comment_obj.external_person_id === $idaa_loc.novi_uuid}
<div class="ae_options">
<button on:click={() => {
<button
type="button"
on:click={() => {
$idaa_slct.post_comment_id = post_comment_obj.post_comment_id;
$idaa_slct.post_comment_obj = post_comment_obj;