@dropins/storefront-order 0.1.0-alpha10 → 0.1.0-alpha11

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.
Files changed (46) hide show
  1. package/api/getOrderDetailsById/graphql/orderItemsFragment.graphql.d.ts +5 -1
  2. package/api/getStoreConfig/graphql/StoreConfigQuery.d.ts +1 -1
  3. package/api.js +21 -51
  4. package/chunks/OrderLoaders.js +1 -1
  5. package/chunks/convertCase.js +1 -0
  6. package/chunks/fetch-graphql.js +1 -1
  7. package/chunks/getAttributesForm.js +3 -3
  8. package/chunks/getCustomer.js +12 -28
  9. package/chunks/getStoreConfig.js +5 -2
  10. package/chunks/transform-order-details.js +81 -5
  11. package/components/OrderCancelReasonsForm/OrderCancelReasonsForm.d.ts +5 -0
  12. package/components/OrderCancelReasonsForm/index.d.ts +3 -0
  13. package/components/OrderLoaders/OrderLoaders.d.ts +1 -0
  14. package/components/OrderProductListContent/CartSummaryItem.d.ts +5 -0
  15. package/components/OrderProductListContent/OrderProductListContent.d.ts +5 -0
  16. package/components/OrderProductListContent/index.d.ts +4 -0
  17. package/components/index.d.ts +2 -1
  18. package/configs/mock.config.d.ts +468 -0
  19. package/containers/CustomerDetails.js +1 -1
  20. package/containers/OrderCancel/OrderCancel.d.ts +5 -0
  21. package/containers/OrderCancel.d.ts +3 -0
  22. package/containers/OrderCancel.js +79 -0
  23. package/containers/OrderProductList/OrderProductList.d.ts +5 -0
  24. package/containers/OrderProductList/index.d.ts +3 -0
  25. package/containers/OrderProductList.d.ts +3 -0
  26. package/containers/OrderProductList.js +1 -0
  27. package/containers/OrderSearch.js +1 -1
  28. package/containers/OrderStatus.js +1 -80
  29. package/containers/ShippingStatus.js +1 -1
  30. package/containers/index.d.ts +2 -0
  31. package/data/models/order-details.d.ts +25 -0
  32. package/data/models/store-config.d.ts +1 -0
  33. package/data/transforms/transform-order-details.d.ts +9 -0
  34. package/hooks/containers/useOrderProductList.d.ts +9 -0
  35. package/hooks/index.d.ts +1 -0
  36. package/i18n/en_US.json.d.ts +17 -2
  37. package/lib/setTaxStatus.d.ts +4 -0
  38. package/package.json +1 -1
  39. package/render.js +2 -2
  40. package/types/api/getOrderDetails.types.d.ts +23 -5
  41. package/types/index.d.ts +1 -0
  42. package/types/orderCancel.types.d.ts +8 -4
  43. package/types/orderProductList.types.d.ts +30 -0
  44. package/components/OrderCancel/OrderCancel.d.ts +0 -5
  45. /package/chunks/{CustomerDetailsContent.js → OrderCancelReasonsForm.js} +0 -0
  46. /package/{components → containers}/OrderCancel/index.d.ts +0 -0
@@ -921,4 +921,472 @@ export declare const storyBookNormalizeAddress: {
921
921
  label: null;
922
922
  }[])[];
923
923
  };
924
+ export declare const orderMockOrderProductItemsList: {
925
+ items: ({
926
+ type: string;
927
+ productName: string;
928
+ quantityCanceled: number;
929
+ quantityInvoiced: number;
930
+ quantityOrdered: number;
931
+ quantityRefunded: number;
932
+ quantityReturned: number;
933
+ quantityShipped: number;
934
+ id: string;
935
+ discounted: boolean;
936
+ total: {
937
+ value: number;
938
+ currency: string;
939
+ };
940
+ totalInclTax: {
941
+ value: number;
942
+ currency: string;
943
+ };
944
+ price: {
945
+ value: number;
946
+ currency: string;
947
+ };
948
+ priceInclTax: {
949
+ value: number;
950
+ currency: string;
951
+ };
952
+ totalQuantity: number;
953
+ regularPrice: {
954
+ value: number;
955
+ currency: string;
956
+ };
957
+ product: {
958
+ __typename: string;
959
+ canonicalUrl: string;
960
+ uid: string;
961
+ name: string;
962
+ sku: string;
963
+ onlyXLeftInStock: null;
964
+ stockStatus: string;
965
+ thumbnail: {
966
+ label: string;
967
+ url: string;
968
+ };
969
+ priceRange: {
970
+ maximumPrice: {
971
+ regularPrice: {
972
+ currency: string;
973
+ value: number;
974
+ };
975
+ };
976
+ };
977
+ id: string;
978
+ image: string;
979
+ productType: string;
980
+ };
981
+ thumbnail: {
982
+ label: string;
983
+ url: string;
984
+ };
985
+ configurableOptions: {
986
+ Color?: undefined;
987
+ Size?: undefined;
988
+ };
989
+ bundleOptions: null;
990
+ itemPrices: {
991
+ priceIncludingTax: {
992
+ value: number;
993
+ currency: string;
994
+ };
995
+ originalPrice: {
996
+ value: number;
997
+ currency: string;
998
+ };
999
+ originalPriceIncludingTax: {
1000
+ value: number;
1001
+ currency: string;
1002
+ };
1003
+ price: {
1004
+ value: number;
1005
+ currency: string;
1006
+ };
1007
+ discounts?: undefined;
1008
+ };
1009
+ downloadableLinks: {
1010
+ count: number;
1011
+ result: string;
1012
+ };
1013
+ giftCard?: undefined;
1014
+ } | {
1015
+ type: string;
1016
+ productName: string;
1017
+ quantityCanceled: number;
1018
+ quantityInvoiced: number;
1019
+ quantityOrdered: number;
1020
+ quantityRefunded: number;
1021
+ quantityReturned: number;
1022
+ quantityShipped: number;
1023
+ id: string;
1024
+ discounted: boolean;
1025
+ total: {
1026
+ value: number;
1027
+ currency: string;
1028
+ };
1029
+ totalInclTax: {
1030
+ value: number;
1031
+ currency: string;
1032
+ };
1033
+ price: {
1034
+ value: number;
1035
+ currency: string;
1036
+ };
1037
+ priceInclTax: {
1038
+ value: number;
1039
+ currency: string;
1040
+ };
1041
+ totalQuantity: number;
1042
+ regularPrice: {
1043
+ value: number;
1044
+ currency: string;
1045
+ };
1046
+ product: {
1047
+ __typename: string;
1048
+ canonicalUrl: string;
1049
+ uid: string;
1050
+ name: string;
1051
+ sku: string;
1052
+ onlyXLeftInStock: null;
1053
+ stockStatus: string;
1054
+ thumbnail: {
1055
+ label: string;
1056
+ url: string;
1057
+ };
1058
+ priceRange: {
1059
+ maximumPrice: {
1060
+ regularPrice: {
1061
+ currency: string;
1062
+ value: number;
1063
+ };
1064
+ };
1065
+ };
1066
+ id: string;
1067
+ image: string;
1068
+ productType: string;
1069
+ };
1070
+ thumbnail: {
1071
+ label: string;
1072
+ url: string;
1073
+ };
1074
+ configurableOptions: {
1075
+ Color: string;
1076
+ Size: string;
1077
+ };
1078
+ bundleOptions: null;
1079
+ itemPrices: {
1080
+ priceIncludingTax: {
1081
+ value: number;
1082
+ currency: string;
1083
+ };
1084
+ originalPrice: {
1085
+ value: number;
1086
+ currency: string;
1087
+ };
1088
+ originalPriceIncludingTax: {
1089
+ value: number;
1090
+ currency: string;
1091
+ };
1092
+ price: {
1093
+ value: number;
1094
+ currency: string;
1095
+ };
1096
+ discounts: {
1097
+ label: string;
1098
+ amount: {
1099
+ value: number;
1100
+ };
1101
+ }[];
1102
+ };
1103
+ downloadableLinks?: undefined;
1104
+ giftCard?: undefined;
1105
+ } | {
1106
+ type: string;
1107
+ productName: string;
1108
+ quantityCanceled: number;
1109
+ quantityInvoiced: number;
1110
+ quantityOrdered: number;
1111
+ quantityRefunded: number;
1112
+ quantityReturned: number;
1113
+ quantityShipped: number;
1114
+ id: string;
1115
+ discounted: boolean;
1116
+ total: {
1117
+ value: number;
1118
+ currency: string;
1119
+ };
1120
+ totalInclTax: {
1121
+ value: number;
1122
+ currency: string;
1123
+ };
1124
+ price: {
1125
+ value: number;
1126
+ currency: string;
1127
+ };
1128
+ priceInclTax: {
1129
+ value: number;
1130
+ currency: string;
1131
+ };
1132
+ totalQuantity: number;
1133
+ regularPrice: {
1134
+ value: number;
1135
+ currency: string;
1136
+ };
1137
+ product: {
1138
+ __typename: string;
1139
+ canonicalUrl: string;
1140
+ uid: string;
1141
+ name: string;
1142
+ sku: string;
1143
+ onlyXLeftInStock: null;
1144
+ stockStatus: string;
1145
+ thumbnail: {
1146
+ label: string;
1147
+ url: string;
1148
+ };
1149
+ priceRange: {
1150
+ maximumPrice: {
1151
+ regularPrice: {
1152
+ currency: string;
1153
+ value: number;
1154
+ };
1155
+ };
1156
+ };
1157
+ id: string;
1158
+ image: string;
1159
+ productType: string;
1160
+ };
1161
+ thumbnail: {
1162
+ label: string;
1163
+ url: string;
1164
+ };
1165
+ configurableOptions: {
1166
+ Color?: undefined;
1167
+ Size?: undefined;
1168
+ };
1169
+ bundleOptions: null;
1170
+ itemPrices: {
1171
+ priceIncludingTax: {
1172
+ value: number;
1173
+ currency: string;
1174
+ };
1175
+ originalPrice: {
1176
+ value: number;
1177
+ currency: string;
1178
+ };
1179
+ originalPriceIncludingTax: {
1180
+ value: number;
1181
+ currency: string;
1182
+ };
1183
+ price: {
1184
+ value: number;
1185
+ currency: string;
1186
+ };
1187
+ discounts: {
1188
+ label: string;
1189
+ amount: {
1190
+ value: number;
1191
+ };
1192
+ }[];
1193
+ };
1194
+ downloadableLinks?: undefined;
1195
+ giftCard?: undefined;
1196
+ } | {
1197
+ type: string;
1198
+ productName: string;
1199
+ quantityCanceled: number;
1200
+ quantityInvoiced: number;
1201
+ quantityOrdered: number;
1202
+ quantityRefunded: number;
1203
+ quantityReturned: number;
1204
+ quantityShipped: number;
1205
+ id: string;
1206
+ discounted: boolean;
1207
+ total: {
1208
+ value: number;
1209
+ currency: string;
1210
+ };
1211
+ totalInclTax: {
1212
+ value: number;
1213
+ currency: string;
1214
+ };
1215
+ price: {
1216
+ value: number;
1217
+ currency: string;
1218
+ };
1219
+ priceInclTax: {
1220
+ value: number;
1221
+ currency: string;
1222
+ };
1223
+ totalQuantity: number;
1224
+ regularPrice: {
1225
+ value: number;
1226
+ currency: string;
1227
+ };
1228
+ product: {
1229
+ __typename: string;
1230
+ canonicalUrl: string;
1231
+ uid: string;
1232
+ name: string;
1233
+ sku: string;
1234
+ onlyXLeftInStock: null;
1235
+ stockStatus: string;
1236
+ thumbnail: {
1237
+ label: string;
1238
+ url: string;
1239
+ };
1240
+ priceRange: {
1241
+ maximumPrice: {
1242
+ regularPrice: {
1243
+ currency: string;
1244
+ value: number;
1245
+ };
1246
+ };
1247
+ };
1248
+ id: string;
1249
+ image: string;
1250
+ productType: string;
1251
+ };
1252
+ thumbnail: {
1253
+ label: string;
1254
+ url: string;
1255
+ };
1256
+ configurableOptions: {
1257
+ Color?: undefined;
1258
+ Size?: undefined;
1259
+ };
1260
+ bundleOptions: {
1261
+ 'Sprite Foam Yoga Brick': string;
1262
+ 'Sprite Foam Roller': string;
1263
+ 'Sprite Stasis Ball': string;
1264
+ 'Sprite Yoga Strap': string;
1265
+ };
1266
+ itemPrices: {
1267
+ priceIncludingTax: {
1268
+ value: number;
1269
+ currency: string;
1270
+ };
1271
+ originalPrice: {
1272
+ value: number;
1273
+ currency: string;
1274
+ };
1275
+ originalPriceIncludingTax: {
1276
+ value: number;
1277
+ currency: string;
1278
+ };
1279
+ price: {
1280
+ value: number;
1281
+ currency: string;
1282
+ };
1283
+ discounts: {
1284
+ label: string;
1285
+ amount: {
1286
+ value: number;
1287
+ };
1288
+ }[];
1289
+ };
1290
+ downloadableLinks?: undefined;
1291
+ giftCard?: undefined;
1292
+ } | {
1293
+ type: string;
1294
+ productName: string;
1295
+ quantityCanceled: number;
1296
+ quantityInvoiced: number;
1297
+ quantityOrdered: number;
1298
+ quantityRefunded: number;
1299
+ quantityReturned: number;
1300
+ quantityShipped: number;
1301
+ id: string;
1302
+ discounted: boolean;
1303
+ total: {
1304
+ value: number;
1305
+ currency: string;
1306
+ };
1307
+ totalInclTax: {
1308
+ value: number;
1309
+ currency: string;
1310
+ };
1311
+ price: {
1312
+ value: number;
1313
+ currency: string;
1314
+ };
1315
+ priceInclTax: {
1316
+ value: number;
1317
+ currency: string;
1318
+ };
1319
+ totalQuantity: number;
1320
+ regularPrice: {
1321
+ value: number;
1322
+ currency: string;
1323
+ };
1324
+ product: {
1325
+ __typename: string;
1326
+ canonicalUrl: string;
1327
+ uid: string;
1328
+ name: string;
1329
+ sku: string;
1330
+ onlyXLeftInStock: null;
1331
+ stockStatus: string;
1332
+ thumbnail: {
1333
+ label: string;
1334
+ url: string;
1335
+ };
1336
+ priceRange: {
1337
+ maximumPrice: {
1338
+ regularPrice: {
1339
+ currency: string;
1340
+ value: number;
1341
+ };
1342
+ };
1343
+ };
1344
+ id: string;
1345
+ image: string;
1346
+ productType: string;
1347
+ };
1348
+ thumbnail: {
1349
+ label: string;
1350
+ url: string;
1351
+ };
1352
+ giftCard: {
1353
+ senderName: string;
1354
+ senderEmail: string;
1355
+ recipientEmail: string;
1356
+ recipientName: string;
1357
+ message: string;
1358
+ };
1359
+ configurableOptions: {
1360
+ Color?: undefined;
1361
+ Size?: undefined;
1362
+ };
1363
+ bundleOptions: null;
1364
+ itemPrices: {
1365
+ priceIncludingTax: {
1366
+ value: number;
1367
+ currency: string;
1368
+ };
1369
+ originalPrice: {
1370
+ value: number;
1371
+ currency: string;
1372
+ };
1373
+ originalPriceIncludingTax: {
1374
+ value: number;
1375
+ currency: string;
1376
+ };
1377
+ price: {
1378
+ value: number;
1379
+ currency: string;
1380
+ };
1381
+ discounts: {
1382
+ label: string;
1383
+ amount: {
1384
+ value: number;
1385
+ };
1386
+ }[];
1387
+ };
1388
+ downloadableLinks?: undefined;
1389
+ })[];
1390
+ totalQuantity: number;
1391
+ };
924
1392
  //# sourceMappingURL=mock.config.d.ts.map
@@ -1 +1 @@
1
- import{jsx as t,jsxs as u,Fragment as P}from"@dropins/tools/preact-jsx-runtime.js";import{classes as b}from"@dropins/tools/lib.js";import{useMemo as V,useCallback as x,useState as k,useEffect as L}from"@dropins/tools/preact-hooks.js";import{events as Z}from"@dropins/tools/event-bus.js";import{c as R}from"../chunks/fetch-graphql.js";import{g as z}from"../chunks/getAttributesForm.js";import{Card as B,Header as F,Price as $,Icon as q}from"@dropins/tools/components.js";import"../chunks/CustomerDetailsContent.js";import*as m from"@dropins/tools/preact-compat.js";import{D as K}from"../chunks/OrderLoaders.js";import{useText as G}from"@dropins/tools/i18n.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/network-error.js";const I=o=>m.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o},m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),J=o=>m.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o},m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.00718 5H22.1507C22.7047 5 23.1579 5.45323 23.1579 6.00718V7.51794C23.1579 7.51794 1.01007 7.58844 1 7.55823V6.00718C1 5.45323 1.45323 5 2.00718 5Z",stroke:"currentColor",strokeWidth:1}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M23.1579 9.78409V18.3451C23.1579 18.899 22.7047 19.3523 22.1507 19.3523H2.00718C1.45323 19.3523 1 18.899 1 18.3451V9.78409H23.1579Z",stroke:"currentColor",strokeWidth:1}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M3.01465 15.9682H8.40305",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round"}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.6192 17.5897C18.4535 17.5897 19.1299 16.9133 19.1299 16.0789C19.1299 15.2446 18.4535 14.5682 17.6192 14.5682C16.7848 14.5682 16.1084 15.2446 16.1084 16.0789C16.1084 16.9133 16.7848 17.5897 17.6192 17.5897Z",stroke:"currentColor",strokeWidth:1}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8848 17.5897C20.7192 17.5897 21.3956 16.9133 21.3956 16.0789C21.3956 15.2446 20.7192 14.5682 19.8848 14.5682C19.0504 14.5682 18.374 15.2446 18.374 16.0789C18.374 16.9133 19.0504 17.5897 19.8848 17.5897Z",stroke:"currentColor",strokeWidth:1})),Q=({loading:o,order:e,withHeader:a=!0,title:c,paymentIconsMap:s={},normalizeAddress:r})=>{var N,M,E,T,D;const i=G({emailTitle:"Order.CustomerDetails.email.title",shippingAddressTitle:"Order.CustomerDetails.shippingAddress.title",shippingMethodsTitle:"Order.CustomerDetails.shippingMethods.title",billingAddressTitle:"Order.CustomerDetails.billingAddress.title",billingMethodsTitle:"Order.CustomerDetails.billingMethods.title",headerText:"Order.CustomerDetails.headerText",freeShipping:"Order.CustomerDetails.freeShipping"}),p=V(()=>({checkmo:I,card:J,...s}),[s]),_=x(j=>{var w;return(w=r[j])==null?void 0:w.map((f,S)=>t("div",{className:"order-customer-details-content__container-description--row",children:f==null?void 0:f.map((l,W)=>t("p",{children:l.label?`${l.label}: ${Array.isArray(l.value)?l.value.join(" "):l==null?void 0:l.value}`:Array.isArray(l.value)?l.value.join(" "):l==null?void 0:l.value},W))},S))},[r]);if(!e||o)return t(K,{});const d=(e==null?void 0:e.email)??"",h=(N=e==null?void 0:e.shipping)==null?void 0:N.code,n=(M=e==null?void 0:e.shipping)==null?void 0:M.amount,v=(E=e==null?void 0:e.shipping)==null?void 0:E.currency,g=e==null?void 0:e.payments,C=g&&g.length>0,A=C?(T=g[0])==null?void 0:T.name:"",y=C?(D=g[0])==null?void 0:D.code:"",H=C&&A!=="";return u(B,{"data-testid":"order-details",variant:"secondary",className:b(["order-customer-details-content"]),children:[a?t(F,{title:c??i.headerText}):null,u("div",{className:"order-customer-details-content__container",children:[u("div",{className:"order-customer-details-content__container-email",children:[t("div",{className:"order-customer-details-content__container-title",children:i.emailTitle}),t("p",{children:d})]}),u("div",{className:"order-customer-details-content__container-shipping_address",children:[t("div",{className:"order-customer-details-content__container-title",children:i.shippingAddressTitle}),t("div",{className:"order-customer-details-content__container-description",children:_("shippingAddress")})]}),u("div",{className:"order-customer-details-content__container-billing_address",children:[t("div",{className:"order-customer-details-content__container-title",children:i.billingAddressTitle}),t("div",{className:"order-customer-details-content__container-description",children:_("billingAddress")})]}),u("div",{className:"order-customer-details-content__container-shipping_methods",children:[t("div",{className:"order-customer-details-content__container-title",children:i.shippingMethodsTitle}),h?t(P,{children:n?u("p",{"data-testid":"shipping_methods_price",children:[t($,{amount:n,currency:v})," ",h]}):t("p",{"data-testid":"shipping_methods_placeholder",children:i.freeShipping})}):null]}),u("div",{className:"order-customer-details-content__container-billing_methods",children:[t("div",{className:"order-customer-details-content__container-title",children:i.billingMethodsTitle}),H&&u("p",{"data-testid":"billing_methods_description",className:b([["order-customer-details-content__container-billing_methods--icon",!!p[y]]]),children:[t(q,{source:p[y]}),A]})]})]})]})},U=["firstname","lastname","city","company","country_code","region","region_code","region_id","telephone","id","vat_id","postcode","street","street_2","default_shipping","default_billing"],O=o=>{o.sort((s,r)=>s.orderNumber-r.orderNumber);const e=[];let a=[];const c=s=>s.value!==void 0&&s.value!==null&&s.value!=="";for(let s=0;s<o.length;s++){const r=o[s];if(c(r))if(Array.isArray(r.value)){const i=r.value.map(p=>({...r,value:p}));e.push(i)}else e.length<4?(a.push(r),a.length===2&&(e.push(a),a=[])):e.push([r])}return a.length>0&&e.length<4&&e.push(a),e},X=({orderData:o})=>{const[e,a]=k(!0),[c,s]=k(o),[r,i]=k([]);L(()=>{const d=Z.on("order/data",h=>{s(h)},{eager:!0});return()=>{d==null||d.off()}},[]),L(()=>{z("shortRequest").then(d=>{if(d){const h=d.map(({name:n,orderNumber:v,label:g})=>({name:R(n),orderNumber:v,label:U.includes(n)?null:g}));i(h)}}).finally(()=>{a(!1)})},[]);const p=x(d=>{if(!r.length||!c||!c[d])return[];const h=Object.fromEntries(Object.entries(c[d]).map(([n,v])=>[n.toLowerCase(),v]));return r.filter(({name:n})=>h[n.toLowerCase()]).map(n=>({name:n.name,orderNumber:n.orderNumber,value:h[n.name.toLowerCase()],label:n.label}))},[r,c]),_=V(()=>({billingAddress:O(p("billingAddress")),shippingAddress:O(p("shippingAddress"))}),[p]);return{order:c,normalizeAddress:_,loading:e}},me=({paymentIconsMap:o,orderData:e,title:a,className:c})=>{const{order:s,normalizeAddress:r,loading:i}=X({orderData:e});return t("div",{className:b(["order-customer-details",c]),children:t(Q,{loading:i,order:s,title:a,paymentIconsMap:o,normalizeAddress:r})})};export{me as CustomerDetails,me as default};
1
+ import{jsx as t,jsxs as u,Fragment as P}from"@dropins/tools/preact-jsx-runtime.js";import{classes as b}from"@dropins/tools/lib.js";import{useMemo as V,useCallback as x,useState as k,useEffect as L}from"@dropins/tools/preact-hooks.js";import{events as Z}from"@dropins/tools/event-bus.js";import{c as R}from"../chunks/convertCase.js";import{g as z}from"../chunks/getAttributesForm.js";import{Card as B,Header as F,Price as $,Icon as q}from"@dropins/tools/components.js";import"../chunks/OrderCancelReasonsForm.js";import*as m from"@dropins/tools/preact-compat.js";import{D as K}from"../chunks/OrderLoaders.js";import"@dropins/tools/preact.js";import{useText as G}from"@dropins/tools/i18n.js";import"../chunks/network-error.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";const I=o=>m.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o},m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.93 14.8V18.75H5.97C4.75 18.75 3.75 17.97 3.75 17V6.5M3.75 6.5C3.75 5.53 4.74 4.75 5.97 4.75H15.94V8.25H5.97C4.75 8.25 3.75 7.47 3.75 6.5Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.35 11.64H14.04V14.81H19.35V11.64Z",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.9304 11.64V8.25H15.1504",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round",strokeLinejoin:"round"})),J=o=>m.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...o},m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M2.00718 5H22.1507C22.7047 5 23.1579 5.45323 23.1579 6.00718V7.51794C23.1579 7.51794 1.01007 7.58844 1 7.55823V6.00718C1 5.45323 1.45323 5 2.00718 5Z",stroke:"currentColor",strokeWidth:1}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M23.1579 9.78409V18.3451C23.1579 18.899 22.7047 19.3523 22.1507 19.3523H2.00718C1.45323 19.3523 1 18.899 1 18.3451V9.78409H23.1579Z",stroke:"currentColor",strokeWidth:1}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M3.01465 15.9682H8.40305",stroke:"currentColor",strokeWidth:1,strokeLinecap:"round"}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M17.6192 17.5897C18.4535 17.5897 19.1299 16.9133 19.1299 16.0789C19.1299 15.2446 18.4535 14.5682 17.6192 14.5682C16.7848 14.5682 16.1084 15.2446 16.1084 16.0789C16.1084 16.9133 16.7848 17.5897 17.6192 17.5897Z",stroke:"currentColor",strokeWidth:1}),m.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M19.8848 17.5897C20.7192 17.5897 21.3956 16.9133 21.3956 16.0789C21.3956 15.2446 20.7192 14.5682 19.8848 14.5682C19.0504 14.5682 18.374 15.2446 18.374 16.0789C18.374 16.9133 19.0504 17.5897 19.8848 17.5897Z",stroke:"currentColor",strokeWidth:1})),Q=({loading:o,order:e,withHeader:a=!0,title:c,paymentIconsMap:s={},normalizeAddress:r})=>{var N,M,E,T,D;const i=G({emailTitle:"Order.CustomerDetails.email.title",shippingAddressTitle:"Order.CustomerDetails.shippingAddress.title",shippingMethodsTitle:"Order.CustomerDetails.shippingMethods.title",billingAddressTitle:"Order.CustomerDetails.billingAddress.title",billingMethodsTitle:"Order.CustomerDetails.billingMethods.title",headerText:"Order.CustomerDetails.headerText",freeShipping:"Order.CustomerDetails.freeShipping"}),p=V(()=>({checkmo:I,card:J,...s}),[s]),_=x(j=>{var w;return(w=r[j])==null?void 0:w.map((f,S)=>t("div",{className:"order-customer-details-content__container-description--row",children:f==null?void 0:f.map((l,W)=>t("p",{children:l.label?`${l.label}: ${Array.isArray(l.value)?l.value.join(" "):l==null?void 0:l.value}`:Array.isArray(l.value)?l.value.join(" "):l==null?void 0:l.value},W))},S))},[r]);if(!e||o)return t(K,{});const d=(e==null?void 0:e.email)??"",h=(N=e==null?void 0:e.shipping)==null?void 0:N.code,n=(M=e==null?void 0:e.shipping)==null?void 0:M.amount,v=(E=e==null?void 0:e.shipping)==null?void 0:E.currency,g=e==null?void 0:e.payments,C=g&&g.length>0,A=C?(T=g[0])==null?void 0:T.name:"",y=C?(D=g[0])==null?void 0:D.code:"",H=C&&A!=="";return u(B,{"data-testid":"order-details",variant:"secondary",className:b(["order-customer-details-content"]),children:[a?t(F,{title:c??i.headerText}):null,u("div",{className:"order-customer-details-content__container",children:[u("div",{className:"order-customer-details-content__container-email",children:[t("div",{className:"order-customer-details-content__container-title",children:i.emailTitle}),t("p",{children:d})]}),u("div",{className:"order-customer-details-content__container-shipping_address",children:[t("div",{className:"order-customer-details-content__container-title",children:i.shippingAddressTitle}),t("div",{className:"order-customer-details-content__container-description",children:_("shippingAddress")})]}),u("div",{className:"order-customer-details-content__container-billing_address",children:[t("div",{className:"order-customer-details-content__container-title",children:i.billingAddressTitle}),t("div",{className:"order-customer-details-content__container-description",children:_("billingAddress")})]}),u("div",{className:"order-customer-details-content__container-shipping_methods",children:[t("div",{className:"order-customer-details-content__container-title",children:i.shippingMethodsTitle}),h?t(P,{children:n?u("p",{"data-testid":"shipping_methods_price",children:[t($,{amount:n,currency:v})," ",h]}):t("p",{"data-testid":"shipping_methods_placeholder",children:i.freeShipping})}):null]}),u("div",{className:"order-customer-details-content__container-billing_methods",children:[t("div",{className:"order-customer-details-content__container-title",children:i.billingMethodsTitle}),H&&u("p",{"data-testid":"billing_methods_description",className:b([["order-customer-details-content__container-billing_methods--icon",!!p[y]]]),children:[t(q,{source:p[y]}),A]})]})]})]})},U=["firstname","lastname","city","company","country_code","region","region_code","region_id","telephone","id","vat_id","postcode","street","street_2","default_shipping","default_billing"],O=o=>{o.sort((s,r)=>s.orderNumber-r.orderNumber);const e=[];let a=[];const c=s=>s.value!==void 0&&s.value!==null&&s.value!=="";for(let s=0;s<o.length;s++){const r=o[s];if(c(r))if(Array.isArray(r.value)){const i=r.value.map(p=>({...r,value:p}));e.push(i)}else e.length<4?(a.push(r),a.length===2&&(e.push(a),a=[])):e.push([r])}return a.length>0&&e.length<4&&e.push(a),e},X=({orderData:o})=>{const[e,a]=k(!0),[c,s]=k(o),[r,i]=k([]);L(()=>{const d=Z.on("order/data",h=>{s(h)},{eager:!0});return()=>{d==null||d.off()}},[]),L(()=>{z("shortRequest").then(d=>{if(d){const h=d.map(({name:n,orderNumber:v,label:g})=>({name:R(n),orderNumber:v,label:U.includes(n)?null:g}));i(h)}}).finally(()=>{a(!1)})},[]);const p=x(d=>{if(!r.length||!c||!c[d])return[];const h=Object.fromEntries(Object.entries(c[d]).map(([n,v])=>[n.toLowerCase(),v]));return r.filter(({name:n})=>h[n.toLowerCase()]).map(n=>({name:n.name,orderNumber:n.orderNumber,value:h[n.name.toLowerCase()],label:n.label}))},[r,c]),_=V(()=>({billingAddress:O(p("billingAddress")),shippingAddress:O(p("shippingAddress"))}),[p]);return{order:c,normalizeAddress:_,loading:e}},ue=({paymentIconsMap:o,orderData:e,title:a,className:c})=>{const{order:s,normalizeAddress:r,loading:i}=X({orderData:e});return t("div",{className:b(["order-customer-details",c]),children:t(Q,{loading:i,order:s,title:a,paymentIconsMap:o,normalizeAddress:r})})};export{ue as CustomerDetails,ue as default};
@@ -0,0 +1,5 @@
1
+ import { OrderCancelProps } from '../../types';
2
+ import { Container } from '@dropins/tools/types/elsie/src/lib';
3
+
4
+ export declare const OrderCancel: Container<OrderCancelProps>;
5
+ //# sourceMappingURL=OrderCancel.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './OrderCancel/index'
2
+ import _default from './OrderCancel/index'
3
+ export default _default
@@ -0,0 +1,79 @@
1
+ import{jsx as o,Fragment as p,jsxs as R}from"@dropins/tools/preact-jsx-runtime.js";import{P as m,O as b,A as E,t as D}from"../chunks/transform-order-details.js";import{f as v,h as A}from"../chunks/fetch-graphql.js";import{useState as l,useEffect as I}from"@dropins/tools/preact-hooks.js";import{g as N}from"../chunks/getStoreConfig.js";import{InLineAlert as F,Picker as x,Button as y}from"@dropins/tools/components.js";import{F as L}from"../chunks/OrderCancelReasonsForm.js";import"@dropins/tools/lib.js";import"@dropins/tools/preact-compat.js";import"@dropins/tools/preact.js";import{events as u}from"@dropins/tools/event-bus.js";import{useText as $,Text as f}from"@dropins/tools/i18n.js";import"../chunks/convertCase.js";import"@dropins/tools/fetch-graphql.js";const T=({pickerProps:a,submitButtonProps:e,cancelReasons:r,cancelOrder:s,orderId:t})=>{const n=$({ErrorHeading:"Order.OrderCancellationReasonsForm.errorHeading",ErrorDescription:"Order.OrderCancellationReasonsForm.errorDescription",orderCancellationLabel:"Order.OrderCancellationReasonsForm.label"}),[i,g]=l(0),[_,O]=l(!1),[C,h]=l(!1);u.on("authenticated",d=>{d&&h(!0)},{eager:!0});const S=d=>{d.preventDefault();const c=Number(d.target.value);g(c)};return o(p,{children:R(L,{onSubmit:async d=>(d.preventDefault(),s(t,r[i].text,c=>{C||(c.status="guest order cancellation requested"),u.emit("order/data",c)},()=>{O(!0)})),"data-testid":"order-order-cancel-reasons-form__text",children:[_&&o(F,{heading:n.ErrorHeading,description:n.ErrorDescription}),o("div",{className:"order-order-cancel-reasons-form__text",children:o(f,{id:"Order.OrderCancellationReasonsForm.description"})}),o(x,{name:"cancellationReasons",floatingLabel:n.orderCancellationLabel,defaultOption:r[0],variant:"primary",options:r,value:String(i),handleSelect:S,required:!0,"data-testid":"order-cancellation-reasons-selector",...a}),o("div",{className:"order-order-cancel-reasons-form__button-container",children:o(y,{variant:"primary",...e,children:o(f,{id:"Order.OrderCancellationReasonsForm.button"})})})]})})},w=`
2
+ mutation CANCEL_ORDER_MUTATION($orderId: ID!, $reason: String!) {
3
+ cancelOrder(input: { order_id: $orderId, reason: $reason }) {
4
+ error
5
+ order {
6
+ email
7
+ available_actions
8
+ status
9
+ number
10
+ id
11
+ order_date
12
+ carrier
13
+ shipping_method
14
+ is_virtual
15
+ applied_coupons {
16
+ code
17
+ }
18
+ shipments {
19
+ id
20
+ number
21
+ tracking {
22
+ title
23
+ number
24
+ carrier
25
+ }
26
+ comments {
27
+ message
28
+ timestamp
29
+ }
30
+ items {
31
+ id
32
+ product_sku
33
+ product_name
34
+ order_item {
35
+ ${m}
36
+ ... on GiftCardOrderItem {
37
+ gift_card {
38
+ recipient_name
39
+ recipient_email
40
+ sender_name
41
+ sender_email
42
+ message
43
+ }
44
+ }
45
+ }
46
+ }
47
+ }
48
+ payment_methods {
49
+ name
50
+ type
51
+ }
52
+ shipping_address {
53
+ ...AddressesList
54
+ }
55
+ billing_address {
56
+ ...AddressesList
57
+ }
58
+ items {
59
+ ${m}
60
+ ... on GiftCardOrderItem {
61
+ __typename
62
+ gift_card {
63
+ recipient_name
64
+ recipient_email
65
+ sender_name
66
+ sender_email
67
+ message
68
+ }
69
+ }
70
+ }
71
+ total {
72
+ ...OrderSummary
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ${b}
78
+ ${E}
79
+ `,G=async(a,e,r,s)=>{if(!a)throw new Error("No order ID found");if(!e)throw new Error("No reason found");return v(w,{variables:{orderId:a,reason:e}}).then(({errors:t,data:n})=>{if(t)return A(t);if(n.cancelOrder.error!=null){s();return}const i=D(n.cancelOrder.order);r(i)})},M=()=>{const[a,e]=l(null);return I(()=>{const r=sessionStorage.getItem("orderStoreConfig"),s=r?JSON.parse(r):null;s?e(s):N().then(t=>{t&&(sessionStorage.setItem("orderStoreConfig",JSON.stringify(t)),e(t))})},[]),a},Z=({orderId:a})=>{const e=M(),r=(e==null?void 0:e.orderCancellationReasons)??[];return o(p,{children:o(T,{orderId:a,cancelOrder:G,cancelReasons:(t=>t.map((n,i)=>({text:n==null?void 0:n.description,value:i.toString()})))(r)})})};export{Z as OrderCancel,Z as default};
@@ -0,0 +1,5 @@
1
+ import { OrderProductListProps } from '../../types';
2
+ import { Container } from '@dropins/tools/types/elsie/src/lib';
3
+
4
+ export declare const OrderProductList: Container<OrderProductListProps>;
5
+ //# sourceMappingURL=OrderProductList.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './OrderProductList';
2
+ export { OrderProductList as default } from './OrderProductList';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ export * from './OrderProductList/index'
2
+ import _default from './OrderProductList/index'
3
+ export default _default
@@ -0,0 +1 @@
1
+ import{jsx as i,jsxs as k,Fragment as E}from"@dropins/tools/preact-jsx-runtime.js";import{Card as Z,Header as j,Price as W,CartItem as z,Icon as B,Image as K}from"@dropins/tools/components.js";import"../chunks/OrderCancelReasonsForm.js";import{classes as q}from"@dropins/tools/lib.js";import*as L from"@dropins/tools/preact-compat.js";import{useMemo as R,useCallback as A,useState as b,useEffect as P}from"@dropins/tools/preact-hooks.js";import{Fragment as J}from"@dropins/tools/preact.js";import{O as U}from"../chunks/OrderLoaders.js";import{events as X}from"@dropins/tools/event-bus.js";import{useText as Y}from"@dropins/tools/i18n.js";import{g}from"../chunks/getStoreConfig.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";const I=d=>L.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...d},L.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M0.75 12C0.75 5.78421 5.78421 0.75 12 0.75C18.2158 0.75 23.25 5.78421 23.25 12C23.25 18.2158 18.2158 23.25 12 23.25C5.78421 23.25 0.75 18.2158 0.75 12Z",stroke:"currentColor"}),L.createElement("path",{vectorEffect:"non-scaling-stroke",d:"M11.75 5.88423V4.75H12.25V5.88423L12.0485 13.0713H11.9515L11.75 5.88423ZM11.7994 18.25V16.9868H12.2253V18.25H11.7994Z",stroke:"currentColor"})),T=({loading:d,taxConfig:e,order:r=null,withHeader:h=!0,showConfigurableOptions:m})=>{const o=Y({cancelled:"Order.OrderProductListContent.cancelledTitle",allOrders:"Order.OrderProductListContent.allOrdersTitle",sender:"Order.OrderProductListContent.GiftCard.sender",recipient:"Order.OrderProductListContent.GiftCard.recipient",message:"Order.OrderProductListContent.GiftCard.message",outOfStock:"Order.OrderProductListContent.stockStatus.outOfStock",downloadableCount:"Order.OrderProductListContent.downloadableCount"}),c=R(()=>{if(!r)return[];const{items:a}=r;return[{type:"cancelled",list:a.filter(s=>s.quantityCanceled),title:o.cancelled},{type:"",list:a.filter(s=>!s.quantityCanceled),title:o.allOrders}]},[r,o]);return r?i(Z,{variant:"secondary",className:"order-order-product-list-content",children:c.filter(a=>a.list.length).map((a,s)=>{var f;return k(J,{children:[h?i(j,{title:`${a.title} (${a.list.length})`}):null,i("ul",{className:"order-order-product-list-content__items",children:(f=a.list)==null?void 0:f.map(O=>i("li",{"data-testid":"order-product-list-content-item",children:i(p,{loading:d,product:O,itemType:a.type,taxConfig:e,translations:o,showConfigurableOptions:m})},O.id))})]},s)})}):i(U,{})},p=({loading:d,product:e,itemType:r,taxConfig:h,translations:m,showConfigurableOptions:o})=>{var S,x,C,N,Q,_,H,V,$,M;const{taxExcluded:c,taxIncluded:a}=h,s=A((v,F,G)=>i(W,{amount:v,currency:F,weight:"normal",...G}),[]);let f={};const O=r==="cancelled",D=(x=(S=e==null?void 0:e.product)==null?void 0:S.stockStatus)==null?void 0:x.includes("IN_STOCK"),t=(e==null?void 0:e.giftCard)||{},l=(C=e==null?void 0:e.itemPrices)==null?void 0:C.priceIncludingTax,n=(N=e==null?void 0:e.itemPrices)==null?void 0:N.originalPrice,u=(Q=e==null?void 0:e.itemPrices)==null?void 0:Q.price,y=e.discounted&&((_=e.price)==null?void 0:_.value)!==(n==null?void 0:n.value)*(e==null?void 0:e.totalQuantity),w={..."configurableOptions"in e?e.configurableOptions:{},..."bundleOptions"in e?e.bundleOptions:{},..."senderName"in t&&(t!=null&&t.senderName)?{[m.sender]:t==null?void 0:t.senderName}:{},..."senderEmail"in t&&(t!=null&&t.senderEmail)?{[m.sender]:t==null?void 0:t.senderEmail}:{},..."recipientName"in t&&(t!=null&&t.recipientName)?{[m.recipient]:t==null?void 0:t.recipientName}:{},..."recipientEmail"in t&&(t!=null&&t.recipientEmail)?{[m.recipient]:t==null?void 0:t.recipientEmail}:{},..."message"in t&&(t!=null&&t.message)?{[m.message]:t==null?void 0:t.message}:{},..."downloadableLinks"in e&&(e!=null&&e.downloadableLinks)?{[`${(H=e==null?void 0:e.downloadableLinks)==null?void 0:H.count} ${m.downloadableCount}`]:(V=e==null?void 0:e.downloadableLinks)==null?void 0:V.result}:{}};if(a&&c){const v=y?n==null?void 0:n.value:(l==null?void 0:l.value)*(e==null?void 0:e.totalQuantity);f={taxExcluded:!0,taxIncluded:void 0,price:s(n==null?void 0:n.value,n==null?void 0:n.currency),total:k(E,{children:[s(v,n==null?void 0:n.currency,{variant:e.discounted&&(l==null?void 0:l.value)!==v?"strikethrough":"default"}),e.discounted&&(l==null?void 0:l.value)!==v?s(l==null?void 0:l.value,l==null?void 0:l.currency,{sale:!0,weight:"bold"}):null]}),totalExcludingTax:s((u==null?void 0:u.value)*e.totalQuantity,u==null?void 0:u.currency)}}else if(!a&&c)f={taxExcluded:void 0,taxIncluded:void 0,price:s(n==null?void 0:n.value,n==null?void 0:n.currency),total:k(E,{children:[s((n==null?void 0:n.value)*(e==null?void 0:e.totalQuantity),l==null?void 0:l.currency,{variant:y?"strikethrough":"default"}),y?s(($=e.price)==null?void 0:$.value,(M=e.price)==null?void 0:M.currency,{sale:!0,weight:"bold"}):null]}),totalExcludingTax:s((u==null?void 0:u.value)*(e==null?void 0:e.totalQuantity),u==null?void 0:u.currency)};else if(a&&!c){const v=y?n.value:l.value*e.totalQuantity;f={taxExcluded:void 0,taxIncluded:!0,price:s(l==null?void 0:l.value,l==null?void 0:l.currency),total:k(E,{children:[s(v,l==null?void 0:l.currency,{variant:y?"strikethrough":"default",weight:"bold"}),y?s(l==null?void 0:l.value,l==null?void 0:l.currency,{sale:!0,weight:"bold"}):null]})}}return i(z,{loading:d,alert:O&&D?k("span",{children:[i(B,{source:I}),m.outOfStock]}):i(E,{}),configurations:(o==null?void 0:o(w))??w,title:i("div",{"data-testid":"product-name",className:q(["cart-summary-item__title",["cart-summary-item__title--strikethrough",O]]),children:e.product.name}),sku:i("div",{children:e.product.sku}),quantity:e.totalQuantity,image:i(K,{src:e.product.thumbnail.url,alt:e.product.thumbnail.label,loading:"lazy",width:"90",height:"120"}),...f})},ee=d=>{let e=!1,r=!1;switch(d){case 1:r=!0;break;case 2:e=!0;break;case 3:e=!0,r=!0;break;default:e=!1,r=!1}return{taxIncluded:e,taxExcluded:r}},te=({orderData:d})=>{const[e,r]=b(!0),[h,m]=b(d),[o,c]=b({taxIncluded:!1,taxExcluded:!1});return P(()=>{g().then(a=>{a&&c(ee(a==null?void 0:a.shoppingCartDisplayPrice))}).finally(()=>{r(!1)})},[]),P(()=>{const a=X.on("order/data",s=>{m(s)},{eager:!0});return()=>{a==null||a.off()}},[]),{loading:e,taxConfig:o,order:h}},fe=({className:d,orderData:e,withHeader:r,showConfigurableOptions:h})=>{const{loading:m,taxConfig:o,order:c}=te({orderData:e});return i("div",{className:q(["order-order-product-list",d]),children:i(T,{loading:m,taxConfig:o,order:c,withHeader:r,showConfigurableOptions:h})})};export{fe as OrderProductList,fe as default};
@@ -1 +1 @@
1
- import{jsxs as v,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{classes as _}from"@dropins/tools/lib.js";import{Card as U,InLineAlert as C,Icon as x,Button as V}from"@dropins/tools/components.js";import{F as L}from"../chunks/CustomerDetailsContent.js";import*as R from"@dropins/tools/preact-compat.js";import{useState as D,useCallback as O,useEffect as g,useMemo as k}from"@dropins/tools/preact-hooks.js";import{events as w}from"@dropins/tools/event-bus.js";import{Text as S,useText as H}from"@dropins/tools/i18n.js";import{g as A,a as P}from"../chunks/getCustomer.js";import"../chunks/network-error.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/transform-order-details.js";const X=e=>R.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},R.createElement("path",{vectorEffect:"non-scaling-stroke",fillRule:"evenodd",clipRule:"evenodd",d:"M1 20.8953L12.1922 1.5L23.395 20.8953H1ZM13.0278 13.9638L13.25 10.0377V9H11.25V10.0377L11.4722 13.9638H13.0278ZM11.2994 16V17.7509H13.2253V16H11.2994Z",fill:"currentColor"})),B=({onSubmit:e,loading:t,inLineAlert:o,fieldsConfig:a})=>v(U,{variant:"secondary",className:"order-order-search-form",children:[s("h2",{className:"order-order-search-form__title",children:s(S,{id:"Order.OrderSearchForm.title"})}),s("p",{children:s(S,{id:"Order.OrderSearchForm.description"})}),o.text?s(C,{"data-testid":"orderAlert",className:"order-order-search-form__alert",type:o.type,variant:"secondary",heading:o.text,icon:s(x,{source:X})}):null,s(L,{className:"order-order-search-form__wrapper",name:"orderSearchForm",loading:t,fieldsConfig:a,onSubmit:e,children:s("div",{className:"order-order-search-form__button-container",children:s(V,{className:"order-order-search-form__button",size:"medium",variant:"primary",type:"submit",disabled:t,children:s(S,{id:"Order.OrderSearchForm.button"})},"logIn")})})]});var T=(e=>(e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.DATETIME="DATETIME",e.DROPDOWN="DROPDOWN",e.FILE="FILE",e.GALLERY="GALLERY",e.HIDDEN="HIDDEN",e.IMAGE="IMAGE",e.MEDIA_IMAGE="MEDIA_IMAGE",e.MULTILINE="MULTILINE",e.MULTISELECT="MULTISELECT",e.PRICE="PRICE",e.SELECT="SELECT",e.TEXT="TEXT",e.TEXTAREA="TEXTAREA",e.UNDEFINED="UNDEFINED",e.VISUAL="VISUAL",e.WEIGHT="WEIGHT",e.EMPTY="",e))(T||{});const j=e=>{if(!e)return null;const t=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(a=>{t.has(a.name)||t.set(a.name,"false"),a.checked&&t.set(a.name,"true")}),t&&typeof t.entries=="function"){const a=t.entries();if(a&&typeof a[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(a)))||{}}return{}},p=(e,t)=>{if(typeof e!="function")return;const o=e();if(!t||Object.keys(t).length===0){window.location.href=o;return}const a=new URLSearchParams;Object.entries(t).forEach(([u,d])=>{a.append(u,String(d))});const c=o.includes("?")?"&":"?";window.location.href=`${o}${c}${a.toString()}`},I=e=>{try{return new URL(window.location.href).searchParams.get(e)}catch{return null}},q=({onError:e,isAuth:t,renderSignIn:o,routeCustomerOrder:a,routeGuestOrder:c})=>{const[u,d]=D({text:"",type:"success"}),[E,h]=D(!1),f=H({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),b=O(async r=>{const n=I("orderRef"),l=n&&n.length>20;if(!r&&!n||!(r!=null&&r.number)&&!(r!=null&&r.token)&&!n)return null;if(t){const m=await A();(m==null?void 0:m.email)===r.email?p(a,{orderRef:r==null?void 0:r.number}):l||p(c,{orderRef:r.token})}else l||p(c,{orderRef:r==null?void 0:r.token})},[t,a,c]);g(()=>{const r=w.on("order/data",n=>{b(n)},{eager:!0});return()=>{r==null||r.off()}},[b]),g(()=>{const r=I("orderRef"),n=r&&r.length>20?r:null;r&&(n?p(c,{orderRef:r}):t?p(a,{orderRef:r}):o==null||o({render:!0,formValues:{number:r}}))},[t,a,c,o]);const M=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.email,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.postcode,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:f.number,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[f]);return{onSubmit:O(async(r,n)=>{if(!n)return null;h(!0);const l=j(r.target);await P(l).then(i=>{i||d({text:f.invalidSearch,type:"warning"}),w.emit("order/data",i)}).catch(async i=>{var N;let m=!0;e==null||e({error:i.message});const y=t?await A():{email:""};(y==null?void 0:y.email)===(l==null?void 0:l.email)?(m=!1,p(a,{orderRef:l.number})):m=o==null?void 0:o({render:(N=i==null?void 0:i.message)==null?void 0:N.includes("Please login to view the order."),formValues:l}),m&&d({text:i.message,type:"warning"})}).finally(()=>{h(!1)})},[t,e,o,a,f.invalidSearch]),inLineAlert:u,loading:E,normalizeFieldsConfig:M}},oe=({className:e,isAuth:t,renderSignIn:o,routeCustomerOrder:a,routeGuestOrder:c,onError:u})=>{const{onSubmit:d,loading:E,inLineAlert:h,normalizeFieldsConfig:f}=q({onError:u,isAuth:t,renderSignIn:o,routeCustomerOrder:a,routeGuestOrder:c});return s("div",{className:_(["order-order-search",e]),children:s(B,{onSubmit:d,loading:E,inLineAlert:h,fieldsConfig:f})})};export{oe as OrderSearch,oe as default};
1
+ import{jsxs as v,jsx as s}from"@dropins/tools/preact-jsx-runtime.js";import{classes as _}from"@dropins/tools/lib.js";import{Card as U,InLineAlert as C,Icon as x,Button as V}from"@dropins/tools/components.js";import{F as L}from"../chunks/OrderCancelReasonsForm.js";import*as R from"@dropins/tools/preact-compat.js";import{useState as D,useCallback as O,useEffect as g,useMemo as k}from"@dropins/tools/preact-hooks.js";import"@dropins/tools/preact.js";import{events as w}from"@dropins/tools/event-bus.js";import{Text as S,useText as H}from"@dropins/tools/i18n.js";import{g as A,a as P}from"../chunks/getCustomer.js";import"../chunks/network-error.js";import"../chunks/fetch-graphql.js";import"@dropins/tools/fetch-graphql.js";import"../chunks/transform-order-details.js";import"../chunks/convertCase.js";const X=e=>R.createElement("svg",{width:24,height:24,viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},R.createElement("path",{vectorEffect:"non-scaling-stroke",fillRule:"evenodd",clipRule:"evenodd",d:"M1 20.8953L12.1922 1.5L23.395 20.8953H1ZM13.0278 13.9638L13.25 10.0377V9H11.25V10.0377L11.4722 13.9638H13.0278ZM11.2994 16V17.7509H13.2253V16H11.2994Z",fill:"currentColor"})),B=({onSubmit:e,loading:t,inLineAlert:o,fieldsConfig:a})=>v(U,{variant:"secondary",className:"order-order-search-form",children:[s("h2",{className:"order-order-search-form__title",children:s(S,{id:"Order.OrderSearchForm.title"})}),s("p",{children:s(S,{id:"Order.OrderSearchForm.description"})}),o.text?s(C,{"data-testid":"orderAlert",className:"order-order-search-form__alert",type:o.type,variant:"secondary",heading:o.text,icon:s(x,{source:X})}):null,s(L,{className:"order-order-search-form__wrapper",name:"orderSearchForm",loading:t,fieldsConfig:a,onSubmit:e,children:s("div",{className:"order-order-search-form__button-container",children:s(V,{className:"order-order-search-form__button",size:"medium",variant:"primary",type:"submit",disabled:t,children:s(S,{id:"Order.OrderSearchForm.button"})},"logIn")})})]});var T=(e=>(e.BOOLEAN="BOOLEAN",e.DATE="DATE",e.DATETIME="DATETIME",e.DROPDOWN="DROPDOWN",e.FILE="FILE",e.GALLERY="GALLERY",e.HIDDEN="HIDDEN",e.IMAGE="IMAGE",e.MEDIA_IMAGE="MEDIA_IMAGE",e.MULTILINE="MULTILINE",e.MULTISELECT="MULTISELECT",e.PRICE="PRICE",e.SELECT="SELECT",e.TEXT="TEXT",e.TEXTAREA="TEXTAREA",e.UNDEFINED="UNDEFINED",e.VISUAL="VISUAL",e.WEIGHT="WEIGHT",e.EMPTY="",e))(T||{});const j=e=>{if(!e)return null;const t=new FormData(e);if(e.querySelectorAll('input[type="checkbox"]').forEach(a=>{t.has(a.name)||t.set(a.name,"false"),a.checked&&t.set(a.name,"true")}),t&&typeof t.entries=="function"){const a=t.entries();if(a&&typeof a[Symbol.iterator]=="function")return JSON.parse(JSON.stringify(Object.fromEntries(a)))||{}}return{}},p=(e,t)=>{if(typeof e!="function")return;const o=e();if(!t||Object.keys(t).length===0){window.location.href=o;return}const a=new URLSearchParams;Object.entries(t).forEach(([u,d])=>{a.append(u,String(d))});const c=o.includes("?")?"&":"?";window.location.href=`${o}${c}${a.toString()}`},I=e=>{try{return new URL(window.location.href).searchParams.get(e)}catch{return null}},q=({onError:e,isAuth:t,renderSignIn:o,routeCustomerOrder:a,routeGuestOrder:c})=>{const[u,d]=D({text:"",type:"success"}),[E,h]=D(!1),m=H({invalidSearch:"Order.Errors.invalidSearch",email:"Order.OrderSearchForm.email",postcode:"Order.OrderSearchForm.postcode",number:"Order.OrderSearchForm.orderNumber"}),b=O(async r=>{const n=I("orderRef"),i=n&&n.length>20;if(!r&&!n||!(r!=null&&r.number)&&!(r!=null&&r.token)&&!n)return null;if(t){const f=await A();(f==null?void 0:f.email)===r.email?p(a,{orderRef:r==null?void 0:r.number}):i||p(c,{orderRef:r.token})}else i||p(c,{orderRef:r==null?void 0:r.token})},[t,a,c]);g(()=>{const r=w.on("order/data",n=>{b(n)},{eager:!0});return()=>{r==null||r.off()}},[b]),g(()=>{const r=I("orderRef"),n=r&&r.length>20?r:null;r&&(n?p(c,{orderRef:r}):t?p(a,{orderRef:r}):o==null||o({render:!0,formValues:{number:r}}))},[t,a,c,o]);const M=k(()=>[{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:m.email,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:1,name:"email",id:"email",code:"email"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:m.postcode,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:2,name:"postcode",id:"postcode",code:"postcode"},{entityType:"CUSTOMER_ADDRESS",is_unique:!1,label:m.number,options:[],defaultValue:"",fieldType:T.TEXT,className:"",required:!0,orderNumber:3,name:"number",id:"number",code:"number"}],[m]);return{onSubmit:O(async(r,n)=>{if(!n)return null;h(!0);const i=j(r.target);await P(i).then(l=>{l||d({text:m.invalidSearch,type:"warning"}),w.emit("order/data",l)}).catch(async l=>{var N;let f=!0;e==null||e({error:l.message});const y=t?await A():{email:""};(y==null?void 0:y.email)===(i==null?void 0:i.email)?(f=!1,p(a,{orderRef:i.number})):f=o==null?void 0:o({render:(N=l==null?void 0:l.message)==null?void 0:N.includes("Please login to view the order."),formValues:i}),f&&d({text:l.message,type:"warning"})}).finally(()=>{h(!1)})},[t,e,o,a,m.invalidSearch]),inLineAlert:u,loading:E,normalizeFieldsConfig:M}},ne=({className:e,isAuth:t,renderSignIn:o,routeCustomerOrder:a,routeGuestOrder:c,onError:u})=>{const{onSubmit:d,loading:E,inLineAlert:h,normalizeFieldsConfig:m}=q({onError:u,isAuth:t,renderSignIn:o,routeCustomerOrder:a,routeGuestOrder:c});return s("div",{className:_(["order-order-search",e]),children:s(B,{onSubmit:d,loading:E,inLineAlert:h,fieldsConfig:m})})};export{ne as OrderSearch,ne as default};