Skip to content

Commit

Permalink
Use useEventListener and destroyed hook for clearing cart in success
Browse files Browse the repository at this point in the history
  • Loading branch information
Jade-GG committed Jan 6, 2025
1 parent 77f04f2 commit 32cf70b
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions resources/js/components/Checkout/CheckoutSuccess.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import { order, refresh as refreshOrder, clear as clearOrder } from '../../stores/useOrder'
import { clear as clearCart } from '../../stores/useCart'
import { useEventListener } from '@vueuse/core'
export default {
data() {
Expand All @@ -20,17 +21,24 @@ export default {
}
refreshOrder()
this.$root.$emit('checkout-success', this.order)
window.addEventListener('beforeunload', function (event) {
useEventListener(window, 'beforeunload', this.beforeUnloadCallback, { once: true })
},
destroyed() {
this.beforeUnloadCallback()
},
methods: {
beforeUnloadCallback() {
clearCart()
if (!window.debug) {
clearOrder()
}
return undefined
})
},
},
methods: {
async refreshOrder() {
await refreshOrder()
},
Expand Down

0 comments on commit 32cf70b

Please sign in to comment.