Skip to content

Commit e4e1e72

Browse files
committed
Add vial code active status
1 parent 1de61e8 commit e4e1e72

File tree

3 files changed

+72
-20
lines changed

3 files changed

+72
-20
lines changed

src/components/CustomerResult/index.jsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,20 @@ export const CustomerResult = ({ result, code, eventData }) => {
7777
</div>
7878
</div>
7979

80-
<div className={`bg-gradient-to-br ${result.gradient} rounded-xl p-1 shadow-[6px_6px_0px_#1d248a] transform hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-[2px_2px_0px_#1d248a] transition-all cursor-default`}>
81-
<div className="border-2 border-white/40 rounded-lg p-4 bg-gradient-to-br from-white/10 to-transparent backdrop-blur-sm relative overflow-hidden">
82-
<div className="absolute -right-4 -top-4 text-white/10 rotate-12">
83-
<ShoppingBag className="w-16 h-16" />
84-
</div>
85-
<p className="text-[8px] font-bold text-white/90 uppercase tracking-widest mb-2 relative z-10">Tunjukkan Kode Ini</p>
86-
<div className="text-4xl font-black font-mono tracking-widest text-white drop-shadow-[3px_3px_0px_rgba(0,0,0,0.3)] relative z-10 mb-3">
87-
{code}
80+
{eventData?.vibeCodeActive === true && (
81+
<div className={`bg-gradient-to-br ${result.gradient} rounded-xl p-1 shadow-[6px_6px_0px_#1d248a] transform hover:translate-x-[2px] hover:translate-y-[2px] hover:shadow-[2px_2px_0px_#1d248a] transition-all cursor-default`}>
82+
<div className="border-2 border-white/40 rounded-lg p-4 bg-gradient-to-br from-white/10 to-transparent backdrop-blur-sm relative overflow-hidden">
83+
<div className="absolute -right-4 -top-4 text-white/10 rotate-12">
84+
<ShoppingBag className="w-16 h-16" />
85+
</div>
86+
<p className="text-[8px] font-bold text-white/90 uppercase tracking-widest mb-2 relative z-10">Tunjukkan Kode Ini</p>
87+
<div className="text-4xl font-black font-mono tracking-widest text-white drop-shadow-[3px_3px_0px_rgba(0,0,0,0.3)] relative z-10 mb-3">
88+
{code}
89+
</div>
90+
<p className="text-[8px] font-bold text-white/80 uppercase tracking-widest relative z-10">Untuk Klaim Free Vial Parfume</p>
8891
</div>
89-
<p className="text-[8px] font-bold text-white/80 uppercase tracking-widest relative z-10">Untuk Klaim Free Vial Parfume</p>
9092
</div>
91-
</div>
93+
)}
9294

9395
{/* Marketplace Vouchers - Only show if event has marketplace data */}
9496
{eventData?.marketplaces && eventData.marketplaces.length > 0 && (

src/hooks/useQuiz.js

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ export const useQuiz = (user, onQuizComplete = () => { }, eventId = 'global', de
2525
if (APP_CONFIG.enableEvents && eventId && eventId !== APP_CONFIG.defaultEventId) {
2626
const fetchEventData = async () => {
2727
try {
28-
const eventDoc = await getDoc(
29-
doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data', 'events', eventId)
30-
);
28+
const [eventDoc, rootDoc] = await Promise.all([
29+
getDoc(doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data', 'events', eventId)),
30+
getDoc(doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data'))
31+
]);
3132
if (eventDoc.exists()) {
32-
setEventData({ id: eventDoc.id, ...eventDoc.data() });
33+
setEventData({
34+
id: eventDoc.id,
35+
...eventDoc.data(),
36+
vibeCodeActive: rootDoc.exists() ? (rootDoc.data()?.vibeCodeActive ?? false) : false
37+
});
3338
}
3439
} catch (error) {
3540
console.error("Error fetching event data:", error);
@@ -43,7 +48,11 @@ export const useQuiz = (user, onQuizComplete = () => { }, eventId = 'global', de
4348
doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data')
4449
);
4550
if (mpDoc.exists()) {
46-
setEventData({ id: null, marketplaces: mpDoc.data()?.marketplaces || [] });
51+
setEventData({
52+
id: null,
53+
marketplaces: mpDoc.data()?.marketplaces || [],
54+
vibeCodeActive: mpDoc.data()?.vibeCodeActive ?? false
55+
});
4756
} else {
4857
console.log("No vouchers found");
4958
}
@@ -88,15 +97,36 @@ export const useQuiz = (user, onQuizComplete = () => { }, eventId = 'global', de
8897
let fetchedEventData = eventData;
8998
if (existingData.eventId && !eventData) {
9099
try {
91-
const eventDoc = await getDoc(
92-
doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data', 'events', existingData.eventId)
93-
);
100+
const [eventDoc, rootDoc] = await Promise.all([
101+
getDoc(doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data', 'events', existingData.eventId)),
102+
getDoc(doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data'))
103+
]);
104+
const vibeCodeActive = rootDoc.exists() ? (rootDoc.data()?.vibeCodeActive ?? false) : false;
94105
if (eventDoc.exists()) {
95-
fetchedEventData = eventDoc.data();
106+
fetchedEventData = { ...eventDoc.data(), vibeCodeActive };
107+
} else {
108+
fetchedEventData = {
109+
id: null,
110+
marketplaces: rootDoc.exists() ? (rootDoc.data()?.marketplaces || []) : [],
111+
vibeCodeActive
112+
};
96113
}
97114
} catch (error) {
98115
console.error("Error fetching event data for existing result:", error);
99116
}
117+
} else if (!eventData) {
118+
try {
119+
const rootDoc = await getDoc(doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data'));
120+
if (rootDoc.exists()) {
121+
fetchedEventData = {
122+
id: null,
123+
marketplaces: rootDoc.data()?.marketplaces || [],
124+
vibeCodeActive: rootDoc.data()?.vibeCodeActive ?? false
125+
};
126+
}
127+
} catch (error) {
128+
console.error("Error fetching root data for existing result:", error);
129+
}
100130
}
101131

102132
onQuizComplete({

src/pages/InsightsPage.jsx

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const InsightsDashboard = () => {
2525
const [showEventForm, setShowEventForm] = useState(false);
2626
const [eventFilter, setEventFilter] = useState("All");
2727
const [editingEventId, setEditingEventId] = useState(null);
28+
const [vibeCodeActive, setVibeCodeActive] = useState(false);
2829
const [formData, setFormData] = useState({
2930
name: '',
3031
location: '',
@@ -93,6 +94,7 @@ export const InsightsDashboard = () => {
9394
endDate: '',
9495
marketplaces: mpDoc.data()?.marketplaces || []
9596
});
97+
setVibeCodeActive(mpDoc.data()?.vibeCodeActive ?? false);
9698
} else {
9799
console.log("No vouchers found");
98100
}
@@ -201,7 +203,7 @@ export const InsightsDashboard = () => {
201203
try {
202204
// Update vouchers
203205
const eventRef = doc(db, 'artifacts', ARTIFACT_ID, 'public', 'data');
204-
await updateDoc(eventRef, { marketplaces: formData.marketplaces });
206+
await updateDoc(eventRef, { marketplaces: formData.marketplaces, vibeCodeActive });
205207

206208
alert('Voucher updated successfully!');
207209
} catch (error) {
@@ -994,6 +996,24 @@ export const InsightsDashboard = () => {
994996
</h3>
995997
<form onSubmit={handleConfigureVouchers} className="space-y-6">
996998

999+
{/* Vial Code Toggle */}
1000+
<div className="flex items-center gap-4 p-4 bg-gray-50 rounded-xl border-2 border-gray-200">
1001+
<input
1002+
type="checkbox"
1003+
id="vibeCodeActive"
1004+
checked={vibeCodeActive}
1005+
onChange={(e) => setVibeCodeActive(e.target.checked)}
1006+
className="w-5 h-5 rounded accent-[#4338ca] cursor-pointer"
1007+
/>
1008+
<label htmlFor="vibeCodeActive" className="flex flex-col cursor-pointer flex-1">
1009+
<span className="text-sm font-black text-[#1d248a] uppercase tracking-wide">Show Vial Code to Customers</span>
1010+
<span className="text-xs text-gray-500 mt-0.5">When enabled, customers will see their unique vial claim code on the result page</span>
1011+
</label>
1012+
<div className={`px-3 py-1 rounded-full text-[10px] font-black uppercase tracking-widest ${vibeCodeActive ? 'bg-[#a3e635] text-[#1d248a]' : 'bg-gray-200 text-gray-500'}`}>
1013+
{vibeCodeActive ? 'Active' : 'Inactive'}
1014+
</div>
1015+
</div>
1016+
9971017
{/* Marketplace Configuration */}
9981018
<div className="border-t-2 border-gray-200 pt-6">
9991019
<label className="block text-sm font-black text-[#1d248a] uppercase tracking-wide mb-4">{`Marketplace ${APP_CONFIG.enableEvents ? 'Global ' : ''}Vouchers (Optional)`}</label>

0 commit comments

Comments
 (0)