fix(pres_mgmt): guard poc_kv_json null access in POC profile and agree modals

poc_kv_json is null when a session has never had POC data saved. Any bracket
access on it crashed immediately on modal open. Fix:
- Reads: use ?.[poc_type] optional chaining everywhere (checkboxes, biography_updated_on)
- Writes: initialize from a shallow copy of poc_kv_json ?? {} before indexing into it,
  so the first save on a fresh session creates the structure rather than throwing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Scott Idem
2026-06-12 15:55:25 -04:00
parent 080ad06a45
commit 94bdeb9a26
2 changed files with 17 additions and 32 deletions

View File

@@ -97,20 +97,12 @@ async function handle_submit_form(event: SubmitEvent) {
console.log(`opt_out_do:`, opt_out_do);
let event_session_data = {
poc_kv_json: lq__event_session_obj.poc_kv_json
};
console.log('event_session_data:', event_session_data);
// poc_kv_json may be null if no POC data has been saved yet — initialize before writing.
const kv: key_val = { ...(lq__event_session_obj.poc_kv_json ?? {}) };
if (!kv[poc_type]) kv[poc_type] = {};
kv[poc_type] = { ...kv[poc_type], ...opt_out_do };
// Check if poc_type exists in the event_session_data.poc_kv_json
if (!event_session_data.poc_kv_json[poc_type]) {
event_session_data.poc_kv_json[poc_type] = {};
}
event_session_data.poc_kv_json[poc_type] = {
...event_session_data.poc_kv_json[poc_type],
...opt_out_do
};
let event_session_data = { poc_kv_json: kv };
// Use this in the future if we need to store the agreements in a more complex way?
// let event_session_data = {poc_kv_json: lq__event_session_obj?.poc_kv_json};
@@ -201,7 +193,7 @@ async function handle_submit_form(event: SubmitEvent) {
class="checkbox preset-tonal-warning border-warning-500 checked:preset-filled-warning-500 hover:preset-filled-error-500 border"
id="optout_audio"
name="optout_audio"
checked={lq__event_session_obj.poc_kv_json[poc_type]
checked={lq__event_session_obj.poc_kv_json?.[poc_type]
?.optout_audio}
value={true} />
Opt-out - Audio Reproduction of Presentation
@@ -215,7 +207,7 @@ async function handle_submit_form(event: SubmitEvent) {
class="checkbox preset-tonal-warning border-warning-500 checked:preset-filled-warning-500 hover:preset-filled-error-500 border"
id="optout_video"
name="optout_video"
checked={lq__event_session_obj.poc_kv_json[poc_type]
checked={lq__event_session_obj.poc_kv_json?.[poc_type]
?.optout_video}
value={true} />
Opt-out - Video Reproduction of Presentation
@@ -229,7 +221,7 @@ async function handle_submit_form(event: SubmitEvent) {
class="checkbox preset-tonal-warning border-warning-500 checked:preset-filled-warning-500 hover:preset-filled-error-500 border"
id="optout_transcription_and_publication"
name="optout_transcription_and_publication"
checked={lq__event_session_obj.poc_kv_json[poc_type]
checked={lq__event_session_obj.poc_kv_json?.[poc_type]
?.optout_transcription_and_publication}
value={true} />
Opt-out - Transcription and Publication of Presentation on LCI
@@ -244,7 +236,7 @@ async function handle_submit_form(event: SubmitEvent) {
class="checkbox preset-tonal-warning border-warning-500 checked:preset-filled-warning-500 hover:preset-filled-error-500 border"
id="optout_publication_in_app"
name="optout_publication_in_app"
checked={lq__event_session_obj.poc_kv_json[poc_type]
checked={lq__event_session_obj.poc_kv_json?.[poc_type]
?.optout_publication_in_app}
value={true} />
Opt-out - Publication of Presentation on LCI Congress App

View File

@@ -135,19 +135,13 @@ let clipboard_success = $state(false);
disabled={ae_tmp.biography ==
lq__event_session_obj.biography}
onclick={() => {
let event_session_data = {
poc_kv_json: lq__event_session_obj.poc_kv_json
};
// poc_kv_json may be null if no POC data has been saved yet — initialize before writing.
const kv: key_val = { ...(lq__event_session_obj.poc_kv_json ?? {}) };
if (!kv[poc_type]) kv[poc_type] = {};
kv[poc_type]['biography'] = ae_tmp.biography;
kv[poc_type]['biography_updated_on'] = new Date().toISOString();
if (!event_session_data.poc_kv_json[poc_type]) {
event_session_data.poc_kv_json[poc_type] = {};
}
event_session_data.poc_kv_json[poc_type]['biography'] =
ae_tmp.biography;
event_session_data.poc_kv_json[poc_type][
'biography_updated_on'
] = new Date().toISOString();
let event_session_data = { poc_kv_json: kv };
ae_promises.update__event_session_obj = events_func
.update_ae_obj__event_session({
@@ -171,11 +165,10 @@ let clipboard_success = $state(false);
Save Biography
</button>
{#if lq__event_session_obj.poc_kv_json[poc_type]?.biography_updated_on}
{#if lq__event_session_obj.poc_kv_json?.[poc_type]?.biography_updated_on}
<span class="text-sm text-gray-500">
Last saved: {ae_util.iso_datetime_formatter(
lq__event_session_obj.poc_kv_json[poc_type]
?.biography_updated_on,
lq__event_session_obj.poc_kv_json?.[poc_type]?.biography_updated_on,
'datetime_12_long'
)}
</span>