@dropins/storefront-order 1.2.0-beta1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/graphql/PlaceOrderFragment.graphql.d.ts +18 -0
- package/api/index.d.ts +1 -0
- package/api/setPaymentMethodAndPlaceOrder/graphql/setPaymentMethodAndPlaceOrderMutation.d.ts +18 -0
- package/api/setPaymentMethodAndPlaceOrder/index.d.ts +18 -0
- package/api/setPaymentMethodAndPlaceOrder/setPaymentMethodAndPlaceOrder.d.ts +4 -0
- package/api.js +110 -76
- package/chunks/confirmCancelOrder.js +1 -1
- package/containers/OrderStatus.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* ADOBE CONFIDENTIAL
|
|
3
|
+
* __________________
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2025 Adobe
|
|
6
|
+
* All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* NOTICE: All information contained herein is, and remains
|
|
9
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
10
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
11
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
12
|
+
* property laws, including trade secret and copyright laws.
|
|
13
|
+
* Dissemination of this information or reproduction of this material
|
|
14
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
15
|
+
* from Adobe.
|
|
16
|
+
*******************************************************************/
|
|
17
|
+
export declare const PLACE_ORDER_FRAGMENT: string;
|
|
18
|
+
//# sourceMappingURL=PlaceOrderFragment.graphql.d.ts.map
|
package/api/index.d.ts
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* ADOBE CONFIDENTIAL
|
|
3
|
+
* __________________
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2025 Adobe
|
|
6
|
+
* All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* NOTICE: All information contained herein is, and remains
|
|
9
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
10
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
11
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
12
|
+
* property laws, including trade secret and copyright laws.
|
|
13
|
+
* Dissemination of this information or reproduction of this material
|
|
14
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
15
|
+
* from Adobe.
|
|
16
|
+
*******************************************************************/
|
|
17
|
+
export declare const SET_PAYMENT_METHOD_AND_PLACE_ORDER_MUTATION: string;
|
|
18
|
+
//# sourceMappingURL=setPaymentMethodAndPlaceOrderMutation.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/********************************************************************
|
|
2
|
+
* ADOBE CONFIDENTIAL
|
|
3
|
+
* __________________
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2025 Adobe
|
|
6
|
+
* All Rights Reserved.
|
|
7
|
+
*
|
|
8
|
+
* NOTICE: All information contained herein is, and remains
|
|
9
|
+
* the property of Adobe and its suppliers, if any. The intellectual
|
|
10
|
+
* and technical concepts contained herein are proprietary to Adobe
|
|
11
|
+
* and its suppliers and are protected by all applicable intellectual
|
|
12
|
+
* property laws, including trade secret and copyright laws.
|
|
13
|
+
* Dissemination of this information or reproduction of this material
|
|
14
|
+
* is strictly forbidden unless prior written permission is obtained
|
|
15
|
+
* from Adobe.
|
|
16
|
+
*******************************************************************/
|
|
17
|
+
export * from './setPaymentMethodAndPlaceOrder';
|
|
18
|
+
//# sourceMappingURL=index.d.ts.map
|
package/api.js
CHANGED
|
@@ -1,92 +1,126 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{c as
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import{c as re,r as te}from"./chunks/requestGuestOrderCancel.js";import{f as m,h as T}from"./chunks/fetch-graphql.js";import{g as oe,r as ne,s as se,a as ce,b as ie}from"./chunks/fetch-graphql.js";import{g as de}from"./chunks/getAttributesForm.js";import{g as pe,a as Ee,r as _e}from"./chunks/requestGuestReturn.js";import{g as Te,a as Re}from"./chunks/getGuestOrder.js";import{g as ge}from"./chunks/getCustomerOrdersReturn.js";import{a as f}from"./chunks/initialize.js";import{c as he,g as De,d as Me,i as fe}from"./chunks/initialize.js";import{g as Ce}from"./chunks/getStoreConfig.js";import{h as R}from"./chunks/network-error.js";import{events as d}from"@dropins/tools/event-bus.js";import{ADDRESS_FRAGMENT as G,BUNDLE_ORDER_ITEM_DETAILS_FRAGMENT as C,GIFT_CARD_DETAILS_FRAGMENT as N,ORDER_ITEM_DETAILS_FRAGMENT as x,ORDER_SUMMARY_FRAGMENT as y,PRICE_DETAILS_FRAGMENT as F,PRODUCT_DETAILS_FRAGMENT as I,ORDER_ITEM_FRAGMENT as P,GIFT_WRAPPING_FRAGMENT as b,GIFT_MESSAGE_FRAGMENT as S,APPLIED_GIFT_CARDS_FRAGMENT as v}from"./fragments.js";import{c as xe,a as ye,r as Fe}from"./chunks/confirmCancelOrder.js";import"@dropins/tools/fetch-graphql.js";import"./chunks/transform-attributes-form.js";import"@dropins/tools/lib.js";const A=(r,t)=>r+t.amount.value,L=(r,t)=>({id:r,totalQuantity:t.totalQuantity,possibleOnepageCheckout:!0,items:t.items.map(e=>{var a,o,n,s,c,i,u,l;return{canApplyMsrp:!0,formattedPrice:"",id:e.id,quantity:e.totalQuantity,product:{canonicalUrl:(a=e.product)==null?void 0:a.canonicalUrl,mainImageUrl:((o=e.product)==null?void 0:o.image)??"",name:((n=e.product)==null?void 0:n.name)??"",productId:0,productType:(s=e.product)==null?void 0:s.productType,sku:((c=e.product)==null?void 0:c.sku)??"",topLevelSku:(i=e.product)==null?void 0:i.sku},prices:{price:{value:e.price.value,currency:e.price.currency,regularPrice:((u=e.regularPrice)==null?void 0:u.value)??e.price.value}},configurableOptions:((l=e.selectedOptions)==null?void 0:l.map(p=>({optionLabel:p.label,valueLabel:p.value})))||[]}}),prices:{subtotalExcludingTax:{value:t.subtotalExclTax.value,currency:t.subtotalExclTax.currency},subtotalIncludingTax:{value:t.subtotalInclTax.value,currency:t.subtotalInclTax.currency}},discountAmount:t.discounts.reduce(A,0)}),$=r=>{var a,o,n;const t=r.coupons[0],e=(a=r.payments)==null?void 0:a[0];return{appliedCouponCode:(t==null?void 0:t.code)??"",email:r.email,grandTotal:r.grandTotal.value,orderId:r.number,orderType:"checkout",otherTax:0,salesTax:r.totalTax.value,shipping:{shippingMethod:((o=r.shipping)==null?void 0:o.code)??"",shippingAmount:((n=r.shipping)==null?void 0:n.amount)??0},subtotalExcludingTax:r.subtotalExclTax.value,subtotalIncludingTax:r.subtotalInclTax.value,payments:e?[{paymentMethodCode:(e==null?void 0:e.code)||"",paymentMethodName:(e==null?void 0:e.name)||"",total:r.grandTotal.value,orderId:r.number}]:[],discountAmount:r.discounts.reduce(A,0),taxAmount:r.totalTax.value}},g=r=>{var e,a;const t=(a=(e=r==null?void 0:r.data)==null?void 0:e.placeOrder)==null?void 0:a.orderV2;return t?f(t):null},E={SHOPPING_CART_CONTEXT:"shoppingCartContext",ORDER_CONTEXT:"orderContext"},w={PLACE_ORDER:"place-order"};function O(){return window.adobeDataLayer=window.adobeDataLayer||[],window.adobeDataLayer}function _(r,t){const e=O();e.push({[r]:null}),e.push({[r]:t})}function k(r){O().push(e=>{const a=e.getState?e.getState():{};e.push({event:r,eventInfo:{...a}})})}function h(r,t){const e=$(t),a=L(r,t);_(E.ORDER_CONTEXT,{...e}),_(E.SHOPPING_CART_CONTEXT,{...a}),k(w.PLACE_ORDER)}class U extends Error{constructor(t){super(t),this.name="PlaceOrderError"}}const D=r=>{const t=r.map(e=>e.message).join(" ");throw new U(t)},M=`
|
|
4
|
+
fragment PLACE_ORDER_FRAGMENT on CustomerOrder {
|
|
5
|
+
printed_card_included
|
|
6
|
+
gift_receipt_included
|
|
7
|
+
gift_wrapping {
|
|
8
|
+
...GIFT_WRAPPING_FRAGMENT
|
|
9
|
+
}
|
|
10
|
+
gift_message {
|
|
11
|
+
...GIFT_MESSAGE_FRAGMENT
|
|
12
|
+
}
|
|
13
|
+
applied_gift_cards {
|
|
14
|
+
...APPLIED_GIFT_CARDS_FRAGMENT
|
|
15
|
+
}
|
|
16
|
+
email
|
|
17
|
+
available_actions
|
|
18
|
+
status
|
|
19
|
+
number
|
|
20
|
+
token
|
|
21
|
+
id
|
|
22
|
+
order_date
|
|
23
|
+
carrier
|
|
24
|
+
shipping_method
|
|
25
|
+
is_virtual
|
|
26
|
+
applied_coupons {
|
|
27
|
+
code
|
|
28
|
+
}
|
|
29
|
+
shipments {
|
|
30
|
+
id
|
|
31
|
+
number
|
|
32
|
+
tracking {
|
|
33
|
+
title
|
|
34
|
+
number
|
|
35
|
+
carrier
|
|
36
|
+
}
|
|
37
|
+
comments {
|
|
8
38
|
message
|
|
39
|
+
timestamp
|
|
9
40
|
}
|
|
10
|
-
|
|
11
|
-
printed_card_included
|
|
12
|
-
gift_receipt_included
|
|
13
|
-
gift_wrapping {
|
|
14
|
-
...GIFT_WRAPPING_FRAGMENT
|
|
15
|
-
}
|
|
16
|
-
gift_message {
|
|
17
|
-
...GIFT_MESSAGE_FRAGMENT
|
|
18
|
-
}
|
|
19
|
-
applied_gift_cards {
|
|
20
|
-
...APPLIED_GIFT_CARDS_FRAGMENT
|
|
21
|
-
}
|
|
22
|
-
email
|
|
23
|
-
available_actions
|
|
24
|
-
status
|
|
25
|
-
number
|
|
26
|
-
token
|
|
41
|
+
items {
|
|
27
42
|
id
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
id
|
|
37
|
-
number
|
|
38
|
-
tracking {
|
|
39
|
-
title
|
|
40
|
-
number
|
|
41
|
-
carrier
|
|
42
|
-
}
|
|
43
|
-
comments {
|
|
44
|
-
message
|
|
45
|
-
timestamp
|
|
46
|
-
}
|
|
47
|
-
items {
|
|
48
|
-
id
|
|
49
|
-
product_sku
|
|
50
|
-
product_name
|
|
51
|
-
order_item {
|
|
52
|
-
...ORDER_ITEM_DETAILS_FRAGMENT
|
|
53
|
-
... on GiftCardOrderItem {
|
|
54
|
-
...GIFT_CARD_DETAILS_FRAGMENT
|
|
55
|
-
product {
|
|
56
|
-
...PRODUCT_DETAILS_FRAGMENT
|
|
57
|
-
}
|
|
58
|
-
}
|
|
43
|
+
product_sku
|
|
44
|
+
product_name
|
|
45
|
+
order_item {
|
|
46
|
+
...ORDER_ITEM_DETAILS_FRAGMENT
|
|
47
|
+
... on GiftCardOrderItem {
|
|
48
|
+
...GIFT_CARD_DETAILS_FRAGMENT
|
|
49
|
+
product {
|
|
50
|
+
...PRODUCT_DETAILS_FRAGMENT
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
}
|
|
62
|
-
payment_methods {
|
|
63
|
-
name
|
|
64
|
-
type
|
|
65
|
-
}
|
|
66
|
-
shipping_address {
|
|
67
|
-
...ADDRESS_FRAGMENT
|
|
68
|
-
}
|
|
69
|
-
billing_address {
|
|
70
|
-
...ADDRESS_FRAGMENT
|
|
71
|
-
}
|
|
72
|
-
items {
|
|
73
|
-
...ORDER_ITEM_FRAGMENT
|
|
74
|
-
}
|
|
75
|
-
total {
|
|
76
|
-
...ORDER_SUMMARY_FRAGMENT
|
|
77
|
-
}
|
|
78
54
|
}
|
|
79
55
|
}
|
|
56
|
+
payment_methods {
|
|
57
|
+
name
|
|
58
|
+
type
|
|
59
|
+
}
|
|
60
|
+
shipping_address {
|
|
61
|
+
...ADDRESS_FRAGMENT
|
|
62
|
+
}
|
|
63
|
+
billing_address {
|
|
64
|
+
...ADDRESS_FRAGMENT
|
|
65
|
+
}
|
|
66
|
+
items {
|
|
67
|
+
...ORDER_ITEM_FRAGMENT
|
|
68
|
+
}
|
|
69
|
+
total {
|
|
70
|
+
...ORDER_SUMMARY_FRAGMENT
|
|
71
|
+
}
|
|
80
72
|
}
|
|
81
|
-
|
|
82
|
-
${O}
|
|
73
|
+
|
|
83
74
|
${G}
|
|
84
|
-
${f}
|
|
85
|
-
${x}
|
|
86
|
-
${M}
|
|
87
75
|
${C}
|
|
88
76
|
${N}
|
|
89
|
-
${
|
|
77
|
+
${x}
|
|
78
|
+
${y}
|
|
90
79
|
${F}
|
|
91
80
|
${I}
|
|
92
|
-
|
|
81
|
+
${P}
|
|
82
|
+
${b}
|
|
83
|
+
${S}
|
|
84
|
+
${v}
|
|
85
|
+
`,Q=`
|
|
86
|
+
mutation PLACE_ORDER_MUTATION($cartId: String!) {
|
|
87
|
+
placeOrder(input: { cart_id: $cartId }) {
|
|
88
|
+
errors {
|
|
89
|
+
code
|
|
90
|
+
message
|
|
91
|
+
}
|
|
92
|
+
orderV2 {
|
|
93
|
+
...PLACE_ORDER_FRAGMENT
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
${M}
|
|
99
|
+
`,J=async r=>{if(!r)throw new Error("No cart ID found");return m(Q,{variables:{cartId:r}}).then(t=>{var a,o,n,s,c;(a=t.errors)!=null&&a.length&&T(t.errors),(s=(n=(o=t.data)==null?void 0:o.placeOrder)==null?void 0:n.errors)!=null&&s.length&&D((c=t.data.placeOrder)==null?void 0:c.errors);const e=g(t);return e&&(d.emit("order/placed",e),d.emit("cart/reset",void 0),h(r,e)),e}).catch(R)},H=`
|
|
100
|
+
mutation setPaymentMethodAndPlaceOrder($cartId: String!, $paymentMethod: PaymentMethodInput!) {
|
|
101
|
+
setPaymentMethodOnCart(
|
|
102
|
+
input: {
|
|
103
|
+
cart_id: $cartId
|
|
104
|
+
payment_method: $paymentMethod
|
|
105
|
+
}
|
|
106
|
+
) {
|
|
107
|
+
cart {
|
|
108
|
+
selected_payment_method {
|
|
109
|
+
code
|
|
110
|
+
title
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
placeOrder(input: { cart_id: $cartId }) {
|
|
115
|
+
errors {
|
|
116
|
+
code
|
|
117
|
+
message
|
|
118
|
+
}
|
|
119
|
+
orderV2 {
|
|
120
|
+
...PLACE_ORDER_FRAGMENT
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
${M}
|
|
126
|
+
`,K=async(r,t)=>{if(!r)throw new Error("No cart ID found");if(!t)throw new Error("No payment method found");return m(H,{variables:{cartId:r,paymentMethod:t}}).then(e=>{var o,n,s,c,i,u;(o=e.errors)!=null&&o.length&&T(e.errors),(c=(s=(n=e.data)==null?void 0:n.placeOrder)==null?void 0:s.errors)!=null&&c.length&&D((i=e.data.placeOrder)==null?void 0:i.errors);const a=g({data:{placeOrder:(u=e.data)==null?void 0:u.placeOrder}});return a&&(d.emit("order/placed",a),d.emit("cart/reset",void 0),h(r,a)),a}).catch(R)};export{re as cancelOrder,he as config,xe as confirmCancelOrder,ye as confirmGuestReturn,m as fetchGraphQl,de as getAttributesForm,pe as getAttributesList,oe as getConfig,Te as getCustomer,ge as getCustomerOrdersReturn,Re as getGuestOrder,De as getOrderDetailsById,Ce as getStoreConfig,Me as guestOrderByToken,fe as initialize,J as placeOrder,ne as removeFetchGraphQlHeader,Fe as reorderItems,te as requestGuestOrderCancel,Ee as requestGuestReturn,_e as requestReturn,se as setEndpoint,ce as setFetchGraphQlHeader,ie as setFetchGraphQlHeaders,K as setPaymentMethodAndPlaceOrder};
|
|
@@ -53,4 +53,4 @@ import{h as f}from"./network-error.js";import{f as u,h as _}from"./fetch-graphql
|
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
${O}
|
|
56
|
-
`,y=async(E,t)=>u(h,{variables:{orderId:E,confirmationKey:t}}).then(async({errors:e,data:r})=>{var i,c,m,R;const n=[...(i=r==null?void 0:r.confirmCancelOrder)!=null&&i.errorV2?[(c=r==null?void 0:r.confirmCancelOrder)==null?void 0:c.errorV2]:[],...e??[]];let o=null;return(m=r==null?void 0:r.confirmCancelOrder)!=null&&m.order&&(o=a((R=r==null?void 0:r.confirmCancelOrder)==null?void 0:R.order),T.emit("order/data",o)),n.length>0?_(n):o});export{
|
|
56
|
+
`,y=async(E,t)=>u(h,{variables:{orderId:E,confirmationKey:t}}).then(async({errors:e,data:r})=>{var i,c,m,R;const n=[...(i=r==null?void 0:r.confirmCancelOrder)!=null&&i.errorV2?[(c=r==null?void 0:r.confirmCancelOrder)==null?void 0:c.errorV2]:[],...e??[]];let o=null;return(m=r==null?void 0:r.confirmCancelOrder)!=null&&m.order&&(o=a((R=r==null?void 0:r.confirmCancelOrder)==null?void 0:R.order),T.emit("order/data",o)),n.length>0?_(n):o});export{G as a,y as c,$ as r};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as s,Fragment as S,jsxs as A}from"@dropins/tools/preact-jsx-runtime.js";import{Slot as $,classes as _}from"@dropins/tools/lib.js";import{Button as P,InLineAlert as B,Modal as V,Card as K,Header as Q}from"@dropins/tools/components.js";import{useState as C,useEffect as k,useCallback as T}from"@dropins/tools/preact-hooks.js";import"../chunks/ShippingStatusCard.js";import{useMemo as J}from"@dropins/tools/preact-compat.js";import{u as G}from"../chunks/useGetStoreConfig.js";import"@dropins/tools/preact.js";import{events as I}from"@dropins/tools/event-bus.js";import{
|
|
3
|
+
import{jsx as s,Fragment as S,jsxs as A}from"@dropins/tools/preact-jsx-runtime.js";import{Slot as $,classes as _}from"@dropins/tools/lib.js";import{Button as P,InLineAlert as B,Modal as V,Card as K,Header as Q}from"@dropins/tools/components.js";import{useState as C,useEffect as k,useCallback as T}from"@dropins/tools/preact-hooks.js";import"../chunks/ShippingStatusCard.js";import{useMemo as J}from"@dropins/tools/preact-compat.js";import{u as G}from"../chunks/useGetStoreConfig.js";import"@dropins/tools/preact.js";import{events as I}from"@dropins/tools/event-bus.js";import{c as X,a as Y,r as Z}from"../chunks/confirmCancelOrder.js";import{useText as O,Text as M}from"@dropins/tools/i18n.js";import{C as D}from"../chunks/OrderLoaders.js";import{f as ee}from"../chunks/returnOrdersHelper.js";import{f as w}from"../chunks/formatDateToLocale.js";import{c as b}from"../chunks/capitalizeFirst.js";import{r as U}from"../chunks/redirectTo.js";import{O as te}from"../chunks/OrderCancelForm.js";import"../chunks/getStoreConfig.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/network-error.js";import"../fragments.js";import"../chunks/initialize.js";import"../chunks/getFormValues.js";import"../chunks/requestGuestOrderCancel.js";var y=(t=>(t.CANCEL="CANCEL",t.RETURN="RETURN",t.REORDER="REORDER",t))(y||{});const re=({className:t,orderData:e,slots:n,routeCreateReturn:r,routeOnSuccess:u,onError:i})=>{const d=O({cancel:"Order.OrderStatusContent.actions.cancel",createReturn:"Order.OrderStatusContent.actions.createReturn",createAnotherReturn:"Order.OrderStatusContent.actions.createAnotherReturn",reorder:"Order.OrderStatusContent.actions.reorder"}),l=J(()=>{const c=e==null?void 0:e.availableActions,o=!!(c!=null&&c.length),a=!!(e!=null&&e.returnNumber),m=()=>{U(r,{},e)};return s(S,{children:n!=null&&n.OrderActions?s($,{"data-testid":"OrderActionsSlot",name:"OrderCanceledActions",slot:n==null?void 0:n.OrderActions,context:e}):s("div",{"data-testid":"availableActionsList",className:_(["order-order-actions__wrapper",["order-order-actions__wrapper--empty",!o]]),children:c==null?void 0:c.map(p=>{switch(p){case y.CANCEL:return s(S,{children:a?null:s(ce,{orderRef:(e==null?void 0:e.token)||(e==null?void 0:e.id)})});case y.RETURN:return s(P,{variant:"secondary",onClick:m,children:a?d.createAnotherReturn:d.createReturn});case y.REORDER:return s(S,{children:a?null:s(ie,{orderData:e,onError:i,routeOnSuccess:u,children:d.reorder})})}})})})},[i,e,u,r,n,d]);return s("div",{className:_(["order-order-actions",t]),children:l})},ne=({orderData:t})=>{const[e,n]=C(t),[r,u]=C(t==null?void 0:t.status);return k(()=>{const i=I.on("order/data",d=>{n(d),u(d.status)},{eager:!0});return()=>{i==null||i.off()}},[]),{orderStatus:r,order:e}},H=t=>{const e=new URL(window.location.href);t.forEach(n=>{e.searchParams.has(n)&&e.searchParams.delete(n)}),window.history.replaceState({},document.title,e.toString())},se=({enableOrderCancellation:t})=>{const e=O({cancelOrderHeading:"Order.OrderStatusContent.actions.cancel",confirmGuestReturnHeading:"Order.OrderStatusContent.actions.confirmGuestReturn",orderCancelled:"Order.OrderStatusContent.orderCanceled.message",guestRequestReturnMessage:"Order.OrderStatusContent.actions.confirmGuestReturnMessage"}),[n,r]=C(!1),[u,i]=C(!1),[d,l]=C({heading:"",text:"",status:void 0}),c=T(()=>{r(!0),H(["order_id","confirmation_key","action"])},[]),o=T((a,m,p)=>{l({heading:a,text:m,status:p}),H(["action"])},[]);return k(()=>{const a=new URLSearchParams(window.location.search),m=a.get("order_id")??"",p=a.get("confirmation_key")??"",g=a.get("action")??"";u||!m||!p||!g||(t&&g==="cancel"&&(i(!0),X(m,p).then(()=>{l({heading:e.cancelOrderHeading,text:e.orderCancelled,status:"success"})}).catch(h=>{l({heading:e.cancelOrderHeading,text:h.message,status:"warning"})})),g==="return"&&(i(!0),Y(m,p).then(()=>{l({heading:e.confirmGuestReturnHeading,text:e.guestRequestReturnMessage,status:"success"})}).catch(h=>{l({heading:e.confirmGuestReturnHeading,text:h.message,status:"warning"})})))},[t,e,o,u]),{orderActionStatus:d,isDismissed:n,onDismiss:c}},be=({slots:t,orderData:e,className:n,statusTitle:r,status:u,routeCreateReturn:i,onError:d,routeOnSuccess:l})=>{const{orderStatus:c,order:o}=ne({orderData:e}),a=G(),{orderActionStatus:m,isDismissed:p,onDismiss:g}=se({enableOrderCancellation:a==null?void 0:a.orderCancellationEnabled});return A("div",{className:_(["order-order-status",n]),children:[!p&&(m==null?void 0:m.status)!==void 0?s(B,{style:{marginBottom:"1rem"},heading:m.heading,onDismiss:g,description:m.text,type:m.status}):null,o?s(oe,{title:r,status:u||c,slots:t,orderData:o,routeCreateReturn:i,onError:d,routeOnSuccess:l}):s(D,{withCard:!1})]})},ce=({orderRef:t})=>{const[e,n]=C(!1),r=()=>{n(!0)},u=()=>{n(!1)},i=G(),d=(i==null?void 0:i.orderCancellationReasons)??[],l=c=>c.map((o,a)=>({text:o==null?void 0:o.description,value:a.toString()}));return I.on("order/data",c=>{const o=String(c.status).toLocaleLowerCase();(o==="guest order cancellation requested"||o==="canceled")&&u()}),A(S,{children:[s(P,{variant:"secondary",onClick:r,"data-testid":"cancel-button",children:s(M,{id:"Order.OrderStatusContent.actions.cancel"})}),e&&s(V,{centered:!0,size:"medium",onClose:u,className:"order-order-cancel__modal",title:s("h2",{className:"order-order-cancel__title",children:s(M,{id:"Order.OrderCancelForm.title"})}),"data-testid":"order-cancellation-reasons-modal",children:s(te,{orderRef:t,cancelReasons:l(d)})})]})},N={pending:"orderPending",shiping:"orderShipped",complete:"orderComplete",processing:"orderProcessing","on hold":"orderOnHold",canceled:"orderCanceled","suspected fraud":"orderSuspectedFraud","payment Review":"orderPaymentReview","order received":"orderReceived","guest order cancellation requested":"guestOrderCancellationRequested","pending payment":"orderPendingPayment",rejected:"orderRejected",authorized:"orderAuthorized","paypal canceled reversal":"orderPaypalCanceledReversal","pending paypal":"orderPendingPaypal","paypal reversed":"orderPaypalReversed",closed:"orderClosed"},oe=({slots:t,title:e,status:n,orderData:r,routeCreateReturn:u,onError:i,routeOnSuccess:d})=>{var x,E,L;const l=!!(r!=null&&r.returnNumber),c=String(n).toLocaleLowerCase(),o=(x=r==null?void 0:r.returns)==null?void 0:x[0],a=(o==null?void 0:o.returnStatus)??"",m=(o==null?void 0:o.createdReturnAt)??"",p=O({message:"Order.OrderStatusContent.orderPlaceholder.message",messageWithoutDate:"Order.OrderStatusContent.orderPlaceholder.messageWithoutDate"}),g=O(`Order.OrderStatusContent.${N[c]}.title`),h=O(`Order.OrderStatusContent.${N[c]}.message`),R=O(`Order.OrderStatusContent.${N[c]}.messageWithoutDate`),f=O({title:`Order.OrderStatusContent.returnStatus.${ee(a)}`,returnMessage:"Order.OrderStatusContent.returnMessage"});if(!n)return s("div",{});const q=g!=null&&g.title?g:{title:b(c)},v=h!=null&&h.message?h:p,F=R!=null&&R.messageWithoutDate?R:p,W=r!=null&&r.orderStatusChangeDate?v==null?void 0:v.message.replace("{DATE}",w(r==null?void 0:r.orderStatusChangeDate)):F.messageWithoutDate,j=((L=(E=f==null?void 0:f.returnMessage)==null?void 0:E.replace("{ORDER_CREATE_DATE}",w(r==null?void 0:r.orderDate)))==null?void 0:L.replace("{RETURN_CREATE_DATE}",w(m)))??"",z=l?e??(f.title||b(a)):e??q.title;return A(K,{className:"order-order-status-content",variant:"secondary",children:[s(Q,{title:z}),A("div",{className:"order-order-status-content__wrapper",children:[s("div",{className:_(["order-order-status-content__wrapper-description",["order-order-status-content__wrapper-description--actions-slot",!!(t!=null&&t.OrderActions)]]),children:s("p",{children:l?j:W})}),s(re,{orderData:r,slots:t,routeCreateReturn:u,routeOnSuccess:d,onError:i})]})]})},ie=({onError:t,routeOnSuccess:e,orderData:n,children:r})=>{const[u,i]=C(!1),d=T(()=>{i(!0);const l=n==null?void 0:n.number;Z(l).then(({success:c,userInputErrors:o})=>{c&&U(e,{}),o.length&&(t==null||t(o))}).catch(c=>{t==null||t(c.message)}).finally(()=>{i(!1)})},[n,e,t]);return s(P,{type:"button",disabled:u,variant:"secondary",className:"order-reorder",onClick:d,children:r})};export{be as OrderStatus,be as default};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/storefront-order", "version": "1.2.0
|
|
1
|
+
{"name": "@dropins/storefront-order", "version": "1.2.0", "@dropins/tools": "~1.2.0", "license": "SEE LICENSE IN LICENSE.md"}
|