@medusajs/draft-order 0.0.1
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/.medusa/server/src/admin/components/common/action-menu.js +77 -0
- package/.medusa/server/src/admin/components/common/conditional-tooltip.js +15 -0
- package/.medusa/server/src/admin/components/common/data-table.js +249 -0
- package/.medusa/server/src/admin/components/common/form.js +151 -0
- package/.medusa/server/src/admin/components/common/inline-tip.js +42 -0
- package/.medusa/server/src/admin/components/common/keybound-form.js +32 -0
- package/.medusa/server/src/admin/components/common/page-skeleton.js +51 -0
- package/.medusa/server/src/admin/components/common/thumbnail.js +15 -0
- package/.medusa/server/src/admin/components/draft-orders/activity-section.js +205 -0
- package/.medusa/server/src/admin/components/draft-orders/customer-section.js +165 -0
- package/.medusa/server/src/admin/components/draft-orders/general-section.js +36 -0
- package/.medusa/server/src/admin/components/draft-orders/json-view-section.js +140 -0
- package/.medusa/server/src/admin/components/draft-orders/metadata-section.js +28 -0
- package/.medusa/server/src/admin/components/draft-orders/shipping-section.js +211 -0
- package/.medusa/server/src/admin/components/draft-orders/summary-section.js +148 -0
- package/.medusa/server/src/admin/components/inputs/combobox.js +311 -0
- package/.medusa/server/src/admin/components/inputs/country-select.js +59 -0
- package/.medusa/server/src/admin/components/inputs/number-input.js +100 -0
- package/.medusa/server/src/admin/components/inputs/switch-block.js +30 -0
- package/.medusa/server/src/admin/components/modals/index.js +19 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-drawer/route-drawer.js +57 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-focus-modal/route-focus-modal.js +71 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/index.js +4 -0
- package/.medusa/server/src/admin/components/modals/route-modal-form/route-modal-form.js +60 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/route-provider.js +30 -0
- package/.medusa/server/src/admin/components/modals/route-modal-provider/use-route-modal.js +12 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-drawer/stacked-drawer.js +55 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/index.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-focus-modal/stacked-focus-modal.js +63 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/index.js +6 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-context.js +5 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/stacked-modal-provider.js +47 -0
- package/.medusa/server/src/admin/components/modals/stacked-modal-provider/use-stacked-modal.js +14 -0
- package/.medusa/server/src/admin/components/utilities/generic-forward-ref.js +7 -0
- package/.medusa/server/src/admin/hooks/api/customers.js +53 -0
- package/.medusa/server/src/admin/hooks/api/draft-orders.js +161 -0
- package/.medusa/server/src/admin/hooks/api/orders.js +274 -0
- package/.medusa/server/src/admin/hooks/api/product-variants.js +21 -0
- package/.medusa/server/src/admin/hooks/api/regions.js +35 -0
- package/.medusa/server/src/admin/hooks/api/sales-channels.js +35 -0
- package/.medusa/server/src/admin/hooks/api/shipping-options.js +35 -0
- package/.medusa/server/src/admin/hooks/api/users.js +26 -0
- package/.medusa/server/src/admin/hooks/common/use-combobox-data.js +61 -0
- package/.medusa/server/src/admin/hooks/common/use-data-table-date-filters.js +89 -0
- package/.medusa/server/src/admin/hooks/common/use-debounced-search.js +22 -0
- package/.medusa/server/src/admin/hooks/common/use-query-params.js +14 -0
- package/.medusa/server/src/admin/hooks/order-edits/use-cancel-order-edit.js +25 -0
- package/.medusa/server/src/admin/hooks/order-edits/use-initiate-order-edit.js +39 -0
- package/.medusa/server/src/admin/lib/data/countries.js +1762 -0
- package/.medusa/server/src/admin/lib/data/currencies.js +36 -0
- package/.medusa/server/src/admin/lib/queries/draft-order-details.js +1 -0
- package/.medusa/server/src/admin/lib/queries/sdk.js +10 -0
- package/.medusa/server/src/admin/lib/schemas/address.js +16 -0
- package/.medusa/server/src/admin/lib/utils/address-utils.js +57 -0
- package/.medusa/server/src/admin/lib/utils/date-utils.js +27 -0
- package/.medusa/server/src/admin/lib/utils/order-utils.js +13 -0
- package/.medusa/server/src/admin/routes/draft-orders/@create/page.js +659 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@billing-address/page.js +228 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@custom-items/page.js +38 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@email/page.js +89 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@items/page.js +576 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@metadata/page.js +338 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@promotions/page.js +70 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@sales-channel/page.js +113 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping/page.js +465 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/@shipping-address/page.js +241 -0
- package/.medusa/server/src/admin/routes/draft-orders/_id_/page.js +70 -0
- package/.medusa/server/src/admin/routes/draft-orders/page.js +148 -0
- package/.medusa/server/src/api/admin/draft-orders/[id]/convert/route.js +18 -0
- package/.medusa/server/src/types/http/draft-orders/payloads.js +3 -0
- package/.medusa/server/src/types/http/draft-orders/responses.js +3 -0
- package/.medusa/server/src/types/http/orders/entity.js +3 -0
- package/.medusa/server/src/types/http/orders/requests.js +3 -0
- package/.medusa/server/src/workflows/draft-orders/convert-draft-order-workflow.js +54 -0
- package/.medusa/server/tailwind.config.js +12 -0
- package/README.md +64 -0
- package/package.json +104 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const getLocaleAmount = (amount, currencyCode) => {
|
|
2
|
+
const formatter = new Intl.NumberFormat([], {
|
|
3
|
+
style: "currency",
|
|
4
|
+
currencyDisplay: "narrowSymbol",
|
|
5
|
+
currency: currencyCode
|
|
6
|
+
});
|
|
7
|
+
return formatter.format(amount);
|
|
8
|
+
};
|
|
9
|
+
const getNativeSymbol = (currencyCode) => {
|
|
10
|
+
const formatted = new Intl.NumberFormat([], {
|
|
11
|
+
style: "currency",
|
|
12
|
+
currency: currencyCode,
|
|
13
|
+
currencyDisplay: "narrowSymbol"
|
|
14
|
+
}).format(0);
|
|
15
|
+
return formatted.replace(/\d/g, "").replace(/[.,]/g, "").trim();
|
|
16
|
+
};
|
|
17
|
+
const getDecimalDigits = (currencyCode) => {
|
|
18
|
+
const formatter = new Intl.NumberFormat(void 0, {
|
|
19
|
+
style: "currency",
|
|
20
|
+
currency: currencyCode
|
|
21
|
+
});
|
|
22
|
+
return formatter.resolvedOptions().maximumFractionDigits;
|
|
23
|
+
};
|
|
24
|
+
const getStylizedAmount = (amount, currencyCode) => {
|
|
25
|
+
const symbol = getNativeSymbol(currencyCode);
|
|
26
|
+
const decimalDigits = getDecimalDigits(currencyCode);
|
|
27
|
+
const total = amount.toLocaleString(void 0, {
|
|
28
|
+
minimumFractionDigits: decimalDigits,
|
|
29
|
+
maximumFractionDigits: decimalDigits
|
|
30
|
+
});
|
|
31
|
+
return `${symbol} ${total} ${currencyCode.toUpperCase()}`;
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
getLocaleAmount,
|
|
35
|
+
getStylizedAmount
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/zod/lib/index.mjs";
|
|
2
|
+
const addressSchema = z.object({
|
|
3
|
+
country_code: z.string().min(1),
|
|
4
|
+
first_name: z.string().min(1),
|
|
5
|
+
last_name: z.string().min(1),
|
|
6
|
+
address_1: z.string().min(1),
|
|
7
|
+
address_2: z.string().optional(),
|
|
8
|
+
company: z.string().optional(),
|
|
9
|
+
city: z.string().min(1),
|
|
10
|
+
province: z.string().optional(),
|
|
11
|
+
postal_code: z.string().min(1),
|
|
12
|
+
phone: z.string().optional()
|
|
13
|
+
});
|
|
14
|
+
export {
|
|
15
|
+
addressSchema
|
|
16
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { getCountryByIso2 } from "../data/countries.js";
|
|
2
|
+
function isSameAddress(a, b) {
|
|
3
|
+
if (!a || !b) {
|
|
4
|
+
return false;
|
|
5
|
+
}
|
|
6
|
+
return a.first_name === b.first_name && a.last_name === b.last_name && a.address_1 === b.address_1 && a.address_2 === b.address_2 && a.city === b.city && a.postal_code === b.postal_code && a.province === b.province && a.country_code === b.country_code && a.phone === b.phone && a.company === b.company;
|
|
7
|
+
}
|
|
8
|
+
function getFormattedAddress(address) {
|
|
9
|
+
if (!address) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const {
|
|
13
|
+
first_name,
|
|
14
|
+
last_name,
|
|
15
|
+
company,
|
|
16
|
+
address_1,
|
|
17
|
+
address_2,
|
|
18
|
+
city,
|
|
19
|
+
postal_code,
|
|
20
|
+
province,
|
|
21
|
+
country_code
|
|
22
|
+
} = address;
|
|
23
|
+
const country = "country" in address ? address.country : null;
|
|
24
|
+
const name = [first_name, last_name].filter(Boolean).join(" ");
|
|
25
|
+
const formattedAddress = [];
|
|
26
|
+
if (name) {
|
|
27
|
+
formattedAddress.push(name);
|
|
28
|
+
}
|
|
29
|
+
if (company) {
|
|
30
|
+
formattedAddress.push(company);
|
|
31
|
+
}
|
|
32
|
+
if (address_1) {
|
|
33
|
+
formattedAddress.push(address_1);
|
|
34
|
+
}
|
|
35
|
+
if (address_2) {
|
|
36
|
+
formattedAddress.push(address_2);
|
|
37
|
+
}
|
|
38
|
+
const cityProvincePostal = [city, province, postal_code].filter(Boolean).join(" ");
|
|
39
|
+
if (cityProvincePostal) {
|
|
40
|
+
formattedAddress.push(cityProvincePostal);
|
|
41
|
+
}
|
|
42
|
+
if (country) {
|
|
43
|
+
formattedAddress.push(country.display_name);
|
|
44
|
+
} else if (country_code) {
|
|
45
|
+
const country2 = getCountryByIso2(country_code);
|
|
46
|
+
if (country2) {
|
|
47
|
+
formattedAddress.push(country2.display_name);
|
|
48
|
+
} else {
|
|
49
|
+
formattedAddress.push(country_code.toUpperCase());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return formattedAddress;
|
|
53
|
+
}
|
|
54
|
+
export {
|
|
55
|
+
getFormattedAddress,
|
|
56
|
+
isSameAddress
|
|
57
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { formatDistance, sub, format } from "date-fns";
|
|
2
|
+
import { enUS } from "/Users/oliverjuhl/Desktop/medusa/draft-order-plugin/node_modules/date-fns/locale.mjs";
|
|
3
|
+
const LOCALE = enUS;
|
|
4
|
+
function getRelativeDate(date) {
|
|
5
|
+
const now = /* @__PURE__ */ new Date();
|
|
6
|
+
return formatDistance(sub(new Date(date), { minutes: 0 }), now, {
|
|
7
|
+
addSuffix: true,
|
|
8
|
+
locale: LOCALE
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
const getFullDate = ({
|
|
12
|
+
date,
|
|
13
|
+
includeTime = false
|
|
14
|
+
}) => {
|
|
15
|
+
const ensuredDate = new Date(date);
|
|
16
|
+
if (isNaN(ensuredDate.getTime())) {
|
|
17
|
+
return "";
|
|
18
|
+
}
|
|
19
|
+
const timeFormat = includeTime ? "p" : "";
|
|
20
|
+
return format(ensuredDate, `PP ${timeFormat}`, {
|
|
21
|
+
locale: LOCALE
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
getFullDate,
|
|
26
|
+
getRelativeDate
|
|
27
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function getUniqueShippingProfiles(items) {
|
|
2
|
+
const shippingProfiles = items.map((item) => {
|
|
3
|
+
var _a, _b;
|
|
4
|
+
return (_b = (_a = item.variant) == null ? void 0 : _a.product) == null ? void 0 : _b.shipping_profile;
|
|
5
|
+
}).filter(Boolean);
|
|
6
|
+
const uniqueShippingProfiles = shippingProfiles.filter(
|
|
7
|
+
(profile, index, self) => self.findIndex((p) => p.id === profile.id) === index
|
|
8
|
+
);
|
|
9
|
+
return uniqueShippingProfiles;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
getUniqueShippingProfiles
|
|
13
|
+
};
|