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
9 changes: 7 additions & 2 deletions src/components/modules/orders/PartialUpdateForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,15 @@ export default defineComponent({
return this.shippingMethod?.shipping_type
},
shippingPoints(): Address[] {
// TODO: maybe we should fetch shipping points from the API
return this.shippingMethod?.shipping_points || []
return (
this.$accessor.shippingMethods.data.find((method) => method.id === this.shippingMethod?.id)
?.shipping_points ?? []
)
},
},
created() {
this.$accessor.shippingMethods.fetch()
},
methods: {
save() {
this.$emit('save', this.form)
Expand Down
19 changes: 13 additions & 6 deletions src/components/modules/orders/ShippingMethodForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ export default defineComponent({
const prevMethod = this.shippingMethods.find((method) => method.id === prevMethodId)
const newMethod = this.shippingMethods.find((method) => method.id === newMethodId)

// Dont clear form if shipping type is the same
if (newMethod?.shipping_type === prevMethod?.shipping_type) return
// Dont clear form if shipping type is the same and it is not a point
if (
newMethod?.shipping_type === prevMethod?.shipping_type &&
newMethod?.shipping_type !== ShippingType.Point
)
return

if (newMethod?.shipping_type) {
switch (newMethod?.shipping_type) {
Expand Down Expand Up @@ -160,8 +164,8 @@ export default defineComponent({
},
},

created() {
this.$accessor.shippingMethods.fetch()
async created() {
await this.$accessor.shippingMethods.fetch()
const method = this.digital ? this.order.digital_shipping_method! : this.order.shipping_method!

this.form = {
Expand All @@ -172,8 +176,11 @@ export default defineComponent({
: this.order.shipping_place,
}
this.shippingType = method?.shipping_type
// TODO: maybe we should fetch shipping points from the API
this.shippingPoints = (method?.shipping_points as AddressDto[]) || []

this.shippingPoints =
this.$accessor.shippingMethods.data.find(
(method) => method.id === this.form.shipping_method_id,
)?.shipping_points ?? []
},
methods: {
isShippingMethodDisabled(method: ShippingMethod) {
Expand Down