@medusajs/draft-order 2.12.4-preview-20251223150132 → 2.12.4-preview-20251223180143

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.
@@ -9762,6 +9762,27 @@ const BillingAddressForm = ({ order }) => {
9762
9762
  ) });
9763
9763
  };
9764
9764
  const schema$5 = addressSchema;
9765
+ const CustomItems = () => {
9766
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9767
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
9768
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
9769
+ ] });
9770
+ };
9771
+ const CustomItemsForm = () => {
9772
+ const form = reactHookForm.useForm({
9773
+ resolver: zod.zodResolver(schema$4)
9774
+ });
9775
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
9776
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
9777
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
9778
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
9779
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
9780
+ ] }) })
9781
+ ] }) });
9782
+ };
9783
+ const schema$4 = objectType({
9784
+ email: stringType().email()
9785
+ });
9765
9786
  const Email = () => {
9766
9787
  const { id } = reactRouterDom.useParams();
9767
9788
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9784,7 +9805,7 @@ const EmailForm = ({ order }) => {
9784
9805
  defaultValues: {
9785
9806
  email: order.email ?? ""
9786
9807
  },
9787
- resolver: zod.zodResolver(schema$4)
9808
+ resolver: zod.zodResolver(schema$3)
9788
9809
  });
9789
9810
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9790
9811
  const { handleSuccess } = useRouteModal();
@@ -9827,526 +9848,176 @@ const EmailForm = ({ order }) => {
9827
9848
  }
9828
9849
  ) });
9829
9850
  };
9830
- const schema$4 = objectType({
9851
+ const schema$3 = objectType({
9831
9852
  email: stringType().email()
9832
9853
  });
9833
- const InlineTip = React.forwardRef(
9834
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9835
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9854
+ const NumberInput = React.forwardRef(
9855
+ ({
9856
+ value,
9857
+ onChange,
9858
+ size = "base",
9859
+ min = 0,
9860
+ max = 100,
9861
+ step = 1,
9862
+ className,
9863
+ disabled,
9864
+ ...props
9865
+ }, ref) => {
9866
+ const handleChange = (event) => {
9867
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9868
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9869
+ onChange(newValue);
9870
+ }
9871
+ };
9872
+ const handleIncrement = () => {
9873
+ const newValue = value + step;
9874
+ if (max === void 0 || newValue <= max) {
9875
+ onChange(newValue);
9876
+ }
9877
+ };
9878
+ const handleDecrement = () => {
9879
+ const newValue = value - step;
9880
+ if (min === void 0 || newValue >= min) {
9881
+ onChange(newValue);
9882
+ }
9883
+ };
9836
9884
  return /* @__PURE__ */ jsxRuntime.jsxs(
9837
9885
  "div",
9838
9886
  {
9839
- ref,
9840
9887
  className: ui.clx(
9841
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9888
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9889
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9890
+ {
9891
+ "h-7": size === "small",
9892
+ "h-8": size === "base"
9893
+ },
9842
9894
  className
9843
9895
  ),
9844
- ...props,
9845
9896
  children: [
9846
9897
  /* @__PURE__ */ jsxRuntime.jsx(
9847
- "div",
9898
+ "input",
9848
9899
  {
9849
- role: "presentation",
9850
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9851
- "bg-ui-tag-orange-icon": variant === "warning"
9852
- })
9900
+ ref,
9901
+ type: "number",
9902
+ value,
9903
+ onChange: handleChange,
9904
+ min,
9905
+ max,
9906
+ step,
9907
+ className: ui.clx(
9908
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9909
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9910
+ "placeholder:text-ui-fg-muted"
9911
+ ),
9912
+ ...props
9853
9913
  }
9854
9914
  ),
9855
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9856
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9857
- labelValue,
9858
- ":"
9859
- ] }),
9860
- " ",
9861
- children
9862
- ] })
9915
+ /* @__PURE__ */ jsxRuntime.jsxs(
9916
+ "button",
9917
+ {
9918
+ className: ui.clx(
9919
+ "flex items-center justify-center outline-none transition-fg",
9920
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9921
+ "focus:bg-ui-bg-field-component-hover",
9922
+ "hover:bg-ui-bg-field-component-hover",
9923
+ {
9924
+ "size-7": size === "small",
9925
+ "size-8": size === "base"
9926
+ }
9927
+ ),
9928
+ type: "button",
9929
+ onClick: handleDecrement,
9930
+ disabled: min !== void 0 && value <= min || disabled,
9931
+ children: [
9932
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9933
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9934
+ ]
9935
+ }
9936
+ ),
9937
+ /* @__PURE__ */ jsxRuntime.jsxs(
9938
+ "button",
9939
+ {
9940
+ className: ui.clx(
9941
+ "flex items-center justify-center outline-none transition-fg",
9942
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9943
+ "focus:bg-ui-bg-field-hover",
9944
+ "hover:bg-ui-bg-field-hover",
9945
+ {
9946
+ "size-7": size === "small",
9947
+ "size-8": size === "base"
9948
+ }
9949
+ ),
9950
+ type: "button",
9951
+ onClick: handleIncrement,
9952
+ disabled: max !== void 0 && value >= max || disabled,
9953
+ children: [
9954
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9955
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9956
+ ]
9957
+ }
9958
+ )
9863
9959
  ]
9864
9960
  }
9865
9961
  );
9866
9962
  }
9867
9963
  );
9868
- InlineTip.displayName = "InlineTip";
9869
- const MetadataFieldSchema = objectType({
9870
- key: stringType(),
9871
- disabled: booleanType().optional(),
9872
- value: anyType()
9873
- });
9874
- const MetadataSchema = objectType({
9875
- metadata: arrayType(MetadataFieldSchema)
9876
- });
9877
- const Metadata = () => {
9878
- const { id } = reactRouterDom.useParams();
9879
- const { order, isPending, isError, error } = useOrder(id, {
9880
- fields: "metadata"
9881
- });
9882
- if (isError) {
9883
- throw error;
9884
- }
9885
- const isReady = !isPending && !!order;
9886
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9887
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9888
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9889
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9890
- ] }),
9891
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9892
- ] });
9964
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9965
+ const productVariantsQueryKeys = {
9966
+ list: (query2) => [
9967
+ PRODUCT_VARIANTS_QUERY_KEY,
9968
+ query2 ? query2 : void 0
9969
+ ]
9893
9970
  };
9894
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9895
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9896
- const MetadataForm = ({ orderId, metadata }) => {
9897
- const { handleSuccess } = useRouteModal();
9898
- const hasUneditableRows = getHasUneditableRows(metadata);
9899
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9900
- const form = reactHookForm.useForm({
9901
- defaultValues: {
9902
- metadata: getDefaultValues(metadata)
9903
- },
9904
- resolver: zod.zodResolver(MetadataSchema)
9971
+ const useProductVariants = (query2, options) => {
9972
+ const { data, ...rest } = reactQuery.useQuery({
9973
+ queryKey: productVariantsQueryKeys.list(query2),
9974
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9975
+ ...options
9905
9976
  });
9906
- const handleSubmit = form.handleSubmit(async (data) => {
9907
- const parsedData = parseValues(data);
9908
- await mutateAsync(
9909
- {
9910
- metadata: parsedData
9977
+ return { ...data, ...rest };
9978
+ };
9979
+ const useCancelOrderEdit = ({ preview }) => {
9980
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9981
+ const onCancel = React.useCallback(async () => {
9982
+ if (!preview) {
9983
+ return true;
9984
+ }
9985
+ let res = false;
9986
+ await cancelOrderEdit(void 0, {
9987
+ onError: (e) => {
9988
+ ui.toast.error(e.message);
9911
9989
  },
9912
- {
9913
- onSuccess: () => {
9914
- ui.toast.success("Metadata updated");
9915
- handleSuccess();
9916
- },
9917
- onError: (error) => {
9918
- ui.toast.error(error.message);
9919
- }
9990
+ onSuccess: () => {
9991
+ res = true;
9920
9992
  }
9921
- );
9922
- });
9923
- const { fields, insert, remove } = reactHookForm.useFieldArray({
9924
- control: form.control,
9925
- name: "metadata"
9926
- });
9927
- function deleteRow(index) {
9928
- remove(index);
9929
- if (fields.length === 1) {
9930
- insert(0, {
9931
- key: "",
9932
- value: "",
9933
- disabled: false
9993
+ });
9994
+ return res;
9995
+ }, [preview, cancelOrderEdit]);
9996
+ return { onCancel };
9997
+ };
9998
+ let IS_REQUEST_RUNNING = false;
9999
+ const useInitiateOrderEdit = ({
10000
+ preview
10001
+ }) => {
10002
+ const navigate = reactRouterDom.useNavigate();
10003
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10004
+ React.useEffect(() => {
10005
+ async function run() {
10006
+ if (IS_REQUEST_RUNNING || !preview) {
10007
+ return;
10008
+ }
10009
+ if (preview.order_change) {
10010
+ return;
10011
+ }
10012
+ IS_REQUEST_RUNNING = true;
10013
+ await mutateAsync(void 0, {
10014
+ onError: (e) => {
10015
+ ui.toast.error(e.message);
10016
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
10017
+ return;
10018
+ }
9934
10019
  });
9935
- }
9936
- }
9937
- function insertRow(index, position) {
9938
- insert(index + (position === "above" ? 0 : 1), {
9939
- key: "",
9940
- value: "",
9941
- disabled: false
9942
- });
9943
- }
9944
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9945
- KeyboundForm,
9946
- {
9947
- onSubmit: handleSubmit,
9948
- className: "flex flex-1 flex-col overflow-hidden",
9949
- children: [
9950
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9951
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9952
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9953
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
9954
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
9955
- ] }),
9956
- fields.map((field, index) => {
9957
- const isDisabled = field.disabled || false;
9958
- let placeholder = "-";
9959
- if (typeof field.value === "object") {
9960
- placeholder = "{ ... }";
9961
- }
9962
- if (Array.isArray(field.value)) {
9963
- placeholder = "[ ... ]";
9964
- }
9965
- return /* @__PURE__ */ jsxRuntime.jsx(
9966
- ConditionalTooltip,
9967
- {
9968
- showTooltip: isDisabled,
9969
- content: "This row is disabled because it contains non-primitive data.",
9970
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9971
- /* @__PURE__ */ jsxRuntime.jsxs(
9972
- "div",
9973
- {
9974
- className: ui.clx("grid grid-cols-2 divide-x", {
9975
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9976
- }),
9977
- children: [
9978
- /* @__PURE__ */ jsxRuntime.jsx(
9979
- Form$2.Field,
9980
- {
9981
- control: form.control,
9982
- name: `metadata.${index}.key`,
9983
- render: ({ field: field2 }) => {
9984
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
9985
- GridInput,
9986
- {
9987
- "aria-labelledby": METADATA_KEY_LABEL_ID,
9988
- ...field2,
9989
- disabled: isDisabled,
9990
- placeholder: "Key"
9991
- }
9992
- ) }) });
9993
- }
9994
- }
9995
- ),
9996
- /* @__PURE__ */ jsxRuntime.jsx(
9997
- Form$2.Field,
9998
- {
9999
- control: form.control,
10000
- name: `metadata.${index}.value`,
10001
- render: ({ field: { value, ...field2 } }) => {
10002
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10003
- GridInput,
10004
- {
10005
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10006
- ...field2,
10007
- value: isDisabled ? placeholder : value,
10008
- disabled: isDisabled,
10009
- placeholder: "Value"
10010
- }
10011
- ) }) });
10012
- }
10013
- }
10014
- )
10015
- ]
10016
- }
10017
- ),
10018
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10019
- /* @__PURE__ */ jsxRuntime.jsx(
10020
- ui.DropdownMenu.Trigger,
10021
- {
10022
- className: ui.clx(
10023
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10024
- {
10025
- hidden: isDisabled
10026
- }
10027
- ),
10028
- disabled: isDisabled,
10029
- asChild: true,
10030
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10031
- }
10032
- ),
10033
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10034
- /* @__PURE__ */ jsxRuntime.jsxs(
10035
- ui.DropdownMenu.Item,
10036
- {
10037
- className: "gap-x-2",
10038
- onClick: () => insertRow(index, "above"),
10039
- children: [
10040
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10041
- "Insert row above"
10042
- ]
10043
- }
10044
- ),
10045
- /* @__PURE__ */ jsxRuntime.jsxs(
10046
- ui.DropdownMenu.Item,
10047
- {
10048
- className: "gap-x-2",
10049
- onClick: () => insertRow(index, "below"),
10050
- children: [
10051
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10052
- "Insert row below"
10053
- ]
10054
- }
10055
- ),
10056
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10057
- /* @__PURE__ */ jsxRuntime.jsxs(
10058
- ui.DropdownMenu.Item,
10059
- {
10060
- className: "gap-x-2",
10061
- onClick: () => deleteRow(index),
10062
- children: [
10063
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10064
- "Delete row"
10065
- ]
10066
- }
10067
- )
10068
- ] })
10069
- ] })
10070
- ] })
10071
- },
10072
- field.id
10073
- );
10074
- })
10075
- ] }),
10076
- hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
10077
- ] }),
10078
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10079
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10080
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10081
- ] }) })
10082
- ]
10083
- }
10084
- ) });
10085
- };
10086
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10087
- return /* @__PURE__ */ jsxRuntime.jsx(
10088
- "input",
10089
- {
10090
- ref,
10091
- ...props,
10092
- autoComplete: "off",
10093
- className: ui.clx(
10094
- "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
10095
- className
10096
- )
10097
- }
10098
- );
10099
- });
10100
- GridInput.displayName = "MetadataForm.GridInput";
10101
- const PlaceholderInner = () => {
10102
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10103
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10104
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10105
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10106
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10107
- ] }) })
10108
- ] });
10109
- };
10110
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10111
- function getDefaultValues(metadata) {
10112
- if (!metadata || !Object.keys(metadata).length) {
10113
- return [
10114
- {
10115
- key: "",
10116
- value: "",
10117
- disabled: false
10118
- }
10119
- ];
10120
- }
10121
- return Object.entries(metadata).map(([key, value]) => {
10122
- if (!EDITABLE_TYPES.includes(typeof value)) {
10123
- return {
10124
- key,
10125
- value,
10126
- disabled: true
10127
- };
10128
- }
10129
- let stringValue = value;
10130
- if (typeof value !== "string") {
10131
- stringValue = JSON.stringify(value);
10132
- }
10133
- return {
10134
- key,
10135
- value: stringValue,
10136
- original_key: key
10137
- };
10138
- });
10139
- }
10140
- function parseValues(values) {
10141
- const metadata = values.metadata;
10142
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10143
- if (isEmpty) {
10144
- return null;
10145
- }
10146
- const update = {};
10147
- metadata.forEach((field) => {
10148
- let key = field.key;
10149
- let value = field.value;
10150
- const disabled = field.disabled;
10151
- if (!key || !value) {
10152
- return;
10153
- }
10154
- if (disabled) {
10155
- update[key] = value;
10156
- return;
10157
- }
10158
- key = key.trim();
10159
- value = value.trim();
10160
- if (value === "true") {
10161
- update[key] = true;
10162
- } else if (value === "false") {
10163
- update[key] = false;
10164
- } else {
10165
- const parsedNumber = parseFloat(value);
10166
- if (!isNaN(parsedNumber)) {
10167
- update[key] = parsedNumber;
10168
- } else {
10169
- update[key] = value;
10170
- }
10171
- }
10172
- });
10173
- return update;
10174
- }
10175
- function getHasUneditableRows(metadata) {
10176
- if (!metadata) {
10177
- return false;
10178
- }
10179
- return Object.values(metadata).some(
10180
- (value) => !EDITABLE_TYPES.includes(typeof value)
10181
- );
10182
- }
10183
- const NumberInput = React.forwardRef(
10184
- ({
10185
- value,
10186
- onChange,
10187
- size = "base",
10188
- min = 0,
10189
- max = 100,
10190
- step = 1,
10191
- className,
10192
- disabled,
10193
- ...props
10194
- }, ref) => {
10195
- const handleChange = (event) => {
10196
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10197
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10198
- onChange(newValue);
10199
- }
10200
- };
10201
- const handleIncrement = () => {
10202
- const newValue = value + step;
10203
- if (max === void 0 || newValue <= max) {
10204
- onChange(newValue);
10205
- }
10206
- };
10207
- const handleDecrement = () => {
10208
- const newValue = value - step;
10209
- if (min === void 0 || newValue >= min) {
10210
- onChange(newValue);
10211
- }
10212
- };
10213
- return /* @__PURE__ */ jsxRuntime.jsxs(
10214
- "div",
10215
- {
10216
- className: ui.clx(
10217
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10218
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10219
- {
10220
- "h-7": size === "small",
10221
- "h-8": size === "base"
10222
- },
10223
- className
10224
- ),
10225
- children: [
10226
- /* @__PURE__ */ jsxRuntime.jsx(
10227
- "input",
10228
- {
10229
- ref,
10230
- type: "number",
10231
- value,
10232
- onChange: handleChange,
10233
- min,
10234
- max,
10235
- step,
10236
- className: ui.clx(
10237
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10238
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10239
- "placeholder:text-ui-fg-muted"
10240
- ),
10241
- ...props
10242
- }
10243
- ),
10244
- /* @__PURE__ */ jsxRuntime.jsxs(
10245
- "button",
10246
- {
10247
- className: ui.clx(
10248
- "flex items-center justify-center outline-none transition-fg",
10249
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10250
- "focus:bg-ui-bg-field-component-hover",
10251
- "hover:bg-ui-bg-field-component-hover",
10252
- {
10253
- "size-7": size === "small",
10254
- "size-8": size === "base"
10255
- }
10256
- ),
10257
- type: "button",
10258
- onClick: handleDecrement,
10259
- disabled: min !== void 0 && value <= min || disabled,
10260
- children: [
10261
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10262
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10263
- ]
10264
- }
10265
- ),
10266
- /* @__PURE__ */ jsxRuntime.jsxs(
10267
- "button",
10268
- {
10269
- className: ui.clx(
10270
- "flex items-center justify-center outline-none transition-fg",
10271
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10272
- "focus:bg-ui-bg-field-hover",
10273
- "hover:bg-ui-bg-field-hover",
10274
- {
10275
- "size-7": size === "small",
10276
- "size-8": size === "base"
10277
- }
10278
- ),
10279
- type: "button",
10280
- onClick: handleIncrement,
10281
- disabled: max !== void 0 && value >= max || disabled,
10282
- children: [
10283
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10284
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10285
- ]
10286
- }
10287
- )
10288
- ]
10289
- }
10290
- );
10291
- }
10292
- );
10293
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10294
- const productVariantsQueryKeys = {
10295
- list: (query2) => [
10296
- PRODUCT_VARIANTS_QUERY_KEY,
10297
- query2 ? query2 : void 0
10298
- ]
10299
- };
10300
- const useProductVariants = (query2, options) => {
10301
- const { data, ...rest } = reactQuery.useQuery({
10302
- queryKey: productVariantsQueryKeys.list(query2),
10303
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10304
- ...options
10305
- });
10306
- return { ...data, ...rest };
10307
- };
10308
- const useCancelOrderEdit = ({ preview }) => {
10309
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10310
- const onCancel = React.useCallback(async () => {
10311
- if (!preview) {
10312
- return true;
10313
- }
10314
- let res = false;
10315
- await cancelOrderEdit(void 0, {
10316
- onError: (e) => {
10317
- ui.toast.error(e.message);
10318
- },
10319
- onSuccess: () => {
10320
- res = true;
10321
- }
10322
- });
10323
- return res;
10324
- }, [preview, cancelOrderEdit]);
10325
- return { onCancel };
10326
- };
10327
- let IS_REQUEST_RUNNING = false;
10328
- const useInitiateOrderEdit = ({
10329
- preview
10330
- }) => {
10331
- const navigate = reactRouterDom.useNavigate();
10332
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10333
- React.useEffect(() => {
10334
- async function run() {
10335
- if (IS_REQUEST_RUNNING || !preview) {
10336
- return;
10337
- }
10338
- if (preview.order_change) {
10339
- return;
10340
- }
10341
- IS_REQUEST_RUNNING = true;
10342
- await mutateAsync(void 0, {
10343
- onError: (e) => {
10344
- ui.toast.error(e.message);
10345
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10346
- return;
10347
- }
10348
- });
10349
- IS_REQUEST_RUNNING = false;
10020
+ IS_REQUEST_RUNNING = false;
10350
10021
  }
10351
10022
  run();
10352
10023
  }, [preview, navigate, mutateAsync]);
@@ -10585,20 +10256,168 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10585
10256
  const [editing, setEditing] = React.useState(false);
10586
10257
  const form = reactHookForm.useForm({
10587
10258
  defaultValues: {
10588
- quantity: item.quantity,
10589
- unit_price: item.unit_price
10259
+ quantity: item.quantity,
10260
+ unit_price: item.unit_price
10261
+ },
10262
+ resolver: zod.zodResolver(variantItemSchema)
10263
+ });
10264
+ const actionId = React.useMemo(() => {
10265
+ var _a, _b;
10266
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10267
+ }, [item]);
10268
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10269
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10270
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10271
+ const onSubmit = form.handleSubmit(async (data) => {
10272
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10273
+ setEditing(false);
10274
+ return;
10275
+ }
10276
+ if (!actionId) {
10277
+ await updateOriginalItem(
10278
+ {
10279
+ item_id: item.id,
10280
+ quantity: data.quantity,
10281
+ unit_price: convertNumber(data.unit_price)
10282
+ },
10283
+ {
10284
+ onSuccess: () => {
10285
+ setEditing(false);
10286
+ },
10287
+ onError: (e) => {
10288
+ ui.toast.error(e.message);
10289
+ }
10290
+ }
10291
+ );
10292
+ return;
10293
+ }
10294
+ await updateActionItem(
10295
+ {
10296
+ action_id: actionId,
10297
+ quantity: data.quantity,
10298
+ unit_price: convertNumber(data.unit_price)
10299
+ },
10300
+ {
10301
+ onSuccess: () => {
10302
+ setEditing(false);
10303
+ },
10304
+ onError: (e) => {
10305
+ ui.toast.error(e.message);
10306
+ }
10307
+ }
10308
+ );
10309
+ });
10310
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10311
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10312
+ /* @__PURE__ */ jsxRuntime.jsx(
10313
+ Thumbnail,
10314
+ {
10315
+ thumbnail: item.thumbnail,
10316
+ alt: item.product_title ?? void 0
10317
+ }
10318
+ ),
10319
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10320
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10321
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10322
+ /* @__PURE__ */ jsxRuntime.jsxs(
10323
+ ui.Text,
10324
+ {
10325
+ size: "small",
10326
+ leading: "compact",
10327
+ className: "text-ui-fg-subtle",
10328
+ children: [
10329
+ "(",
10330
+ item.variant_title,
10331
+ ")"
10332
+ ]
10333
+ }
10334
+ )
10335
+ ] }),
10336
+ /* @__PURE__ */ jsxRuntime.jsx(
10337
+ ui.Text,
10338
+ {
10339
+ size: "small",
10340
+ leading: "compact",
10341
+ className: "text-ui-fg-subtle",
10342
+ children: item.variant_sku
10343
+ }
10344
+ )
10345
+ ] })
10346
+ ] }),
10347
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10348
+ Form$2.Field,
10349
+ {
10350
+ control: form.control,
10351
+ name: "quantity",
10352
+ render: ({ field }) => {
10353
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10354
+ }
10355
+ }
10356
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10357
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10358
+ Form$2.Field,
10359
+ {
10360
+ control: form.control,
10361
+ name: "unit_price",
10362
+ render: ({ field: { onChange, ...field } }) => {
10363
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10364
+ ui.CurrencyInput,
10365
+ {
10366
+ ...field,
10367
+ symbol: getNativeSymbol(currencyCode),
10368
+ code: currencyCode,
10369
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10370
+ }
10371
+ ) }) });
10372
+ }
10373
+ }
10374
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10375
+ /* @__PURE__ */ jsxRuntime.jsx(
10376
+ ui.IconButton,
10377
+ {
10378
+ type: "button",
10379
+ size: "small",
10380
+ onClick: editing ? onSubmit : () => {
10381
+ setEditing(true);
10382
+ },
10383
+ disabled: isPending,
10384
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10385
+ }
10386
+ )
10387
+ ] }) }) });
10388
+ };
10389
+ const variantItemSchema = objectType({
10390
+ quantity: numberType(),
10391
+ unit_price: unionType([numberType(), stringType()])
10392
+ });
10393
+ const CustomItem = ({ item, preview, currencyCode }) => {
10394
+ const [editing, setEditing] = React.useState(false);
10395
+ const { quantity, unit_price, title } = item;
10396
+ const form = reactHookForm.useForm({
10397
+ defaultValues: {
10398
+ title,
10399
+ quantity,
10400
+ unit_price
10590
10401
  },
10591
- resolver: zod.zodResolver(variantItemSchema)
10402
+ resolver: zod.zodResolver(customItemSchema)
10592
10403
  });
10404
+ React.useEffect(() => {
10405
+ form.reset({
10406
+ title,
10407
+ quantity,
10408
+ unit_price
10409
+ });
10410
+ }, [form, title, quantity, unit_price]);
10593
10411
  const actionId = React.useMemo(() => {
10594
10412
  var _a, _b;
10595
10413
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10596
10414
  }, [item]);
10597
10415
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10416
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10598
10417
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10599
10418
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10600
10419
  const onSubmit = form.handleSubmit(async (data) => {
10601
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10420
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10602
10421
  setEditing(false);
10603
10422
  return;
10604
10423
  }
@@ -10620,6 +10439,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10620
10439
  );
10621
10440
  return;
10622
10441
  }
10442
+ if (data.quantity === 0) {
10443
+ await removeActionItem(actionId, {
10444
+ onSuccess: () => {
10445
+ setEditing(false);
10446
+ },
10447
+ onError: (e) => {
10448
+ ui.toast.error(e.message);
10449
+ }
10450
+ });
10451
+ return;
10452
+ }
10623
10453
  await updateActionItem(
10624
10454
  {
10625
10455
  action_id: actionId,
@@ -10637,43 +10467,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10637
10467
  );
10638
10468
  });
10639
10469
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10640
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10470
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10641
10471
  /* @__PURE__ */ jsxRuntime.jsx(
10642
10472
  Thumbnail,
10643
10473
  {
10644
10474
  thumbnail: item.thumbnail,
10645
- alt: item.product_title ?? void 0
10475
+ alt: item.title ?? void 0
10646
10476
  }
10647
10477
  ),
10648
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10649
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10650
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10651
- /* @__PURE__ */ jsxRuntime.jsxs(
10652
- ui.Text,
10653
- {
10654
- size: "small",
10655
- leading: "compact",
10656
- className: "text-ui-fg-subtle",
10657
- children: [
10658
- "(",
10659
- item.variant_title,
10660
- ")"
10661
- ]
10662
- }
10663
- )
10664
- ] }),
10665
- /* @__PURE__ */ jsxRuntime.jsx(
10666
- ui.Text,
10667
- {
10668
- size: "small",
10669
- leading: "compact",
10670
- className: "text-ui-fg-subtle",
10671
- children: item.variant_sku
10478
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10479
+ Form$2.Field,
10480
+ {
10481
+ control: form.control,
10482
+ name: "title",
10483
+ render: ({ field }) => {
10484
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10672
10485
  }
10673
- )
10674
- ] })
10486
+ }
10487
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10675
10488
  ] }),
10676
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10489
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10677
10490
  Form$2.Field,
10678
10491
  {
10679
10492
  control: form.control,
@@ -10682,8 +10495,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10682
10495
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10683
10496
  }
10684
10497
  }
10685
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10686
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10498
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10499
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10687
10500
  Form$2.Field,
10688
10501
  {
10689
10502
  control: form.control,
@@ -10700,7 +10513,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10700
10513
  ) }) });
10701
10514
  }
10702
10515
  }
10703
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex w-full flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10516
+ ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10704
10517
  /* @__PURE__ */ jsxRuntime.jsx(
10705
10518
  ui.IconButton,
10706
10519
  {
@@ -10715,79 +10528,215 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10715
10528
  )
10716
10529
  ] }) }) });
10717
10530
  };
10718
- const variantItemSchema = objectType({
10719
- quantity: numberType(),
10720
- unit_price: unionType([numberType(), stringType()])
10721
- });
10722
- const CustomItem = ({ item, preview, currencyCode }) => {
10723
- const [editing, setEditing] = React.useState(false);
10724
- const { quantity, unit_price, title } = item;
10531
+ const StackedModalTrigger$1 = ({
10532
+ type,
10533
+ setModalContent
10534
+ }) => {
10535
+ const { setIsOpen } = useStackedModal();
10536
+ const onClick = React.useCallback(() => {
10537
+ setModalContent(type);
10538
+ setIsOpen(STACKED_MODAL_ID, true);
10539
+ }, [setModalContent, setIsOpen, type]);
10540
+ return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10541
+ };
10542
+ const VARIANT_PREFIX = "items";
10543
+ const LIMIT = 50;
10544
+ const ExistingItemsForm = ({ orderId, items }) => {
10545
+ const { setIsOpen } = useStackedModal();
10546
+ const [rowSelection, setRowSelection] = React.useState(
10547
+ items.reduce((acc, item) => {
10548
+ acc[item.variant_id] = true;
10549
+ return acc;
10550
+ }, {})
10551
+ );
10552
+ React.useEffect(() => {
10553
+ setRowSelection(
10554
+ items.reduce((acc, item) => {
10555
+ if (item.variant_id) {
10556
+ acc[item.variant_id] = true;
10557
+ }
10558
+ return acc;
10559
+ }, {})
10560
+ );
10561
+ }, [items]);
10562
+ const { q, order, offset } = useQueryParams(
10563
+ ["q", "order", "offset"],
10564
+ VARIANT_PREFIX
10565
+ );
10566
+ const { variants, count, isPending, isError, error } = useProductVariants(
10567
+ {
10568
+ q,
10569
+ order,
10570
+ offset: offset ? parseInt(offset) : void 0,
10571
+ limit: LIMIT
10572
+ },
10573
+ {
10574
+ placeholderData: reactQuery.keepPreviousData
10575
+ }
10576
+ );
10577
+ const columns = useColumns();
10578
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10579
+ const onSubmit = async () => {
10580
+ const ids = Object.keys(rowSelection).filter(
10581
+ (id) => !items.find((i) => i.variant_id === id)
10582
+ );
10583
+ await mutateAsync(
10584
+ {
10585
+ items: ids.map((id) => ({
10586
+ variant_id: id,
10587
+ quantity: 1
10588
+ }))
10589
+ },
10590
+ {
10591
+ onSuccess: () => {
10592
+ setRowSelection({});
10593
+ setIsOpen(STACKED_MODAL_ID, false);
10594
+ },
10595
+ onError: (e) => {
10596
+ ui.toast.error(e.message);
10597
+ }
10598
+ }
10599
+ );
10600
+ };
10601
+ if (isError) {
10602
+ throw error;
10603
+ }
10604
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10605
+ StackedFocusModal.Content,
10606
+ {
10607
+ onOpenAutoFocus: (e) => {
10608
+ e.preventDefault();
10609
+ const searchInput = document.querySelector(
10610
+ "[data-modal-id='modal-search-input']"
10611
+ );
10612
+ if (searchInput) {
10613
+ searchInput.focus();
10614
+ }
10615
+ },
10616
+ children: [
10617
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10618
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10619
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10620
+ ] }),
10621
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10622
+ DataTable,
10623
+ {
10624
+ data: variants,
10625
+ columns,
10626
+ isLoading: isPending,
10627
+ getRowId: (row) => row.id,
10628
+ rowCount: count,
10629
+ prefix: VARIANT_PREFIX,
10630
+ layout: "fill",
10631
+ rowSelection: {
10632
+ state: rowSelection,
10633
+ onRowSelectionChange: setRowSelection,
10634
+ enableRowSelection: (row) => {
10635
+ return !items.find((i) => i.variant_id === row.original.id);
10636
+ }
10637
+ },
10638
+ autoFocusSearch: true
10639
+ }
10640
+ ) }),
10641
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10642
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10643
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10644
+ ] }) })
10645
+ ]
10646
+ }
10647
+ );
10648
+ };
10649
+ const columnHelper = ui.createDataTableColumnHelper();
10650
+ const useColumns = () => {
10651
+ return React.useMemo(() => {
10652
+ return [
10653
+ columnHelper.select(),
10654
+ columnHelper.accessor("product.title", {
10655
+ header: "Product",
10656
+ cell: ({ row }) => {
10657
+ var _a, _b, _c;
10658
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10659
+ /* @__PURE__ */ jsxRuntime.jsx(
10660
+ Thumbnail,
10661
+ {
10662
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10663
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10664
+ }
10665
+ ),
10666
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10667
+ ] });
10668
+ },
10669
+ enableSorting: true
10670
+ }),
10671
+ columnHelper.accessor("title", {
10672
+ header: "Variant",
10673
+ enableSorting: true
10674
+ }),
10675
+ columnHelper.accessor("sku", {
10676
+ header: "SKU",
10677
+ cell: ({ getValue }) => {
10678
+ return getValue() ?? "-";
10679
+ },
10680
+ enableSorting: true
10681
+ }),
10682
+ columnHelper.accessor("updated_at", {
10683
+ header: "Updated",
10684
+ cell: ({ getValue }) => {
10685
+ return /* @__PURE__ */ jsxRuntime.jsx(
10686
+ ui.Tooltip,
10687
+ {
10688
+ content: getFullDate({ date: getValue(), includeTime: true }),
10689
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10690
+ }
10691
+ );
10692
+ },
10693
+ enableSorting: true,
10694
+ sortAscLabel: "Oldest first",
10695
+ sortDescLabel: "Newest first"
10696
+ }),
10697
+ columnHelper.accessor("created_at", {
10698
+ header: "Created",
10699
+ cell: ({ getValue }) => {
10700
+ return /* @__PURE__ */ jsxRuntime.jsx(
10701
+ ui.Tooltip,
10702
+ {
10703
+ content: getFullDate({ date: getValue(), includeTime: true }),
10704
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10705
+ }
10706
+ );
10707
+ },
10708
+ enableSorting: true,
10709
+ sortAscLabel: "Oldest first",
10710
+ sortDescLabel: "Newest first"
10711
+ })
10712
+ ];
10713
+ }, []);
10714
+ };
10715
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10716
+ const { setIsOpen } = useStackedModal();
10717
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10725
10718
  const form = reactHookForm.useForm({
10726
10719
  defaultValues: {
10727
- title,
10728
- quantity,
10729
- unit_price
10720
+ title: "",
10721
+ quantity: 1,
10722
+ unit_price: ""
10730
10723
  },
10731
10724
  resolver: zod.zodResolver(customItemSchema)
10732
10725
  });
10733
- React.useEffect(() => {
10734
- form.reset({
10735
- title,
10736
- quantity,
10737
- unit_price
10738
- });
10739
- }, [form, title, quantity, unit_price]);
10740
- const actionId = React.useMemo(() => {
10741
- var _a, _b;
10742
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10743
- }, [item]);
10744
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10745
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10746
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10747
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10748
10726
  const onSubmit = form.handleSubmit(async (data) => {
10749
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10750
- setEditing(false);
10751
- return;
10752
- }
10753
- if (!actionId) {
10754
- await updateOriginalItem(
10755
- {
10756
- item_id: item.id,
10757
- quantity: data.quantity,
10758
- unit_price: convertNumber(data.unit_price)
10759
- },
10760
- {
10761
- onSuccess: () => {
10762
- setEditing(false);
10763
- },
10764
- onError: (e) => {
10765
- ui.toast.error(e.message);
10766
- }
10767
- }
10768
- );
10769
- return;
10770
- }
10771
- if (data.quantity === 0) {
10772
- await removeActionItem(actionId, {
10773
- onSuccess: () => {
10774
- setEditing(false);
10775
- },
10776
- onError: (e) => {
10777
- ui.toast.error(e.message);
10778
- }
10779
- });
10780
- return;
10781
- }
10782
- await updateActionItem(
10727
+ await addItems(
10783
10728
  {
10784
- action_id: actionId,
10785
- quantity: data.quantity,
10786
- unit_price: convertNumber(data.unit_price)
10729
+ items: [
10730
+ {
10731
+ title: data.title,
10732
+ quantity: data.quantity,
10733
+ unit_price: convertNumber(data.unit_price)
10734
+ }
10735
+ ]
10787
10736
  },
10788
10737
  {
10789
10738
  onSuccess: () => {
10790
- setEditing(false);
10739
+ setIsOpen(STACKED_MODAL_ID, false);
10791
10740
  },
10792
10741
  onError: (e) => {
10793
10742
  ui.toast.error(e.message);
@@ -10795,386 +10744,437 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10795
10744
  }
10796
10745
  );
10797
10746
  });
10798
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-[minmax(0,2fr)_minmax(0,1fr)_minmax(0,2fr)_28px] items-center gap-3 rounded-lg px-4 py-2", children: [
10799
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10747
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10748
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10749
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
10750
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10751
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10752
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
10753
+ ] }),
10754
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10800
10755
  /* @__PURE__ */ jsxRuntime.jsx(
10801
- Thumbnail,
10756
+ Form$2.Field,
10802
10757
  {
10803
- thumbnail: item.thumbnail,
10804
- alt: item.title ?? void 0
10758
+ control: form.control,
10759
+ name: "title",
10760
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10761
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10762
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10764
+ ] }),
10765
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10766
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10767
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10768
+ ] })
10769
+ ] }) })
10805
10770
  }
10806
10771
  ),
10807
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10772
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10773
+ /* @__PURE__ */ jsxRuntime.jsx(
10808
10774
  Form$2.Field,
10809
10775
  {
10810
10776
  control: form.control,
10811
- name: "title",
10812
- render: ({ field }) => {
10813
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10814
- }
10777
+ name: "unit_price",
10778
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10779
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10780
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10781
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10782
+ ] }),
10783
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10784
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10785
+ ui.CurrencyInput,
10786
+ {
10787
+ symbol: getNativeSymbol(currencyCode),
10788
+ code: currencyCode,
10789
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10790
+ ...field
10791
+ }
10792
+ ) }),
10793
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10794
+ ] })
10795
+ ] }) })
10815
10796
  }
10816
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10817
- ] }),
10818
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10819
- Form$2.Field,
10820
- {
10821
- control: form.control,
10822
- name: "quantity",
10823
- render: ({ field }) => {
10824
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10797
+ ),
10798
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10799
+ /* @__PURE__ */ jsxRuntime.jsx(
10800
+ Form$2.Field,
10801
+ {
10802
+ control: form.control,
10803
+ name: "quantity",
10804
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10805
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10806
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10807
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10808
+ ] }),
10809
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10810
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
10811
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10812
+ ] })
10813
+ ] }) })
10825
10814
  }
10826
- }
10827
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10828
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10829
- Form$2.Field,
10815
+ )
10816
+ ] }) }) }),
10817
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10818
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10819
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10820
+ ] }) })
10821
+ ] }) }) });
10822
+ };
10823
+ const customItemSchema = objectType({
10824
+ title: stringType().min(1),
10825
+ quantity: numberType(),
10826
+ unit_price: unionType([numberType(), stringType()])
10827
+ });
10828
+ const InlineTip = React.forwardRef(
10829
+ ({ variant = "tip", label, className, children, ...props }, ref) => {
10830
+ const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
10831
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10832
+ "div",
10830
10833
  {
10831
- control: form.control,
10832
- name: "unit_price",
10833
- render: ({ field: { onChange, ...field } }) => {
10834
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10835
- ui.CurrencyInput,
10834
+ ref,
10835
+ className: ui.clx(
10836
+ "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
10837
+ className
10838
+ ),
10839
+ ...props,
10840
+ children: [
10841
+ /* @__PURE__ */ jsxRuntime.jsx(
10842
+ "div",
10836
10843
  {
10837
- ...field,
10838
- symbol: getNativeSymbol(currencyCode),
10839
- code: currencyCode,
10840
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10844
+ role: "presentation",
10845
+ className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
10846
+ "bg-ui-tag-orange-icon": variant === "warning"
10847
+ })
10841
10848
  }
10842
- ) }) });
10843
- }
10844
- }
10845
- ) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 items-center justify-end", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: getLocaleAmount(item.unit_price, currencyCode) }) }),
10846
- /* @__PURE__ */ jsxRuntime.jsx(
10847
- ui.IconButton,
10848
- {
10849
- type: "button",
10850
- size: "small",
10851
- onClick: editing ? onSubmit : () => {
10852
- setEditing(true);
10853
- },
10854
- disabled: isPending,
10855
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10856
- }
10857
- )
10858
- ] }) }) });
10859
- };
10860
- const StackedModalTrigger$1 = ({
10861
- type,
10862
- setModalContent
10863
- }) => {
10864
- const { setIsOpen } = useStackedModal();
10865
- const onClick = React.useCallback(() => {
10866
- setModalContent(type);
10867
- setIsOpen(STACKED_MODAL_ID, true);
10868
- }, [setModalContent, setIsOpen, type]);
10869
- return /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Trigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Item, { onClick, children: type === "add-items" ? "Add items" : "Add custom item" }) });
10870
- };
10871
- const VARIANT_PREFIX = "items";
10872
- const LIMIT = 50;
10873
- const ExistingItemsForm = ({ orderId, items }) => {
10874
- const { setIsOpen } = useStackedModal();
10875
- const [rowSelection, setRowSelection] = React.useState(
10876
- items.reduce((acc, item) => {
10877
- acc[item.variant_id] = true;
10878
- return acc;
10879
- }, {})
10880
- );
10881
- React.useEffect(() => {
10882
- setRowSelection(
10883
- items.reduce((acc, item) => {
10884
- if (item.variant_id) {
10885
- acc[item.variant_id] = true;
10886
- }
10887
- return acc;
10888
- }, {})
10849
+ ),
10850
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
10851
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
10852
+ labelValue,
10853
+ ":"
10854
+ ] }),
10855
+ " ",
10856
+ children
10857
+ ] })
10858
+ ]
10859
+ }
10889
10860
  );
10890
- }, [items]);
10891
- const { q, order, offset } = useQueryParams(
10892
- ["q", "order", "offset"],
10893
- VARIANT_PREFIX
10894
- );
10895
- const { variants, count, isPending, isError, error } = useProductVariants(
10896
- {
10897
- q,
10898
- order,
10899
- offset: offset ? parseInt(offset) : void 0,
10900
- limit: LIMIT
10861
+ }
10862
+ );
10863
+ InlineTip.displayName = "InlineTip";
10864
+ const MetadataFieldSchema = objectType({
10865
+ key: stringType(),
10866
+ disabled: booleanType().optional(),
10867
+ value: anyType()
10868
+ });
10869
+ const MetadataSchema = objectType({
10870
+ metadata: arrayType(MetadataFieldSchema)
10871
+ });
10872
+ const Metadata = () => {
10873
+ const { id } = reactRouterDom.useParams();
10874
+ const { order, isPending, isError, error } = useOrder(id, {
10875
+ fields: "metadata"
10876
+ });
10877
+ if (isError) {
10878
+ throw error;
10879
+ }
10880
+ const isReady = !isPending && !!order;
10881
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10882
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
10883
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
10884
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
10885
+ ] }),
10886
+ !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
10887
+ ] });
10888
+ };
10889
+ const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
10890
+ const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
10891
+ const MetadataForm = ({ orderId, metadata }) => {
10892
+ const { handleSuccess } = useRouteModal();
10893
+ const hasUneditableRows = getHasUneditableRows(metadata);
10894
+ const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
10895
+ const form = reactHookForm.useForm({
10896
+ defaultValues: {
10897
+ metadata: getDefaultValues(metadata)
10901
10898
  },
10902
- {
10903
- placeholderData: reactQuery.keepPreviousData
10904
- }
10905
- );
10906
- const columns = useColumns();
10907
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10908
- const onSubmit = async () => {
10909
- const ids = Object.keys(rowSelection).filter(
10910
- (id) => !items.find((i) => i.variant_id === id)
10911
- );
10899
+ resolver: zod.zodResolver(MetadataSchema)
10900
+ });
10901
+ const handleSubmit = form.handleSubmit(async (data) => {
10902
+ const parsedData = parseValues(data);
10912
10903
  await mutateAsync(
10913
10904
  {
10914
- items: ids.map((id) => ({
10915
- variant_id: id,
10916
- quantity: 1
10917
- }))
10905
+ metadata: parsedData
10918
10906
  },
10919
10907
  {
10920
10908
  onSuccess: () => {
10921
- setRowSelection({});
10922
- setIsOpen(STACKED_MODAL_ID, false);
10909
+ ui.toast.success("Metadata updated");
10910
+ handleSuccess();
10923
10911
  },
10924
- onError: (e) => {
10925
- ui.toast.error(e.message);
10912
+ onError: (error) => {
10913
+ ui.toast.error(error.message);
10926
10914
  }
10927
10915
  }
10928
10916
  );
10929
- };
10930
- if (isError) {
10931
- throw error;
10917
+ });
10918
+ const { fields, insert, remove } = reactHookForm.useFieldArray({
10919
+ control: form.control,
10920
+ name: "metadata"
10921
+ });
10922
+ function deleteRow(index) {
10923
+ remove(index);
10924
+ if (fields.length === 1) {
10925
+ insert(0, {
10926
+ key: "",
10927
+ value: "",
10928
+ disabled: false
10929
+ });
10930
+ }
10932
10931
  }
10933
- return /* @__PURE__ */ jsxRuntime.jsxs(
10934
- StackedFocusModal.Content,
10932
+ function insertRow(index, position) {
10933
+ insert(index + (position === "above" ? 0 : 1), {
10934
+ key: "",
10935
+ value: "",
10936
+ disabled: false
10937
+ });
10938
+ }
10939
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
10940
+ KeyboundForm,
10935
10941
  {
10936
- onOpenAutoFocus: (e) => {
10937
- e.preventDefault();
10938
- const searchInput = document.querySelector(
10939
- "[data-modal-id='modal-search-input']"
10940
- );
10941
- if (searchInput) {
10942
- searchInput.focus();
10943
- }
10944
- },
10942
+ onSubmit: handleSubmit,
10943
+ className: "flex flex-1 flex-col overflow-hidden",
10945
10944
  children: [
10946
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10947
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10948
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10949
- ] }),
10950
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10951
- DataTable,
10952
- {
10953
- data: variants,
10954
- columns,
10955
- isLoading: isPending,
10956
- getRowId: (row) => row.id,
10957
- rowCount: count,
10958
- prefix: VARIANT_PREFIX,
10959
- layout: "fill",
10960
- rowSelection: {
10961
- state: rowSelection,
10962
- onRowSelectionChange: setRowSelection,
10963
- enableRowSelection: (row) => {
10964
- return !items.find((i) => i.variant_id === row.original.id);
10945
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
10946
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
10947
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
10948
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_KEY_LABEL_ID, children: "Key" }) }),
10949
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "txt-compact-small-plus text-ui-fg-subtle px-2 py-1.5", children: /* @__PURE__ */ jsxRuntime.jsx("label", { id: METADATA_VALUE_LABEL_ID, children: "Value" }) })
10950
+ ] }),
10951
+ fields.map((field, index) => {
10952
+ const isDisabled = field.disabled || false;
10953
+ let placeholder = "-";
10954
+ if (typeof field.value === "object") {
10955
+ placeholder = "{ ... }";
10965
10956
  }
10966
- },
10967
- autoFocusSearch: true
10968
- }
10969
- ) }),
10970
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10971
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10972
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10957
+ if (Array.isArray(field.value)) {
10958
+ placeholder = "[ ... ]";
10959
+ }
10960
+ return /* @__PURE__ */ jsxRuntime.jsx(
10961
+ ConditionalTooltip,
10962
+ {
10963
+ showTooltip: isDisabled,
10964
+ content: "This row is disabled because it contains non-primitive data.",
10965
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
10966
+ /* @__PURE__ */ jsxRuntime.jsxs(
10967
+ "div",
10968
+ {
10969
+ className: ui.clx("grid grid-cols-2 divide-x", {
10970
+ "overflow-hidden rounded-b-lg": index === fields.length - 1
10971
+ }),
10972
+ children: [
10973
+ /* @__PURE__ */ jsxRuntime.jsx(
10974
+ Form$2.Field,
10975
+ {
10976
+ control: form.control,
10977
+ name: `metadata.${index}.key`,
10978
+ render: ({ field: field2 }) => {
10979
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10980
+ GridInput,
10981
+ {
10982
+ "aria-labelledby": METADATA_KEY_LABEL_ID,
10983
+ ...field2,
10984
+ disabled: isDisabled,
10985
+ placeholder: "Key"
10986
+ }
10987
+ ) }) });
10988
+ }
10989
+ }
10990
+ ),
10991
+ /* @__PURE__ */ jsxRuntime.jsx(
10992
+ Form$2.Field,
10993
+ {
10994
+ control: form.control,
10995
+ name: `metadata.${index}.value`,
10996
+ render: ({ field: { value, ...field2 } }) => {
10997
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10998
+ GridInput,
10999
+ {
11000
+ "aria-labelledby": METADATA_VALUE_LABEL_ID,
11001
+ ...field2,
11002
+ value: isDisabled ? placeholder : value,
11003
+ disabled: isDisabled,
11004
+ placeholder: "Value"
11005
+ }
11006
+ ) }) });
11007
+ }
11008
+ }
11009
+ )
11010
+ ]
11011
+ }
11012
+ ),
11013
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
11014
+ /* @__PURE__ */ jsxRuntime.jsx(
11015
+ ui.DropdownMenu.Trigger,
11016
+ {
11017
+ className: ui.clx(
11018
+ "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
11019
+ {
11020
+ hidden: isDisabled
11021
+ }
11022
+ ),
11023
+ disabled: isDisabled,
11024
+ asChild: true,
11025
+ children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
11026
+ }
11027
+ ),
11028
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
11029
+ /* @__PURE__ */ jsxRuntime.jsxs(
11030
+ ui.DropdownMenu.Item,
11031
+ {
11032
+ className: "gap-x-2",
11033
+ onClick: () => insertRow(index, "above"),
11034
+ children: [
11035
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
11036
+ "Insert row above"
11037
+ ]
11038
+ }
11039
+ ),
11040
+ /* @__PURE__ */ jsxRuntime.jsxs(
11041
+ ui.DropdownMenu.Item,
11042
+ {
11043
+ className: "gap-x-2",
11044
+ onClick: () => insertRow(index, "below"),
11045
+ children: [
11046
+ /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
11047
+ "Insert row below"
11048
+ ]
11049
+ }
11050
+ ),
11051
+ /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
11052
+ /* @__PURE__ */ jsxRuntime.jsxs(
11053
+ ui.DropdownMenu.Item,
11054
+ {
11055
+ className: "gap-x-2",
11056
+ onClick: () => deleteRow(index),
11057
+ children: [
11058
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
11059
+ "Delete row"
11060
+ ]
11061
+ }
11062
+ )
11063
+ ] })
11064
+ ] })
11065
+ ] })
11066
+ },
11067
+ field.id
11068
+ );
11069
+ })
11070
+ ] }),
11071
+ hasUneditableRows && /* @__PURE__ */ jsxRuntime.jsx(InlineTip, { variant: "warning", label: "Some rows are disabled", children: "This object contains non-primitive metadata, such as arrays or objects, that can't be edited here. To edit the disabled rows, use the API directly." })
11072
+ ] }),
11073
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11074
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11075
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10973
11076
  ] }) })
10974
11077
  ]
10975
11078
  }
11079
+ ) });
11080
+ };
11081
+ const GridInput = React.forwardRef(({ className, ...props }, ref) => {
11082
+ return /* @__PURE__ */ jsxRuntime.jsx(
11083
+ "input",
11084
+ {
11085
+ ref,
11086
+ ...props,
11087
+ autoComplete: "off",
11088
+ className: ui.clx(
11089
+ "txt-compact-small text-ui-fg-base placeholder:text-ui-fg-muted disabled:text-ui-fg-disabled disabled:bg-ui-bg-base bg-transparent px-2 py-1.5 outline-none",
11090
+ className
11091
+ )
11092
+ }
10976
11093
  );
11094
+ });
11095
+ GridInput.displayName = "MetadataForm.GridInput";
11096
+ const PlaceholderInner = () => {
11097
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
11098
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
11099
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11100
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
11101
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
11102
+ ] }) })
11103
+ ] });
10977
11104
  };
10978
- const columnHelper = ui.createDataTableColumnHelper();
10979
- const useColumns = () => {
10980
- return React.useMemo(() => {
11105
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11106
+ function getDefaultValues(metadata) {
11107
+ if (!metadata || !Object.keys(metadata).length) {
10981
11108
  return [
10982
- columnHelper.select(),
10983
- columnHelper.accessor("product.title", {
10984
- header: "Product",
10985
- cell: ({ row }) => {
10986
- var _a, _b, _c;
10987
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10988
- /* @__PURE__ */ jsxRuntime.jsx(
10989
- Thumbnail,
10990
- {
10991
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10992
- alt: (_b = row.original.product) == null ? void 0 : _b.title
10993
- }
10994
- ),
10995
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10996
- ] });
10997
- },
10998
- enableSorting: true
10999
- }),
11000
- columnHelper.accessor("title", {
11001
- header: "Variant",
11002
- enableSorting: true
11003
- }),
11004
- columnHelper.accessor("sku", {
11005
- header: "SKU",
11006
- cell: ({ getValue }) => {
11007
- return getValue() ?? "-";
11008
- },
11009
- enableSorting: true
11010
- }),
11011
- columnHelper.accessor("updated_at", {
11012
- header: "Updated",
11013
- cell: ({ getValue }) => {
11014
- return /* @__PURE__ */ jsxRuntime.jsx(
11015
- ui.Tooltip,
11016
- {
11017
- content: getFullDate({ date: getValue(), includeTime: true }),
11018
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11019
- }
11020
- );
11021
- },
11022
- enableSorting: true,
11023
- sortAscLabel: "Oldest first",
11024
- sortDescLabel: "Newest first"
11025
- }),
11026
- columnHelper.accessor("created_at", {
11027
- header: "Created",
11028
- cell: ({ getValue }) => {
11029
- return /* @__PURE__ */ jsxRuntime.jsx(
11030
- ui.Tooltip,
11031
- {
11032
- content: getFullDate({ date: getValue(), includeTime: true }),
11033
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11034
- }
11035
- );
11036
- },
11037
- enableSorting: true,
11038
- sortAscLabel: "Oldest first",
11039
- sortDescLabel: "Newest first"
11040
- })
11041
- ];
11042
- }, []);
11043
- };
11044
- const CustomItemForm = ({ orderId, currencyCode }) => {
11045
- const { setIsOpen } = useStackedModal();
11046
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11047
- const form = reactHookForm.useForm({
11048
- defaultValues: {
11049
- title: "",
11050
- quantity: 1,
11051
- unit_price: ""
11052
- },
11053
- resolver: zod.zodResolver(customItemSchema)
11054
- });
11055
- const onSubmit = form.handleSubmit(async (data) => {
11056
- await addItems(
11057
- {
11058
- items: [
11059
- {
11060
- title: data.title,
11061
- quantity: data.quantity,
11062
- unit_price: convertNumber(data.unit_price)
11063
- }
11064
- ]
11065
- },
11066
11109
  {
11067
- onSuccess: () => {
11068
- setIsOpen(STACKED_MODAL_ID, false);
11069
- },
11070
- onError: (e) => {
11071
- ui.toast.error(e.message);
11072
- }
11110
+ key: "",
11111
+ value: "",
11112
+ disabled: false
11073
11113
  }
11074
- );
11114
+ ];
11115
+ }
11116
+ return Object.entries(metadata).map(([key, value]) => {
11117
+ if (!EDITABLE_TYPES.includes(typeof value)) {
11118
+ return {
11119
+ key,
11120
+ value,
11121
+ disabled: true
11122
+ };
11123
+ }
11124
+ let stringValue = value;
11125
+ if (typeof value !== "string") {
11126
+ stringValue = JSON.stringify(value);
11127
+ }
11128
+ return {
11129
+ key,
11130
+ value: stringValue,
11131
+ original_key: key
11132
+ };
11075
11133
  });
11076
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11077
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11078
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex flex-1 flex-col overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full max-w-[720px] flex-col gap-y-6 px-2 py-16", children: [
11079
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11080
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
11081
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", className: "text-ui-fg-subtle", children: "Add a custom item to the order. This will add a new line item that is not associated with an existing product." }) })
11082
- ] }),
11083
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11084
- /* @__PURE__ */ jsxRuntime.jsx(
11085
- Form$2.Field,
11086
- {
11087
- control: form.control,
11088
- name: "title",
11089
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11090
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11091
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
11092
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
11093
- ] }),
11094
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11095
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11096
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11097
- ] })
11098
- ] }) })
11099
- }
11100
- ),
11101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11102
- /* @__PURE__ */ jsxRuntime.jsx(
11103
- Form$2.Field,
11104
- {
11105
- control: form.control,
11106
- name: "unit_price",
11107
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11108
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11109
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
11110
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11111
- ] }),
11112
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11113
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11114
- ui.CurrencyInput,
11115
- {
11116
- symbol: getNativeSymbol(currencyCode),
11117
- code: currencyCode,
11118
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11119
- ...field
11120
- }
11121
- ) }),
11122
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11123
- ] })
11124
- ] }) })
11125
- }
11126
- ),
11127
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11128
- /* @__PURE__ */ jsxRuntime.jsx(
11129
- Form$2.Field,
11130
- {
11131
- control: form.control,
11132
- name: "quantity",
11133
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11134
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11135
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
11136
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11137
- ] }),
11138
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
11139
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field, className: "w-full" }) }) }),
11140
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11141
- ] })
11142
- ] }) })
11143
- }
11144
- )
11145
- ] }) }) }),
11146
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11147
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11148
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11149
- ] }) })
11150
- ] }) }) });
11151
- };
11152
- const customItemSchema = objectType({
11153
- title: stringType().min(1),
11154
- quantity: numberType(),
11155
- unit_price: unionType([numberType(), stringType()])
11156
- });
11157
- const CustomItems = () => {
11158
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
11159
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
11160
- /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
11161
- ] });
11162
- };
11163
- const CustomItemsForm = () => {
11164
- const form = reactHookForm.useForm({
11165
- resolver: zod.zodResolver(schema$3)
11134
+ }
11135
+ function parseValues(values) {
11136
+ const metadata = values.metadata;
11137
+ const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
11138
+ if (isEmpty) {
11139
+ return null;
11140
+ }
11141
+ const update = {};
11142
+ metadata.forEach((field) => {
11143
+ let key = field.key;
11144
+ let value = field.value;
11145
+ const disabled = field.disabled;
11146
+ if (!key || !value) {
11147
+ return;
11148
+ }
11149
+ if (disabled) {
11150
+ update[key] = value;
11151
+ return;
11152
+ }
11153
+ key = key.trim();
11154
+ value = value.trim();
11155
+ if (value === "true") {
11156
+ update[key] = true;
11157
+ } else if (value === "false") {
11158
+ update[key] = false;
11159
+ } else {
11160
+ const parsedNumber = parseFloat(value);
11161
+ if (!isNaN(parsedNumber)) {
11162
+ update[key] = parsedNumber;
11163
+ } else {
11164
+ update[key] = value;
11165
+ }
11166
+ }
11166
11167
  });
11167
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
11168
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
11169
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
11170
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
11171
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
11172
- ] }) })
11173
- ] }) });
11174
- };
11175
- const schema$3 = objectType({
11176
- email: stringType().email()
11177
- });
11168
+ return update;
11169
+ }
11170
+ function getHasUneditableRows(metadata) {
11171
+ if (!metadata) {
11172
+ return false;
11173
+ }
11174
+ return Object.values(metadata).some(
11175
+ (value) => !EDITABLE_TYPES.includes(typeof value)
11176
+ );
11177
+ }
11178
11178
  const PROMOTION_QUERY_KEY = "promotions";
11179
11179
  const promotionsQueryKeys = {
11180
11180
  list: (query2) => [
@@ -12344,230 +12344,27 @@ const CustomAmountField = ({
12344
12344
  Form$2.Field,
12345
12345
  {
12346
12346
  control,
12347
- name: "custom_amount",
12348
- render: ({ field: { onChange, ...field } }) => {
12349
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12350
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12351
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12352
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12353
- ] }),
12354
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12355
- ui.CurrencyInput,
12356
- {
12357
- ...field,
12358
- onValueChange: (value) => onChange(value),
12359
- symbol: getNativeSymbol(currencyCode),
12360
- code: currencyCode
12361
- }
12362
- ) })
12363
- ] });
12364
- }
12365
- }
12366
- );
12367
- };
12368
- const ShippingAddress = () => {
12369
- const { id } = reactRouterDom.useParams();
12370
- const { order, isPending, isError, error } = useOrder(id, {
12371
- fields: "+shipping_address"
12372
- });
12373
- if (isError) {
12374
- throw error;
12375
- }
12376
- const isReady = !isPending && !!order;
12377
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12378
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12379
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12380
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12381
- ] }),
12382
- isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12383
- ] });
12384
- };
12385
- const ShippingAddressForm = ({ order }) => {
12386
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12387
- const form = reactHookForm.useForm({
12388
- defaultValues: {
12389
- first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12390
- last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12391
- company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12392
- address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12393
- address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12394
- city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12395
- province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12396
- country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12397
- postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12398
- phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12399
- },
12400
- resolver: zod.zodResolver(schema$1)
12401
- });
12402
- const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12403
- const { handleSuccess } = useRouteModal();
12404
- const onSubmit = form.handleSubmit(async (data) => {
12405
- await mutateAsync(
12406
- {
12407
- shipping_address: {
12408
- first_name: data.first_name,
12409
- last_name: data.last_name,
12410
- company: data.company,
12411
- address_1: data.address_1,
12412
- address_2: data.address_2,
12413
- city: data.city,
12414
- province: data.province,
12415
- country_code: data.country_code,
12416
- postal_code: data.postal_code,
12417
- phone: data.phone
12418
- }
12419
- },
12420
- {
12421
- onSuccess: () => {
12422
- handleSuccess();
12423
- },
12424
- onError: (error) => {
12425
- ui.toast.error(error.message);
12426
- }
12427
- }
12428
- );
12429
- });
12430
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12431
- KeyboundForm,
12432
- {
12433
- className: "flex flex-1 flex-col overflow-hidden",
12434
- onSubmit,
12435
- children: [
12436
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12437
- /* @__PURE__ */ jsxRuntime.jsx(
12438
- Form$2.Field,
12439
- {
12440
- control: form.control,
12441
- name: "country_code",
12442
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12443
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12444
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12445
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12446
- ] })
12447
- }
12448
- ),
12449
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12450
- /* @__PURE__ */ jsxRuntime.jsx(
12451
- Form$2.Field,
12452
- {
12453
- control: form.control,
12454
- name: "first_name",
12455
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12456
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12457
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12458
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12459
- ] })
12460
- }
12461
- ),
12462
- /* @__PURE__ */ jsxRuntime.jsx(
12463
- Form$2.Field,
12464
- {
12465
- control: form.control,
12466
- name: "last_name",
12467
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12468
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12469
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12470
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12471
- ] })
12472
- }
12473
- )
12474
- ] }),
12475
- /* @__PURE__ */ jsxRuntime.jsx(
12476
- Form$2.Field,
12477
- {
12478
- control: form.control,
12479
- name: "company",
12480
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12481
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12482
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12483
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12484
- ] })
12485
- }
12486
- ),
12487
- /* @__PURE__ */ jsxRuntime.jsx(
12488
- Form$2.Field,
12489
- {
12490
- control: form.control,
12491
- name: "address_1",
12492
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12493
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12494
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12495
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12496
- ] })
12497
- }
12498
- ),
12499
- /* @__PURE__ */ jsxRuntime.jsx(
12500
- Form$2.Field,
12501
- {
12502
- control: form.control,
12503
- name: "address_2",
12504
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12505
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12506
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12507
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12508
- ] })
12509
- }
12510
- ),
12511
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12512
- /* @__PURE__ */ jsxRuntime.jsx(
12513
- Form$2.Field,
12514
- {
12515
- control: form.control,
12516
- name: "postal_code",
12517
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12518
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12519
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12520
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12521
- ] })
12522
- }
12523
- ),
12524
- /* @__PURE__ */ jsxRuntime.jsx(
12525
- Form$2.Field,
12526
- {
12527
- control: form.control,
12528
- name: "city",
12529
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12530
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
12531
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12532
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12533
- ] })
12534
- }
12535
- )
12536
- ] }),
12537
- /* @__PURE__ */ jsxRuntime.jsx(
12538
- Form$2.Field,
12539
- {
12540
- control: form.control,
12541
- name: "province",
12542
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12543
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
12544
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12545
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12546
- ] })
12547
- }
12548
- ),
12549
- /* @__PURE__ */ jsxRuntime.jsx(
12550
- Form$2.Field,
12347
+ name: "custom_amount",
12348
+ render: ({ field: { onChange, ...field } }) => {
12349
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12350
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
12351
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Custom amount" }),
12352
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Set a custom amount for the shipping option." })
12353
+ ] }),
12354
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
12355
+ ui.CurrencyInput,
12551
12356
  {
12552
- control: form.control,
12553
- name: "phone",
12554
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12555
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
12556
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12557
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12558
- ] })
12357
+ ...field,
12358
+ onValueChange: (value) => onChange(value),
12359
+ symbol: getNativeSymbol(currencyCode),
12360
+ code: currencyCode
12559
12361
  }
12560
- )
12561
- ] }) }),
12562
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
12563
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
12564
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
12565
- ] }) })
12566
- ]
12362
+ ) })
12363
+ ] });
12364
+ }
12567
12365
  }
12568
- ) });
12366
+ );
12569
12367
  };
12570
- const schema$1 = addressSchema;
12571
12368
  const TransferOwnership = () => {
12572
12369
  const { id } = reactRouterDom.useParams();
12573
12370
  const { draft_order, isPending, isError, error } = useDraftOrder(id, {
@@ -12591,7 +12388,7 @@ const TransferOwnershipForm = ({ order }) => {
12591
12388
  defaultValues: {
12592
12389
  customer_id: order.customer_id || ""
12593
12390
  },
12594
- resolver: zod.zodResolver(schema)
12391
+ resolver: zod.zodResolver(schema$1)
12595
12392
  });
12596
12393
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12597
12394
  const { handleSuccess } = useRouteModal();
@@ -13041,9 +12838,212 @@ const Illustration = () => {
13041
12838
  }
13042
12839
  );
13043
12840
  };
13044
- const schema = objectType({
12841
+ const schema$1 = objectType({
13045
12842
  customer_id: stringType().min(1)
13046
12843
  });
12844
+ const ShippingAddress = () => {
12845
+ const { id } = reactRouterDom.useParams();
12846
+ const { order, isPending, isError, error } = useOrder(id, {
12847
+ fields: "+shipping_address"
12848
+ });
12849
+ if (isError) {
12850
+ throw error;
12851
+ }
12852
+ const isReady = !isPending && !!order;
12853
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
12854
+ /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
12855
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Shipping Address" }) }),
12856
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Edit the shipping address for the draft order" }) })
12857
+ ] }),
12858
+ isReady && /* @__PURE__ */ jsxRuntime.jsx(ShippingAddressForm, { order })
12859
+ ] });
12860
+ };
12861
+ const ShippingAddressForm = ({ order }) => {
12862
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
12863
+ const form = reactHookForm.useForm({
12864
+ defaultValues: {
12865
+ first_name: ((_a = order.shipping_address) == null ? void 0 : _a.first_name) ?? "",
12866
+ last_name: ((_b = order.shipping_address) == null ? void 0 : _b.last_name) ?? "",
12867
+ company: ((_c = order.shipping_address) == null ? void 0 : _c.company) ?? "",
12868
+ address_1: ((_d = order.shipping_address) == null ? void 0 : _d.address_1) ?? "",
12869
+ address_2: ((_e = order.shipping_address) == null ? void 0 : _e.address_2) ?? "",
12870
+ city: ((_f = order.shipping_address) == null ? void 0 : _f.city) ?? "",
12871
+ province: ((_g = order.shipping_address) == null ? void 0 : _g.province) ?? "",
12872
+ country_code: ((_h = order.shipping_address) == null ? void 0 : _h.country_code) ?? "",
12873
+ postal_code: ((_i = order.shipping_address) == null ? void 0 : _i.postal_code) ?? "",
12874
+ phone: ((_j = order.shipping_address) == null ? void 0 : _j.phone) ?? ""
12875
+ },
12876
+ resolver: zod.zodResolver(schema)
12877
+ });
12878
+ const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
12879
+ const { handleSuccess } = useRouteModal();
12880
+ const onSubmit = form.handleSubmit(async (data) => {
12881
+ await mutateAsync(
12882
+ {
12883
+ shipping_address: {
12884
+ first_name: data.first_name,
12885
+ last_name: data.last_name,
12886
+ company: data.company,
12887
+ address_1: data.address_1,
12888
+ address_2: data.address_2,
12889
+ city: data.city,
12890
+ province: data.province,
12891
+ country_code: data.country_code,
12892
+ postal_code: data.postal_code,
12893
+ phone: data.phone
12894
+ }
12895
+ },
12896
+ {
12897
+ onSuccess: () => {
12898
+ handleSuccess();
12899
+ },
12900
+ onError: (error) => {
12901
+ ui.toast.error(error.message);
12902
+ }
12903
+ }
12904
+ );
12905
+ });
12906
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
12907
+ KeyboundForm,
12908
+ {
12909
+ className: "flex flex-1 flex-col overflow-hidden",
12910
+ onSubmit,
12911
+ children: [
12912
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { className: "flex flex-col gap-y-6 overflow-y-auto", children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-y-4", children: [
12913
+ /* @__PURE__ */ jsxRuntime.jsx(
12914
+ Form$2.Field,
12915
+ {
12916
+ control: form.control,
12917
+ name: "country_code",
12918
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12919
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Country" }),
12920
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(CountrySelect, { ...field }) }),
12921
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12922
+ ] })
12923
+ }
12924
+ ),
12925
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12926
+ /* @__PURE__ */ jsxRuntime.jsx(
12927
+ Form$2.Field,
12928
+ {
12929
+ control: form.control,
12930
+ name: "first_name",
12931
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12932
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "First name" }),
12933
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12934
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12935
+ ] })
12936
+ }
12937
+ ),
12938
+ /* @__PURE__ */ jsxRuntime.jsx(
12939
+ Form$2.Field,
12940
+ {
12941
+ control: form.control,
12942
+ name: "last_name",
12943
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12944
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Last name" }),
12945
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12946
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12947
+ ] })
12948
+ }
12949
+ )
12950
+ ] }),
12951
+ /* @__PURE__ */ jsxRuntime.jsx(
12952
+ Form$2.Field,
12953
+ {
12954
+ control: form.control,
12955
+ name: "company",
12956
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12957
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Company" }),
12958
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12959
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12960
+ ] })
12961
+ }
12962
+ ),
12963
+ /* @__PURE__ */ jsxRuntime.jsx(
12964
+ Form$2.Field,
12965
+ {
12966
+ control: form.control,
12967
+ name: "address_1",
12968
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12969
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Address" }),
12970
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12971
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12972
+ ] })
12973
+ }
12974
+ ),
12975
+ /* @__PURE__ */ jsxRuntime.jsx(
12976
+ Form$2.Field,
12977
+ {
12978
+ control: form.control,
12979
+ name: "address_2",
12980
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12981
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Apartment, suite, etc." }),
12982
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12983
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12984
+ ] })
12985
+ }
12986
+ ),
12987
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-4", children: [
12988
+ /* @__PURE__ */ jsxRuntime.jsx(
12989
+ Form$2.Field,
12990
+ {
12991
+ control: form.control,
12992
+ name: "postal_code",
12993
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
12994
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Postal code" }),
12995
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
12996
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
12997
+ ] })
12998
+ }
12999
+ ),
13000
+ /* @__PURE__ */ jsxRuntime.jsx(
13001
+ Form$2.Field,
13002
+ {
13003
+ control: form.control,
13004
+ name: "city",
13005
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13006
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "City" }),
13007
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13008
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13009
+ ] })
13010
+ }
13011
+ )
13012
+ ] }),
13013
+ /* @__PURE__ */ jsxRuntime.jsx(
13014
+ Form$2.Field,
13015
+ {
13016
+ control: form.control,
13017
+ name: "province",
13018
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13019
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Province / State" }),
13020
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13021
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13022
+ ] })
13023
+ }
13024
+ ),
13025
+ /* @__PURE__ */ jsxRuntime.jsx(
13026
+ Form$2.Field,
13027
+ {
13028
+ control: form.control,
13029
+ name: "phone",
13030
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsxs(Form$2.Item, { children: [
13031
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { optional: true, children: "Phone" }),
13032
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
13033
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
13034
+ ] })
13035
+ }
13036
+ )
13037
+ ] }) }),
13038
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
13039
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
13040
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
13041
+ ] }) })
13042
+ ]
13043
+ }
13044
+ ) });
13045
+ };
13046
+ const schema = addressSchema;
13047
13047
  const widgetModule = { widgets: [] };
13048
13048
  const routeModule = {
13049
13049
  routes: [
@@ -13069,20 +13069,20 @@ const routeModule = {
13069
13069
  path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
13071
  {
13072
- Component: Email,
13073
- path: "/draft-orders/:id/email"
13072
+ Component: CustomItems,
13073
+ path: "/draft-orders/:id/custom-items"
13074
13074
  },
13075
13075
  {
13076
- Component: Metadata,
13077
- path: "/draft-orders/:id/metadata"
13076
+ Component: Email,
13077
+ path: "/draft-orders/:id/email"
13078
13078
  },
13079
13079
  {
13080
13080
  Component: Items,
13081
13081
  path: "/draft-orders/:id/items"
13082
13082
  },
13083
13083
  {
13084
- Component: CustomItems,
13085
- path: "/draft-orders/:id/custom-items"
13084
+ Component: Metadata,
13085
+ path: "/draft-orders/:id/metadata"
13086
13086
  },
13087
13087
  {
13088
13088
  Component: Promotions,
@@ -13096,13 +13096,13 @@ const routeModule = {
13096
13096
  Component: Shipping,
13097
13097
  path: "/draft-orders/:id/shipping"
13098
13098
  },
13099
- {
13100
- Component: ShippingAddress,
13101
- path: "/draft-orders/:id/shipping-address"
13102
- },
13103
13099
  {
13104
13100
  Component: TransferOwnership,
13105
13101
  path: "/draft-orders/:id/transfer-ownership"
13102
+ },
13103
+ {
13104
+ Component: ShippingAddress,
13105
+ path: "/draft-orders/:id/shipping-address"
13106
13106
  }
13107
13107
  ]
13108
13108
  }