Skip to content

Commit ad4d8c4

Browse files
authored
Utilize DOM events to fix broken partial-submit (#1099)
1 parent c19493b commit ad4d8c4

File tree

12 files changed

+32
-16
lines changed

12 files changed

+32
-16
lines changed

resources/js/callbacks.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,27 @@ document.addEventListener('vue:loaded', function (event) {
2323
vue.config.globalProperties.submitPartials = async function (form, sequential = false) {
2424
let promises = []
2525
for (const element of form.querySelectorAll('[partial-submit]')) {
26-
if (!element.__vnode.props.onPartialSubmit) {
27-
continue
28-
}
29-
30-
const createdPromise = element.__vnode.props.onPartialSubmit().then((result) => {
26+
let resolveFn, rejectFn
27+
const createdPromise = new Promise((res, rej) => {
28+
resolveFn = res
29+
rejectFn = rej
30+
}).then((result) => {
3131
if (result === false) {
32-
throw new Error()
32+
throw new Error('Result was false')
3333
}
3434
})
3535

36+
const e = new CustomEvent('partial-submit', {
37+
detail: { resolve: resolveFn, reject: rejectFn },
38+
bubbles: false,
39+
cancelable: true,
40+
})
41+
42+
const dispatched = element.dispatchEvent(e)
43+
if (!dispatched) {
44+
resolveFn()
45+
}
46+
3647
if (sequential) {
3748
await createdPromise
3849
}

resources/js/components/Graphql.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,12 @@ export default {
103103
if (this.cache) {
104104
useLocalStorage(this.cachePrefix + this.cache, null, { serializer: StorageSerializers.object }).value = this.data
105105
}
106+
107+
return this.data
106108
} catch (error) {
107109
console.error(error)
108110
this.errorCallback(this.dataVariables, await error?.response?.json())
111+
return false
109112
} finally {
110113
this.running = false
111114
}

resources/js/components/GraphqlMutation.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export default {
185185
})
186186
187187
if (response.errors) {
188-
return
188+
return false
189189
}
190190
191191
if (this.callback) {
@@ -218,6 +218,8 @@ export default {
218218
}
219219
Turbo.visit(window.url(this.redirect))
220220
}
221+
222+
return response
221223
} catch (error) {
222224
console.error(error)
223225
this.error = error.message

resources/views/checkout/pages/credentials.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
.then((result) =>
1717
window.$emit('checkout-credentials-saved')
1818
&& window.Turbo.visit(window.url('{{ route('checkout', ['step' => 'payment']) }}'))
19-
).catch();
19+
).catch(() => {});
2020
}"
2121
class="flex flex-col gap-5"
2222
>

resources/views/checkout/pages/login.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
window.app.config.globalProperties.submitPartials(e.target?.form ?? e.target)
1414
.then((result) =>
1515
window.Turbo.visit(window.url('{{ route('checkout', ['step' => 'credentials']) }}'))
16-
).catch();
16+
).catch(() => {});
1717
}"
1818
class="max-w-md mx-auto"
1919
v-cloak

resources/views/checkout/pages/onestep.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
window.$emit('checkout-credentials-saved')
1515
&& window.$emit('checkout-payment-saved')
1616
&& window.$emit('placeOrder')
17-
).catch();
17+
).catch(() => {});
1818
}">
1919
<div class="lg:w-1/2 lg:pr-2.5 lg:col-span-2">
2020
@include('rapidez::checkout.steps.login')

resources/views/checkout/pages/payment.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
.then((result) =>
1515
window.$emit('checkout-payment-saved')
1616
&& window.$emit('placeOrder')
17-
).catch();
17+
).catch(() => {});
1818
}">
1919
@include('rapidez::checkout.steps.payment-method')
2020
<div class="mt-3">@include('rapidez::checkout.steps.agreements')</div>

resources/views/checkout/steps/billing-address.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
mutate-event="setBillingAddressOnCart"
1717
v-slot="{ mutate, variables }"
1818
>
19-
<div partial-submit="mutate">
19+
<div partial-submit v-on:partial-submit="(e) => mutate().then(e.detail.resolve).catch(e.detail.reject)">
2020
<fieldset v-on:change="function (e) {
2121
e.target.closest('fieldset').querySelector(':invalid') === null
2222
&& (!variables.same_as_shipping || !!cart?.shipping_addresses?.[0]?.postcode)

resources/views/checkout/steps/login.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
v-bind:allow-passwordless="Boolean({{ (int)(config('rapidez.frontend.allow_guest_on_existing_account')) }})"
44
v-bind:allow-guest="Boolean({{ (int)(Rapidez::config('checkout/options/guest_checkout')) }})"
55
>
6-
<fieldset partial-submit v-on:partial-submit="async () => await checkoutLogin.go()" class="flex flex-col gap-3" v-cloak>
6+
<fieldset partial-submit v-on:partial-submit="(e) => checkoutLogin.go().then(e.detail.resolve).catch(e.detail.reject)" class="flex flex-col gap-3" v-cloak>
77
<label>
88
<x-rapidez::label>@lang('Email')</x-rapidez::label>
99
<x-rapidez::input

resources/views/checkout/steps/payment-method.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
mutate-event="setPaymentMethodOnCart"
1212
v-slot="{ mutate, variables }"
1313
>
14-
<div class="flex flex-col gap-3" partial-submit v-on:partial-submit="async () => await mutate()">
14+
<div class="flex flex-col gap-3" partial-submit v-on:partial-submit="(e) => mutate().then(e.detail.resolve).catch(e.detail.reject)">
1515
<label class="flex items-center p-5 border rounded relative bg-white" v-if="!cart.value.is_virtual && !cart.value.shipping_addresses?.[0]?.uid">
1616
<span>@lang('Please enter a shipping address first')</span>
1717
</label>

0 commit comments

Comments
 (0)