Skip to content

Commit 1c655d1

Browse files
committed
localstorage + eid handling uppercase + more food
1 parent 6e653de commit 1c655d1

File tree

4 files changed

+103
-15
lines changed

4 files changed

+103
-15
lines changed

public/member/.htaccess

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# /member/.htaccess (scoped to this directory only)
2+
Options -MultiViews
3+
DirectoryIndex index.html

public/member/constants.js

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,76 @@ export const HCB_BASE_URL = 'https://hcb.hackclub.com/donations/start/austin-iee
1212

1313
// IRL-only shop items (snacks, etc)
1414
export const irlShopItems = [
15+
// Drinks
1516
{
16-
id: "caprisun",
17-
name: "CapriSun",
18-
price: 50,
17+
id: "drinks",
18+
name: "Drinks (Capri Sun, Soda)",
19+
price: 100,
1920
},
21+
2022
{
21-
id: "poptart",
22-
name: "PopTart",
23+
id: "drinks",
24+
name: "Celcius",
25+
price: 150,
26+
},
27+
// Snack Packs
28+
{
29+
id: "smallsnacks",
30+
name: "Fruit Snacks/Rice Krispies)",
2331
price: 50,
2432
},
33+
34+
// Chips
35+
{
36+
id: "chips",
37+
name: "Chips",
38+
price: 100,
39+
},
40+
41+
// Candy
42+
{
43+
id: "candy",
44+
name: "Candy (Twix, M&Ms, Snickers, Sour Patch, Airhead)",
45+
price: 150,
46+
},
47+
48+
// Microwaveable Foods
49+
{
50+
id: "popcorn",
51+
name: "Popcorn",
52+
price: 100,
53+
},
54+
{
55+
id: "microwavemeals",
56+
name: "Microwave Meals (Ramen/Mac and Cheese)",
57+
price: 150,
58+
},
59+
60+
// Pop Tarts
61+
{
62+
id: "poptarts",
63+
name: "Pop Tarts",
64+
price: 100,
65+
},
2566
{
26-
id: "shirtXSpost",
67+
id: "shirtXS",
2768
name: "Shirt (Overstock) XS",
2869
price: 1500,
2970
},
3071
{
31-
id: "shirtSpost",
72+
id: "shirtS",
3273
name: "Shirt (Overstock) S",
3374
},
3475
{
35-
id: "shirtMpost",
76+
id: "shirtM",
3677
name: "Shirt (Overstock) M"
3778
},
3879
{
39-
id: "shirtLpost",
80+
id: "shirtL",
4081
name: "Shirt (Overstock) L"
4182
},
4283
{
43-
id: "shirtXLpost",
84+
id: "shirtXL",
4485
name: "Shirt (Overstock) XL"
4586
},
4687
];

public/member/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ <h2>Welcome to the Member Area</h2>
1919

2020
<div class="form-group eid-lookup">
2121
<label for="eid">Enter your UT EID *</label>
22-
<input type="text" id="eid" name="eid" required pattern="[a-z]{2,3}[0-9]{3,8}" title="Enter a valid UT EID (2-3 lowercase letters followed by 3-8 numbers)">
23-
<small class="form-text">Your UT EID should be 2-3 lowercase letters followed by 3-8 numbers</small>
22+
<input type="text" id="eid" name="eid" required pattern="[a-zA-Z]{2,3}[0-9]{3,8}" title="Enter a valid UT EID (2-3 letters followed by 3-8 numbers)">
23+
<small class="form-text">Your UT EID should be 2-3 letters followed by 3-8 numbers</small>
2424
<div id="eidStatus" class="status-message"></div>
2525
</div>
2626

public/member/script.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,24 @@ document.addEventListener('DOMContentLoaded', function() {
4545
// Function to process EID if already present on load
4646
function processExistingEid() {
4747
const eidInput = document.getElementById('eid');
48-
if (eidInput && eidInput.value && eidInput.value.trim() !== '') {
49-
// Trigger the blur event to process the EID
48+
if (!eidInput) return;
49+
50+
// Try to restore saved EID from localStorage
51+
try {
52+
const saved = localStorage.getItem('savedEid');
53+
if (saved && saved.trim() !== '') {
54+
eidInput.value = saved;
55+
// Trigger the blur event to process the EID
56+
const event = new Event('blur');
57+
eidInput.dispatchEvent(event);
58+
return;
59+
}
60+
} catch (e) {
61+
console.warn('Unable to access localStorage to restore EID', e);
62+
}
63+
64+
// Fallback: if the input already has a value (e.g., prefilled), process it
65+
if (eidInput.value && eidInput.value.trim() !== '') {
5066
const event = new Event('blur');
5167
eidInput.dispatchEvent(event);
5268
}
@@ -74,6 +90,13 @@ document.addEventListener('DOMContentLoaded', function() {
7490
if (eid === '') {
7591
statusElement.textContent = '';
7692
statusElement.className = 'status-message';
93+
// Clear saved EID info from localStorage
94+
try {
95+
localStorage.removeItem('savedEid');
96+
localStorage.removeItem('savedEidMemberExists');
97+
} catch (e) {
98+
console.warn('Unable to clear localStorage for EID', e);
99+
}
77100
return;
78101
}
79102

@@ -87,12 +110,33 @@ document.addEventListener('DOMContentLoaded', function() {
87110
try {
88111
// EID format is valid, proceed with checking if it exists
89112
const memberExists = await fetchMemberInfo(eid);
113+
114+
// Persist EID and membership-exists flag so we can restore them on next load
115+
try {
116+
localStorage.setItem('savedEid', eid);
117+
localStorage.setItem('savedEidMemberExists', memberExists ? '1' : '0');
118+
} catch (e) {
119+
console.warn('Unable to save EID to localStorage', e);
120+
}
90121

91122
// Only if EID is valid, show the content
92123
contentAfterEid.classList.remove('hidden-until-eid');
93124

94125
// Handle form visibility based on member existence
95126
handleFormVisibility(memberExists, eid);
127+
128+
// If we have restored a saved membership flag, ensure form visibility matches it
129+
try {
130+
const savedFlag = localStorage.getItem('savedEidMemberExists');
131+
if (savedFlag !== null) {
132+
// If savedFlag differs from memberExists, update it to reflect current state
133+
if ((savedFlag === '1') !== Boolean(memberExists)) {
134+
localStorage.setItem('savedEidMemberExists', memberExists ? '1' : '0');
135+
}
136+
}
137+
} catch (e) {
138+
// ignore
139+
}
96140

97141
// Regenerate the shop table to show purchase history for this EID
98142
const shopTableContainer = document.getElementById('shopTableContainer');
@@ -129,7 +173,7 @@ document.addEventListener('DOMContentLoaded', function() {
129173

130174
// Show validation message while typing
131175
if (!isValidEid(eid)) {
132-
statusElement.textContent = 'EID should be 2-3 lowercase letters followed by 3-8 numbers';
176+
statusElement.textContent = 'EID should be 2-3 letters followed by 3-8 numbers';
133177
statusElement.className = 'status-message warning';
134178
} else {
135179
statusElement.textContent = 'Valid EID format. Click/tab out to check membership.';

0 commit comments

Comments
 (0)