Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"dependencies": {
"@vueuse/core": "^13.6.0",
"@vueuse/router": "^13.6.0",
"canvas-confetti": "^1.9.3",
"feather-icons": "^4.29.2",
"frappe-ui": "^0.1.257",
Expand Down
24 changes: 20 additions & 4 deletions dashboard/src/components/BookingForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
v-model="couponCode"
:placeholder="__('Enter code')"
:aria-label="__('Coupon code')"
class="flex-1"
class="flex-1 uppercase"
@keyup.enter="applyCoupon"
/>
<Button
Expand Down Expand Up @@ -404,6 +404,7 @@ import { clearBookingCache } from "@/utils/index";
import { FormControl, createResource, toast } from "frappe-ui";
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useRouteQuery } from "@vueuse/router";
import LucideAlertCircle from "~icons/lucide/alert-circle";
import LucideCheck from "~icons/lucide/check";
import LucideCheckCircle from "~icons/lucide/check-circle";
Expand Down Expand Up @@ -518,7 +519,8 @@ const activeOfflineCustomFields = computed(() => {
return selectedOfflineMethod.value.custom_fields || [];
});

// Coupon state
// Coupon state — `appliedCouponQuery` keeps the URL in sync with the applied coupon
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove this comment?

const appliedCouponQuery = useRouteQuery("coupon", null);
const couponCode = ref("");
const couponApplied = ref(false);
const couponError = ref("");
Expand Down Expand Up @@ -822,6 +824,13 @@ onMounted(async () => {

attendees.value = [newAttendee];
}

// Pre-fill and auto-apply coupon from ?coupon= query param
const initialCoupon = appliedCouponQuery.value;
if (typeof initialCoupon === "string" && initialCoupon.trim() && !couponApplied.value) {
couponCode.value = initialCoupon.trim().toUpperCase();
await applyCoupon();
}
Comment on lines +829 to +833
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user is not logged in applyCoupon fails and gives this error

Image

This error also comes if the user applies the coupon manually

Issue

});

// Ensure existing attendees have proper add-on structure when availableAddOns changes
Expand Down Expand Up @@ -962,16 +971,20 @@ function sendOtpForVerification() {

// --- COUPON FUNCTIONS ---
async function applyCoupon() {
if (!couponCode.value.trim()) {
const normalizedCode = couponCode.value.trim().toUpperCase();
if (!normalizedCode) {
couponError.value = __("Please enter a coupon code");
return;
}

// Reflect normalized casing back into the input / applied card
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we remove this commnet?

couponCode.value = normalizedCode;

couponError.value = "";
let result;
try {
const params = {
coupon_code: couponCode.value.trim(),
coupon_code: normalizedCode,
event: eventId.value,
};
// Pass user email for guest mode to properly check per-user limits
Expand Down Expand Up @@ -1018,6 +1031,8 @@ async function applyCoupon() {
};
// Info panel shows details - no toast needed
}

appliedCouponQuery.value = normalizedCode;
} else {
couponApplied.value = false;
couponData.value = null;
Expand All @@ -1030,6 +1045,7 @@ function removeCoupon() {
couponApplied.value = false;
couponData.value = null;
couponError.value = "";
appliedCouponQuery.value = null;
}

// --- FORM VALIDATION ---
Expand Down
12 changes: 12 additions & 0 deletions dashboard/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1147,6 +1147,13 @@
resolved "https://registry.npmjs.org/@vueuse/metadata/-/metadata-13.6.0.tgz"
integrity sha512-rnIH7JvU7NjrpexTsl2Iwv0V0yAx9cw7+clymjKuLSXG0QMcLD0LDgdNmXic+qL0SGvgSVPEpM9IDO/wqo1vkQ==

"@vueuse/router@^13.6.0":
version "13.9.0"
resolved "https://registry.yarnpkg.com/@vueuse/router/-/router-13.9.0.tgz#44235e6732a30b53d1c8e2ef13ce783fdd189ca6"
integrity sha512-7AYay8Pv/0fC4D0eygbIyZuLyVs+9D7dsnO5D8aqat9qcOz91v/XFWR667WE1+p+OkU0ib+FjQUdnTVBNoIw8g==
dependencies:
"@vueuse/shared" "13.9.0"

"@vueuse/shared@10.11.1", "@vueuse/shared@^10.5.0":
version "10.11.1"
resolved "https://registry.npmjs.org/@vueuse/shared/-/shared-10.11.1.tgz"
Expand All @@ -1166,6 +1173,11 @@
resolved "https://registry.npmjs.org/@vueuse/shared/-/shared-13.6.0.tgz"
integrity sha512-pDykCSoS2T3fsQrYqf9SyF0QXWHmcGPQ+qiOVjlYSzlWd9dgppB2bFSM1GgKKkt7uzn0BBMV3IbJsUfHG2+BCg==

"@vueuse/shared@13.9.0":
version "13.9.0"
resolved "https://registry.yarnpkg.com/@vueuse/shared/-/shared-13.9.0.tgz#7168b4ed647e625b05eb4e7e80fe8aabd00e3923"
integrity sha512-e89uuTLMh0U5cZ9iDpEI2senqPGfbPRTHM/0AaQkcxnpqjkZqDYP8rpfm7edOz8s+pOCOROEy1PIveSW8+fL5g==

acorn@^8.14.0, acorn@^8.14.1, acorn@^8.15.0:
version "8.15.0"
resolved "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz"
Expand Down
Loading