Skip to content

Commit 3564012

Browse files
committed
ok cool
1 parent 1c655d1 commit 3564012

File tree

4 files changed

+123
-32
lines changed

4 files changed

+123
-32
lines changed

public/member/apiService.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { GOOGLE_APPS_SCRIPT_URL } from './constants.js';
1313
* @returns {Promise} - Promise representing the fetch request
1414
*/
1515
export function postToAppsScript(data, onSuccess = null, onError = null) {
16+
// Log data being sent to the API for debugging
17+
console.log('Sending data to Google Apps Script:', data);
18+
1619
return fetch(GOOGLE_APPS_SCRIPT_URL, {
1720
method: 'POST',
1821
headers: {

public/member/constants.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,52 @@ export const irlShopItems = [
1616
{
1717
id: "drinks",
1818
name: "Drinks (Capri Sun, Soda)",
19-
price: 100,
19+
price: 108,
2020
},
2121

2222
{
2323
id: "drinks",
2424
name: "Celcius",
25-
price: 150,
25+
price: 161,
2626
},
2727
// Snack Packs
2828
{
2929
id: "smallsnacks",
3030
name: "Fruit Snacks/Rice Krispies)",
31-
price: 50,
31+
price: 54,
3232
},
3333

3434
// Chips
3535
{
3636
id: "chips",
3737
name: "Chips",
38-
price: 100,
38+
price: 108,
3939
},
4040

4141
// Candy
4242
{
4343
id: "candy",
4444
name: "Candy (Twix, M&Ms, Snickers, Sour Patch, Airhead)",
45-
price: 150,
45+
price: 161,
4646
},
4747

4848
// Microwaveable Foods
4949
{
5050
id: "popcorn",
5151
name: "Popcorn",
52-
price: 100,
52+
price: 108,
5353
},
5454
{
5555
id: "microwavemeals",
5656
name: "Microwave Meals (Ramen/Mac and Cheese)",
57-
price: 150,
57+
price: 161,
5858
},
5959

6060
// Pop Tarts
6161
{
6262
id: "poptarts",
6363
name: "Pop Tarts",
64-
price: 100,
64+
price: 108,
6565
},
6666
{
6767
id: "shirtXS",
@@ -134,6 +134,6 @@ export const activityData = {
134134
"VexU": [],
135135
"BusinessOrAdvertising": [],
136136
"LM": [],
137-
"VolunteerTabling": [],
137+
"Volunteer": [],
138138
"Other": []
139139
};

public/member/membershipForm.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,15 @@ function setupFormSubmissionHandler() {
5959
'TYPE': 'MEMBERSHIP' // Default type for membership form
6060
};
6161

62+
// Log form data for debugging
63+
console.log("Form data before processing:", Object.fromEntries(formData));
64+
6265
// Process all form fields
6366
processFormFields(memberForm, data);
6467

68+
// Log processed data
69+
console.log("Processed data being submitted:", data);
70+
6571
// Submit data to Google Apps Script
6672
submitMembershipForm(memberForm, data, submitButton, originalButtonText);
6773
});
@@ -96,18 +102,26 @@ function processFormFields(form, data) {
96102
return;
97103
}
98104

99-
// Handle radio buttons - only process if checked
100-
if (element.type === 'radio' && !element.checked) {
101-
return;
105+
// Handle radio buttons
106+
if (element.type === 'radio') {
107+
// Only process checked radio buttons
108+
if (element.checked) {
109+
// If value is not 'other', add it to the data object
110+
if (element.value !== 'other') {
111+
data[fieldName] = element.value;
112+
}
113+
// 'other' values will be handled separately below
114+
}
115+
return; // Skip further processing for radio buttons
102116
}
103117

104118
// Skip text inputs that are part of "other" options (will be processed later)
105119
if (element.type === 'text' && element.id.startsWith('other')) {
106120
return;
107121
}
108122

109-
// Standard field processing for non-other fields
110-
if (element.type !== 'radio' && element.type !== 'checkbox') {
123+
// Standard field processing for non-radio and non-checkbox fields
124+
if (element.type !== 'checkbox') {
111125
if (element.value.trim() !== '' || element.required) {
112126
data[fieldName] = element.value;
113127
}

public/member/shopFunctions.js

Lines changed: 92 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
import { shopItems, irlShopItems, HCB_BASE_URL } from './constants.js';
77
import { getPurchasesByEid } from './eidStats.js';
88

9+
// Track current shop mode globally
10+
let currentShopMode = 'regular';
11+
912
/**
1013
* Initialize shop functionality
1114
*/
1215
export function initShopFunctionality() {
16+
// Check if we're in IRL mode from URL
17+
const searchParams = new URLSearchParams(window.location.search);
18+
currentShopMode = searchParams.get('irl') === '1' ? 'irl' : 'regular';
19+
1320
// Generate the shop table
14-
generateShopTable();
21+
generateShopTable(currentShopMode);
1522

1623
// Add event listener to checkout button
1724
const checkoutBtn = document.getElementById('checkoutBtn');
@@ -58,21 +65,74 @@ export function processShopItems(itemsArray = shopItems) {
5865
});
5966
}
6067

68+
/**
69+
* Switch between shop types (IRL vs Regular) without page reload
70+
* @param {string} mode - The shop mode to switch to ('irl' or 'regular')
71+
*/
72+
export function switchShopType(mode) {
73+
// Show a brief loading message
74+
const container = document.getElementById('shopTableContainer');
75+
if (container) {
76+
const loadingMsg = document.createElement('div');
77+
loadingMsg.textContent = 'Loading...';
78+
loadingMsg.style.padding = '10px';
79+
loadingMsg.style.textAlign = 'center';
80+
container.innerHTML = '';
81+
container.appendChild(loadingMsg);
82+
}
83+
84+
// Small delay to allow UI update
85+
setTimeout(() => {
86+
// Update current shop mode
87+
currentShopMode = mode === 'irl' ? 'irl' : 'regular';
88+
89+
// Update URL without reloading the page
90+
const url = new URL(window.location);
91+
if (currentShopMode === 'irl') {
92+
url.searchParams.set('irl', '1');
93+
} else {
94+
url.searchParams.set('irl', '0');
95+
}
96+
window.history.pushState({}, '', url);
97+
98+
// Clear existing table
99+
if (container) {
100+
container.innerHTML = '';
101+
}
102+
103+
// Regenerate the shop table with the new mode
104+
generateShopTable(currentShopMode);
105+
106+
// Recalculate total
107+
updateTotal();
108+
}, 100); // Short delay for better user experience
109+
}
110+
61111
/**
62112
* Generate shop table from items array
113+
* @param {string} mode - The shop mode ('irl' or 'regular')
63114
*/
64-
export function generateShopTable() {
115+
export function generateShopTable(mode = null) {
65116
const container = document.getElementById('shopTableContainer');
66117
if (!container) return;
67118

68-
// Check if we're in IRL mode
69-
const isIrlMode = new URLSearchParams(window.location.search).has('irl');
119+
// If mode is not provided, use the current shop mode or determine from URL
120+
if (mode === null) {
121+
const searchParams = new URLSearchParams(window.location.search);
122+
mode = searchParams.get('irl') === '1' ? 'irl' : 'regular';
123+
currentShopMode = mode;
124+
}
125+
126+
const isIrlMode = mode === 'irl';
70127

71128
// Get the items to display based on mode
72-
let itemsToProcess = [...shopItems]; // Make a copy of the array
129+
let itemsToProcess = [];
73130
if (isIrlMode) {
74-
// In IRL mode, show IRL items first, then regular items
75-
itemsToProcess = [...irlShopItems, ...shopItems];
131+
// In IRL mode, show ONLY IRL items
132+
itemsToProcess = [...irlShopItems];
133+
} else {
134+
// In regular mode, show ONLY regular shop items
135+
itemsToProcess = [...shopItems];
76136
}
77137

78138
// Process items to propagate values
@@ -179,18 +239,32 @@ export function generateShopTable() {
179239
table.appendChild(tbody);
180240
container.appendChild(table);
181241

182-
// Add "Snack Shop" link if we're NOT already in IRL mode
183-
if (!isIrlMode) {
184-
const snackShopLink = document.createElement('a');
185-
snackShopLink.href = window.location.pathname + '?irl=1';
186-
snackShopLink.textContent = 'Snack Shop';
187-
snackShopLink.style.color = '#0066cc';
188-
snackShopLink.style.textDecoration = 'underline';
189-
snackShopLink.style.display = 'inline-block';
190-
snackShopLink.style.marginTop = '10px';
191-
snackShopLink.style.fontSize = '0.9em';
192-
container.appendChild(snackShopLink);
242+
// Add shop switch link
243+
const shopSwitchLink = document.createElement('a');
244+
shopSwitchLink.href = '#'; // Use # to prevent page navigation
245+
246+
if (isIrlMode) {
247+
shopSwitchLink.textContent = 'Switch to Online Shop';
248+
shopSwitchLink.setAttribute('data-target-mode', 'regular');
249+
} else {
250+
shopSwitchLink.textContent = 'Switch to Snack Shop';
251+
shopSwitchLink.setAttribute('data-target-mode', 'irl');
193252
}
253+
254+
// Add click event listener to switch shop type without page reload
255+
shopSwitchLink.addEventListener('click', function(e) {
256+
e.preventDefault(); // Prevent the default link behavior
257+
const targetMode = this.getAttribute('data-target-mode');
258+
switchShopType(targetMode);
259+
});
260+
261+
shopSwitchLink.style.color = '#0066cc';
262+
shopSwitchLink.style.textDecoration = 'underline';
263+
shopSwitchLink.style.display = 'inline-block';
264+
shopSwitchLink.style.marginTop = '10px';
265+
shopSwitchLink.style.fontSize = '0.9em';
266+
shopSwitchLink.style.cursor = 'pointer';
267+
container.appendChild(shopSwitchLink);
194268
}
195269

196270
/**

0 commit comments

Comments
 (0)