@medusajs/draft-order 2.12.2-preview-20251204090232 → 2.12.2-preview-20251204150146

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,27 +9762,6 @@ 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
- });
9786
9765
  const Email = () => {
9787
9766
  const { id } = reactRouterDom.useParams();
9788
9767
  const { order, isPending, isError, error } = useOrder(id, {
@@ -9805,7 +9784,7 @@ const EmailForm = ({ order }) => {
9805
9784
  defaultValues: {
9806
9785
  email: order.email ?? ""
9807
9786
  },
9808
- resolver: zod.zodResolver(schema$3)
9787
+ resolver: zod.zodResolver(schema$4)
9809
9788
  });
9810
9789
  const { mutateAsync, isPending } = useUpdateDraftOrder(order.id);
9811
9790
  const { handleSuccess } = useRouteModal();
@@ -9848,526 +9827,176 @@ const EmailForm = ({ order }) => {
9848
9827
  }
9849
9828
  ) });
9850
9829
  };
9851
- const schema$3 = objectType({
9830
+ const schema$4 = objectType({
9852
9831
  email: stringType().email()
9853
9832
  });
9854
- const InlineTip = React.forwardRef(
9855
- ({ variant = "tip", label, className, children, ...props }, ref) => {
9856
- const labelValue = label || (variant === "warning" ? "Warning" : "Tip");
9833
+ const NumberInput = React.forwardRef(
9834
+ ({
9835
+ value,
9836
+ onChange,
9837
+ size = "base",
9838
+ min = 0,
9839
+ max = 100,
9840
+ step = 1,
9841
+ className,
9842
+ disabled,
9843
+ ...props
9844
+ }, ref) => {
9845
+ const handleChange = (event) => {
9846
+ const newValue = event.target.value === "" ? min : Number(event.target.value);
9847
+ if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
9848
+ onChange(newValue);
9849
+ }
9850
+ };
9851
+ const handleIncrement = () => {
9852
+ const newValue = value + step;
9853
+ if (max === void 0 || newValue <= max) {
9854
+ onChange(newValue);
9855
+ }
9856
+ };
9857
+ const handleDecrement = () => {
9858
+ const newValue = value - step;
9859
+ if (min === void 0 || newValue >= min) {
9860
+ onChange(newValue);
9861
+ }
9862
+ };
9857
9863
  return /* @__PURE__ */ jsxRuntime.jsxs(
9858
9864
  "div",
9859
9865
  {
9860
- ref,
9861
9866
  className: ui.clx(
9862
- "bg-ui-bg-component txt-small text-ui-fg-subtle grid grid-cols-[4px_1fr] items-start gap-3 rounded-lg border p-3",
9867
+ "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
9868
+ "[&:has(input:focus)]:shadow-borders-interactive-with-active",
9869
+ {
9870
+ "h-7": size === "small",
9871
+ "h-8": size === "base"
9872
+ },
9863
9873
  className
9864
9874
  ),
9865
- ...props,
9866
9875
  children: [
9867
9876
  /* @__PURE__ */ jsxRuntime.jsx(
9868
- "div",
9877
+ "input",
9869
9878
  {
9870
- role: "presentation",
9871
- className: ui.clx("w-4px bg-ui-tag-neutral-icon h-full rounded-full", {
9872
- "bg-ui-tag-orange-icon": variant === "warning"
9873
- })
9879
+ ref,
9880
+ type: "number",
9881
+ value,
9882
+ onChange: handleChange,
9883
+ min,
9884
+ max,
9885
+ step,
9886
+ className: ui.clx(
9887
+ "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
9888
+ "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
9889
+ "placeholder:text-ui-fg-muted"
9890
+ ),
9891
+ ...props
9874
9892
  }
9875
9893
  ),
9876
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "text-pretty", children: [
9877
- /* @__PURE__ */ jsxRuntime.jsxs("strong", { className: "txt-small-plus text-ui-fg-base", children: [
9878
- labelValue,
9879
- ":"
9880
- ] }),
9881
- " ",
9882
- children
9883
- ] })
9894
+ /* @__PURE__ */ jsxRuntime.jsxs(
9895
+ "button",
9896
+ {
9897
+ className: ui.clx(
9898
+ "flex items-center justify-center outline-none transition-fg",
9899
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9900
+ "focus:bg-ui-bg-field-component-hover",
9901
+ "hover:bg-ui-bg-field-component-hover",
9902
+ {
9903
+ "size-7": size === "small",
9904
+ "size-8": size === "base"
9905
+ }
9906
+ ),
9907
+ type: "button",
9908
+ onClick: handleDecrement,
9909
+ disabled: min !== void 0 && value <= min || disabled,
9910
+ children: [
9911
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
9912
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
9913
+ ]
9914
+ }
9915
+ ),
9916
+ /* @__PURE__ */ jsxRuntime.jsxs(
9917
+ "button",
9918
+ {
9919
+ className: ui.clx(
9920
+ "flex items-center justify-center outline-none transition-fg",
9921
+ "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
9922
+ "focus:bg-ui-bg-field-hover",
9923
+ "hover:bg-ui-bg-field-hover",
9924
+ {
9925
+ "size-7": size === "small",
9926
+ "size-8": size === "base"
9927
+ }
9928
+ ),
9929
+ type: "button",
9930
+ onClick: handleIncrement,
9931
+ disabled: max !== void 0 && value >= max || disabled,
9932
+ children: [
9933
+ /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
9934
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
9935
+ ]
9936
+ }
9937
+ )
9884
9938
  ]
9885
9939
  }
9886
9940
  );
9887
9941
  }
9888
9942
  );
9889
- InlineTip.displayName = "InlineTip";
9890
- const MetadataFieldSchema = objectType({
9891
- key: stringType(),
9892
- disabled: booleanType().optional(),
9893
- value: anyType()
9894
- });
9895
- const MetadataSchema = objectType({
9896
- metadata: arrayType(MetadataFieldSchema)
9897
- });
9898
- const Metadata = () => {
9899
- const { id } = reactRouterDom.useParams();
9900
- const { order, isPending, isError, error } = useOrder(id, {
9901
- fields: "metadata"
9902
- });
9903
- if (isError) {
9904
- throw error;
9905
- }
9906
- const isReady = !isPending && !!order;
9907
- return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
9908
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Header, { children: [
9909
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Metadata" }) }),
9910
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Add metadata to the draft order." }) })
9911
- ] }),
9912
- !isReady ? /* @__PURE__ */ jsxRuntime.jsx(PlaceholderInner, {}) : /* @__PURE__ */ jsxRuntime.jsx(MetadataForm, { orderId: id, metadata: order == null ? void 0 : order.metadata })
9913
- ] });
9943
+ const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
9944
+ const productVariantsQueryKeys = {
9945
+ list: (query2) => [
9946
+ PRODUCT_VARIANTS_QUERY_KEY,
9947
+ query2 ? query2 : void 0
9948
+ ]
9914
9949
  };
9915
- const METADATA_KEY_LABEL_ID = "metadata-form-key-label";
9916
- const METADATA_VALUE_LABEL_ID = "metadata-form-value-label";
9917
- const MetadataForm = ({ orderId, metadata }) => {
9918
- const { handleSuccess } = useRouteModal();
9919
- const hasUneditableRows = getHasUneditableRows(metadata);
9920
- const { mutateAsync, isPending } = useUpdateDraftOrder(orderId);
9921
- const form = reactHookForm.useForm({
9922
- defaultValues: {
9923
- metadata: getDefaultValues(metadata)
9924
- },
9925
- resolver: zod.zodResolver(MetadataSchema)
9950
+ const useProductVariants = (query2, options) => {
9951
+ const { data, ...rest } = reactQuery.useQuery({
9952
+ queryKey: productVariantsQueryKeys.list(query2),
9953
+ queryFn: async () => await sdk.admin.productVariant.list(query2),
9954
+ ...options
9926
9955
  });
9927
- const handleSubmit = form.handleSubmit(async (data) => {
9928
- const parsedData = parseValues(data);
9929
- await mutateAsync(
9930
- {
9931
- metadata: parsedData
9956
+ return { ...data, ...rest };
9957
+ };
9958
+ const useCancelOrderEdit = ({ preview }) => {
9959
+ const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
9960
+ const onCancel = React.useCallback(async () => {
9961
+ if (!preview) {
9962
+ return true;
9963
+ }
9964
+ let res = false;
9965
+ await cancelOrderEdit(void 0, {
9966
+ onError: (e) => {
9967
+ ui.toast.error(e.message);
9932
9968
  },
9933
- {
9934
- onSuccess: () => {
9935
- ui.toast.success("Metadata updated");
9936
- handleSuccess();
9937
- },
9938
- onError: (error) => {
9939
- ui.toast.error(error.message);
9940
- }
9969
+ onSuccess: () => {
9970
+ res = true;
9941
9971
  }
9942
- );
9943
- });
9944
- const { fields, insert, remove } = reactHookForm.useFieldArray({
9945
- control: form.control,
9946
- name: "metadata"
9947
- });
9948
- function deleteRow(index) {
9949
- remove(index);
9950
- if (fields.length === 1) {
9951
- insert(0, {
9952
- key: "",
9953
- value: "",
9954
- disabled: false
9972
+ });
9973
+ return res;
9974
+ }, [preview, cancelOrderEdit]);
9975
+ return { onCancel };
9976
+ };
9977
+ let IS_REQUEST_RUNNING = false;
9978
+ const useInitiateOrderEdit = ({
9979
+ preview
9980
+ }) => {
9981
+ const navigate = reactRouterDom.useNavigate();
9982
+ const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
9983
+ React.useEffect(() => {
9984
+ async function run() {
9985
+ if (IS_REQUEST_RUNNING || !preview) {
9986
+ return;
9987
+ }
9988
+ if (preview.order_change) {
9989
+ return;
9990
+ }
9991
+ IS_REQUEST_RUNNING = true;
9992
+ await mutateAsync(void 0, {
9993
+ onError: (e) => {
9994
+ ui.toast.error(e.message);
9995
+ navigate(`/draft-orders/${preview.id}`, { replace: true });
9996
+ return;
9997
+ }
9955
9998
  });
9956
- }
9957
- }
9958
- function insertRow(index, position) {
9959
- insert(index + (position === "above" ? 0 : 1), {
9960
- key: "",
9961
- value: "",
9962
- disabled: false
9963
- });
9964
- }
9965
- return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(
9966
- KeyboundForm,
9967
- {
9968
- onSubmit: handleSubmit,
9969
- className: "flex flex-1 flex-col overflow-hidden",
9970
- children: [
9971
- /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer.Body, { className: "flex flex-1 flex-col gap-y-8 overflow-y-auto", children: [
9972
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-base shadow-elevation-card-rest grid grid-cols-1 divide-y rounded-lg", children: [
9973
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "bg-ui-bg-subtle grid grid-cols-2 divide-x rounded-t-lg", children: [
9974
- /* @__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" }) }),
9975
- /* @__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" }) })
9976
- ] }),
9977
- fields.map((field, index) => {
9978
- const isDisabled = field.disabled || false;
9979
- let placeholder = "-";
9980
- if (typeof field.value === "object") {
9981
- placeholder = "{ ... }";
9982
- }
9983
- if (Array.isArray(field.value)) {
9984
- placeholder = "[ ... ]";
9985
- }
9986
- return /* @__PURE__ */ jsxRuntime.jsx(
9987
- ConditionalTooltip,
9988
- {
9989
- showTooltip: isDisabled,
9990
- content: "This row is disabled because it contains non-primitive data.",
9991
- children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "group/table relative", children: [
9992
- /* @__PURE__ */ jsxRuntime.jsxs(
9993
- "div",
9994
- {
9995
- className: ui.clx("grid grid-cols-2 divide-x", {
9996
- "overflow-hidden rounded-b-lg": index === fields.length - 1
9997
- }),
9998
- children: [
9999
- /* @__PURE__ */ jsxRuntime.jsx(
10000
- Form$2.Field,
10001
- {
10002
- control: form.control,
10003
- name: `metadata.${index}.key`,
10004
- render: ({ field: field2 }) => {
10005
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10006
- GridInput,
10007
- {
10008
- "aria-labelledby": METADATA_KEY_LABEL_ID,
10009
- ...field2,
10010
- disabled: isDisabled,
10011
- placeholder: "Key"
10012
- }
10013
- ) }) });
10014
- }
10015
- }
10016
- ),
10017
- /* @__PURE__ */ jsxRuntime.jsx(
10018
- Form$2.Field,
10019
- {
10020
- control: form.control,
10021
- name: `metadata.${index}.value`,
10022
- render: ({ field: { value, ...field2 } }) => {
10023
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10024
- GridInput,
10025
- {
10026
- "aria-labelledby": METADATA_VALUE_LABEL_ID,
10027
- ...field2,
10028
- value: isDisabled ? placeholder : value,
10029
- disabled: isDisabled,
10030
- placeholder: "Value"
10031
- }
10032
- ) }) });
10033
- }
10034
- }
10035
- )
10036
- ]
10037
- }
10038
- ),
10039
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu, { children: [
10040
- /* @__PURE__ */ jsxRuntime.jsx(
10041
- ui.DropdownMenu.Trigger,
10042
- {
10043
- className: ui.clx(
10044
- "invisible absolute inset-y-0 -right-2.5 my-auto group-hover/table:visible data-[state='open']:visible",
10045
- {
10046
- hidden: isDisabled
10047
- }
10048
- ),
10049
- disabled: isDisabled,
10050
- asChild: true,
10051
- children: /* @__PURE__ */ jsxRuntime.jsx(ui.IconButton, { size: "2xsmall", children: /* @__PURE__ */ jsxRuntime.jsx(icons.EllipsisVertical, {}) })
10052
- }
10053
- ),
10054
- /* @__PURE__ */ jsxRuntime.jsxs(ui.DropdownMenu.Content, { children: [
10055
- /* @__PURE__ */ jsxRuntime.jsxs(
10056
- ui.DropdownMenu.Item,
10057
- {
10058
- className: "gap-x-2",
10059
- onClick: () => insertRow(index, "above"),
10060
- children: [
10061
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowUpMini, { className: "text-ui-fg-subtle" }),
10062
- "Insert row above"
10063
- ]
10064
- }
10065
- ),
10066
- /* @__PURE__ */ jsxRuntime.jsxs(
10067
- ui.DropdownMenu.Item,
10068
- {
10069
- className: "gap-x-2",
10070
- onClick: () => insertRow(index, "below"),
10071
- children: [
10072
- /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowDownMini, { className: "text-ui-fg-subtle" }),
10073
- "Insert row below"
10074
- ]
10075
- }
10076
- ),
10077
- /* @__PURE__ */ jsxRuntime.jsx(ui.DropdownMenu.Separator, {}),
10078
- /* @__PURE__ */ jsxRuntime.jsxs(
10079
- ui.DropdownMenu.Item,
10080
- {
10081
- className: "gap-x-2",
10082
- onClick: () => deleteRow(index),
10083
- children: [
10084
- /* @__PURE__ */ jsxRuntime.jsx(icons.Trash, { className: "text-ui-fg-subtle" }),
10085
- "Delete row"
10086
- ]
10087
- }
10088
- )
10089
- ] })
10090
- ] })
10091
- ] })
10092
- },
10093
- field.id
10094
- );
10095
- })
10096
- ] }),
10097
- 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." })
10098
- ] }),
10099
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10100
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10101
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", isLoading: isPending, children: "Save" })
10102
- ] }) })
10103
- ]
10104
- }
10105
- ) });
10106
- };
10107
- const GridInput = React.forwardRef(({ className, ...props }, ref) => {
10108
- return /* @__PURE__ */ jsxRuntime.jsx(
10109
- "input",
10110
- {
10111
- ref,
10112
- ...props,
10113
- autoComplete: "off",
10114
- className: ui.clx(
10115
- "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",
10116
- className
10117
- )
10118
- }
10119
- );
10120
- });
10121
- GridInput.displayName = "MetadataForm.GridInput";
10122
- const PlaceholderInner = () => {
10123
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-1 flex-col overflow-hidden", children: [
10124
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-[148ox] w-full rounded-lg" }) }),
10125
- /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10126
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" }),
10127
- /* @__PURE__ */ jsxRuntime.jsx(ui.Skeleton, { className: "h-7 w-12 rounded-md" })
10128
- ] }) })
10129
- ] });
10130
- };
10131
- const EDITABLE_TYPES = ["string", "number", "boolean"];
10132
- function getDefaultValues(metadata) {
10133
- if (!metadata || !Object.keys(metadata).length) {
10134
- return [
10135
- {
10136
- key: "",
10137
- value: "",
10138
- disabled: false
10139
- }
10140
- ];
10141
- }
10142
- return Object.entries(metadata).map(([key, value]) => {
10143
- if (!EDITABLE_TYPES.includes(typeof value)) {
10144
- return {
10145
- key,
10146
- value,
10147
- disabled: true
10148
- };
10149
- }
10150
- let stringValue = value;
10151
- if (typeof value !== "string") {
10152
- stringValue = JSON.stringify(value);
10153
- }
10154
- return {
10155
- key,
10156
- value: stringValue,
10157
- original_key: key
10158
- };
10159
- });
10160
- }
10161
- function parseValues(values) {
10162
- const metadata = values.metadata;
10163
- const isEmpty = !metadata.length || metadata.length === 1 && !metadata[0].key && !metadata[0].value;
10164
- if (isEmpty) {
10165
- return null;
10166
- }
10167
- const update = {};
10168
- metadata.forEach((field) => {
10169
- let key = field.key;
10170
- let value = field.value;
10171
- const disabled = field.disabled;
10172
- if (!key || !value) {
10173
- return;
10174
- }
10175
- if (disabled) {
10176
- update[key] = value;
10177
- return;
10178
- }
10179
- key = key.trim();
10180
- value = value.trim();
10181
- if (value === "true") {
10182
- update[key] = true;
10183
- } else if (value === "false") {
10184
- update[key] = false;
10185
- } else {
10186
- const parsedNumber = parseFloat(value);
10187
- if (!isNaN(parsedNumber)) {
10188
- update[key] = parsedNumber;
10189
- } else {
10190
- update[key] = value;
10191
- }
10192
- }
10193
- });
10194
- return update;
10195
- }
10196
- function getHasUneditableRows(metadata) {
10197
- if (!metadata) {
10198
- return false;
10199
- }
10200
- return Object.values(metadata).some(
10201
- (value) => !EDITABLE_TYPES.includes(typeof value)
10202
- );
10203
- }
10204
- const NumberInput = React.forwardRef(
10205
- ({
10206
- value,
10207
- onChange,
10208
- size = "base",
10209
- min = 0,
10210
- max = 100,
10211
- step = 1,
10212
- className,
10213
- disabled,
10214
- ...props
10215
- }, ref) => {
10216
- const handleChange = (event) => {
10217
- const newValue = event.target.value === "" ? min : Number(event.target.value);
10218
- if (!isNaN(newValue) && (max === void 0 || newValue <= max) && (min === void 0 || newValue >= min)) {
10219
- onChange(newValue);
10220
- }
10221
- };
10222
- const handleIncrement = () => {
10223
- const newValue = value + step;
10224
- if (max === void 0 || newValue <= max) {
10225
- onChange(newValue);
10226
- }
10227
- };
10228
- const handleDecrement = () => {
10229
- const newValue = value - step;
10230
- if (min === void 0 || newValue >= min) {
10231
- onChange(newValue);
10232
- }
10233
- };
10234
- return /* @__PURE__ */ jsxRuntime.jsxs(
10235
- "div",
10236
- {
10237
- className: ui.clx(
10238
- "inline-flex rounded-md bg-ui-bg-field shadow-borders-base overflow-hidden divide-x transition-fg",
10239
- "[&:has(input:focus)]:shadow-borders-interactive-with-active",
10240
- {
10241
- "h-7": size === "small",
10242
- "h-8": size === "base"
10243
- },
10244
- className
10245
- ),
10246
- children: [
10247
- /* @__PURE__ */ jsxRuntime.jsx(
10248
- "input",
10249
- {
10250
- ref,
10251
- type: "number",
10252
- value,
10253
- onChange: handleChange,
10254
- min,
10255
- max,
10256
- step,
10257
- className: ui.clx(
10258
- "flex-1 px-2 py-1 bg-transparent txt-compact-small text-ui-fg-base outline-none [appearance:textfield]",
10259
- "[&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none",
10260
- "placeholder:text-ui-fg-muted"
10261
- ),
10262
- ...props
10263
- }
10264
- ),
10265
- /* @__PURE__ */ jsxRuntime.jsxs(
10266
- "button",
10267
- {
10268
- className: ui.clx(
10269
- "flex items-center justify-center outline-none transition-fg",
10270
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10271
- "focus:bg-ui-bg-field-component-hover",
10272
- "hover:bg-ui-bg-field-component-hover",
10273
- {
10274
- "size-7": size === "small",
10275
- "size-8": size === "base"
10276
- }
10277
- ),
10278
- type: "button",
10279
- onClick: handleDecrement,
10280
- disabled: min !== void 0 && value <= min || disabled,
10281
- children: [
10282
- /* @__PURE__ */ jsxRuntime.jsx(icons.Minus, {}),
10283
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Decrease by ${step}` })
10284
- ]
10285
- }
10286
- ),
10287
- /* @__PURE__ */ jsxRuntime.jsxs(
10288
- "button",
10289
- {
10290
- className: ui.clx(
10291
- "flex items-center justify-center outline-none transition-fg",
10292
- "disabled:cursor-not-allowed disabled:text-ui-fg-muted",
10293
- "focus:bg-ui-bg-field-hover",
10294
- "hover:bg-ui-bg-field-hover",
10295
- {
10296
- "size-7": size === "small",
10297
- "size-8": size === "base"
10298
- }
10299
- ),
10300
- type: "button",
10301
- onClick: handleIncrement,
10302
- disabled: max !== void 0 && value >= max || disabled,
10303
- children: [
10304
- /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}),
10305
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: `Increase by ${step}` })
10306
- ]
10307
- }
10308
- )
10309
- ]
10310
- }
10311
- );
10312
- }
10313
- );
10314
- const PRODUCT_VARIANTS_QUERY_KEY = "product-variants";
10315
- const productVariantsQueryKeys = {
10316
- list: (query2) => [
10317
- PRODUCT_VARIANTS_QUERY_KEY,
10318
- query2 ? query2 : void 0
10319
- ]
10320
- };
10321
- const useProductVariants = (query2, options) => {
10322
- const { data, ...rest } = reactQuery.useQuery({
10323
- queryKey: productVariantsQueryKeys.list(query2),
10324
- queryFn: async () => await sdk.admin.productVariant.list(query2),
10325
- ...options
10326
- });
10327
- return { ...data, ...rest };
10328
- };
10329
- const useCancelOrderEdit = ({ preview }) => {
10330
- const { mutateAsync: cancelOrderEdit } = useDraftOrderCancelEdit(preview == null ? void 0 : preview.id);
10331
- const onCancel = React.useCallback(async () => {
10332
- if (!preview) {
10333
- return true;
10334
- }
10335
- let res = false;
10336
- await cancelOrderEdit(void 0, {
10337
- onError: (e) => {
10338
- ui.toast.error(e.message);
10339
- },
10340
- onSuccess: () => {
10341
- res = true;
10342
- }
10343
- });
10344
- return res;
10345
- }, [preview, cancelOrderEdit]);
10346
- return { onCancel };
10347
- };
10348
- let IS_REQUEST_RUNNING = false;
10349
- const useInitiateOrderEdit = ({
10350
- preview
10351
- }) => {
10352
- const navigate = reactRouterDom.useNavigate();
10353
- const { mutateAsync } = useDraftOrderBeginEdit(preview == null ? void 0 : preview.id);
10354
- React.useEffect(() => {
10355
- async function run() {
10356
- if (IS_REQUEST_RUNNING || !preview) {
10357
- return;
10358
- }
10359
- if (preview.order_change) {
10360
- return;
10361
- }
10362
- IS_REQUEST_RUNNING = true;
10363
- await mutateAsync(void 0, {
10364
- onError: (e) => {
10365
- ui.toast.error(e.message);
10366
- navigate(`/draft-orders/${preview.id}`, { replace: true });
10367
- return;
10368
- }
10369
- });
10370
- IS_REQUEST_RUNNING = false;
9999
+ IS_REQUEST_RUNNING = false;
10371
10000
  }
10372
10001
  run();
10373
10002
  }, [preview, navigate, mutateAsync]);
@@ -10606,20 +10235,168 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10606
10235
  const [editing, setEditing] = React.useState(false);
10607
10236
  const form = reactHookForm.useForm({
10608
10237
  defaultValues: {
10609
- quantity: item.quantity,
10610
- unit_price: item.unit_price
10238
+ quantity: item.quantity,
10239
+ unit_price: item.unit_price
10240
+ },
10241
+ resolver: zod.zodResolver(variantItemSchema)
10242
+ });
10243
+ const actionId = React.useMemo(() => {
10244
+ var _a, _b;
10245
+ return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10246
+ }, [item]);
10247
+ const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10248
+ const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10249
+ const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10250
+ const onSubmit = form.handleSubmit(async (data) => {
10251
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10252
+ setEditing(false);
10253
+ return;
10254
+ }
10255
+ if (!actionId) {
10256
+ await updateOriginalItem(
10257
+ {
10258
+ item_id: item.id,
10259
+ quantity: data.quantity,
10260
+ unit_price: convertNumber(data.unit_price)
10261
+ },
10262
+ {
10263
+ onSuccess: () => {
10264
+ setEditing(false);
10265
+ },
10266
+ onError: (e) => {
10267
+ ui.toast.error(e.message);
10268
+ }
10269
+ }
10270
+ );
10271
+ return;
10272
+ }
10273
+ await updateActionItem(
10274
+ {
10275
+ action_id: actionId,
10276
+ quantity: data.quantity,
10277
+ unit_price: convertNumber(data.unit_price)
10278
+ },
10279
+ {
10280
+ onSuccess: () => {
10281
+ setEditing(false);
10282
+ },
10283
+ onError: (e) => {
10284
+ ui.toast.error(e.message);
10285
+ }
10286
+ }
10287
+ );
10288
+ });
10289
+ 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: [
10290
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10291
+ /* @__PURE__ */ jsxRuntime.jsx(
10292
+ Thumbnail,
10293
+ {
10294
+ thumbnail: item.thumbnail,
10295
+ alt: item.product_title ?? void 0
10296
+ }
10297
+ ),
10298
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10299
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10300
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10301
+ /* @__PURE__ */ jsxRuntime.jsxs(
10302
+ ui.Text,
10303
+ {
10304
+ size: "small",
10305
+ leading: "compact",
10306
+ className: "text-ui-fg-subtle",
10307
+ children: [
10308
+ "(",
10309
+ item.variant_title,
10310
+ ")"
10311
+ ]
10312
+ }
10313
+ )
10314
+ ] }),
10315
+ /* @__PURE__ */ jsxRuntime.jsx(
10316
+ ui.Text,
10317
+ {
10318
+ size: "small",
10319
+ leading: "compact",
10320
+ className: "text-ui-fg-subtle",
10321
+ children: item.variant_sku
10322
+ }
10323
+ )
10324
+ ] })
10325
+ ] }),
10326
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10327
+ Form$2.Field,
10328
+ {
10329
+ control: form.control,
10330
+ name: "quantity",
10331
+ render: ({ field }) => {
10332
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10333
+ }
10334
+ }
10335
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10336
+ editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10337
+ Form$2.Field,
10338
+ {
10339
+ control: form.control,
10340
+ name: "unit_price",
10341
+ render: ({ field: { onChange, ...field } }) => {
10342
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10343
+ ui.CurrencyInput,
10344
+ {
10345
+ ...field,
10346
+ symbol: getNativeSymbol(currencyCode),
10347
+ code: currencyCode,
10348
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10349
+ }
10350
+ ) }) });
10351
+ }
10352
+ }
10353
+ ) }) : /* @__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) }) }),
10354
+ /* @__PURE__ */ jsxRuntime.jsx(
10355
+ ui.IconButton,
10356
+ {
10357
+ type: "button",
10358
+ size: "small",
10359
+ onClick: editing ? onSubmit : () => {
10360
+ setEditing(true);
10361
+ },
10362
+ disabled: isPending,
10363
+ children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10364
+ }
10365
+ )
10366
+ ] }) }) });
10367
+ };
10368
+ const variantItemSchema = objectType({
10369
+ quantity: numberType(),
10370
+ unit_price: unionType([numberType(), stringType()])
10371
+ });
10372
+ const CustomItem = ({ item, preview, currencyCode }) => {
10373
+ const [editing, setEditing] = React.useState(false);
10374
+ const { quantity, unit_price, title } = item;
10375
+ const form = reactHookForm.useForm({
10376
+ defaultValues: {
10377
+ title,
10378
+ quantity,
10379
+ unit_price
10611
10380
  },
10612
- resolver: zod.zodResolver(variantItemSchema)
10381
+ resolver: zod.zodResolver(customItemSchema)
10613
10382
  });
10383
+ React.useEffect(() => {
10384
+ form.reset({
10385
+ title,
10386
+ quantity,
10387
+ unit_price
10388
+ });
10389
+ }, [form, title, quantity, unit_price]);
10614
10390
  const actionId = React.useMemo(() => {
10615
10391
  var _a, _b;
10616
10392
  return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10617
10393
  }, [item]);
10618
10394
  const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10395
+ const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10619
10396
  const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10620
10397
  const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10621
10398
  const onSubmit = form.handleSubmit(async (data) => {
10622
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity) {
10399
+ if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10623
10400
  setEditing(false);
10624
10401
  return;
10625
10402
  }
@@ -10641,6 +10418,17 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10641
10418
  );
10642
10419
  return;
10643
10420
  }
10421
+ if (data.quantity === 0) {
10422
+ await removeActionItem(actionId, {
10423
+ onSuccess: () => {
10424
+ setEditing(false);
10425
+ },
10426
+ onError: (e) => {
10427
+ ui.toast.error(e.message);
10428
+ }
10429
+ });
10430
+ return;
10431
+ }
10644
10432
  await updateActionItem(
10645
10433
  {
10646
10434
  action_id: actionId,
@@ -10658,43 +10446,26 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10658
10446
  );
10659
10447
  });
10660
10448
  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: [
10661
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full items-center gap-x-3", children: [
10449
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10662
10450
  /* @__PURE__ */ jsxRuntime.jsx(
10663
10451
  Thumbnail,
10664
10452
  {
10665
10453
  thumbnail: item.thumbnail,
10666
- alt: item.product_title ?? void 0
10454
+ alt: item.title ?? void 0
10667
10455
  }
10668
10456
  ),
10669
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
10670
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-1", children: [
10671
- /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", leading: "compact", children: item.product_title }),
10672
- /* @__PURE__ */ jsxRuntime.jsxs(
10673
- ui.Text,
10674
- {
10675
- size: "small",
10676
- leading: "compact",
10677
- className: "text-ui-fg-subtle",
10678
- children: [
10679
- "(",
10680
- item.variant_title,
10681
- ")"
10682
- ]
10683
- }
10684
- )
10685
- ] }),
10686
- /* @__PURE__ */ jsxRuntime.jsx(
10687
- ui.Text,
10688
- {
10689
- size: "small",
10690
- leading: "compact",
10691
- className: "text-ui-fg-subtle",
10692
- children: item.variant_sku
10457
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10458
+ Form$2.Field,
10459
+ {
10460
+ control: form.control,
10461
+ name: "title",
10462
+ render: ({ field }) => {
10463
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10693
10464
  }
10694
- )
10695
- ] })
10465
+ }
10466
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10696
10467
  ] }),
10697
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10468
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10698
10469
  Form$2.Field,
10699
10470
  {
10700
10471
  control: form.control,
@@ -10703,8 +10474,8 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10703
10474
  return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10704
10475
  }
10705
10476
  }
10706
- ) }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }) }),
10707
- editing ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
10477
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10478
+ editing ? /* @__PURE__ */ jsxRuntime.jsx(
10708
10479
  Form$2.Field,
10709
10480
  {
10710
10481
  control: form.control,
@@ -10721,7 +10492,7 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10721
10492
  ) }) });
10722
10493
  }
10723
10494
  }
10724
- ) }) : /* @__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) }) }),
10495
+ ) : /* @__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) }) }),
10725
10496
  /* @__PURE__ */ jsxRuntime.jsx(
10726
10497
  ui.IconButton,
10727
10498
  {
@@ -10736,79 +10507,215 @@ const VariantItem = ({ item, preview, currencyCode }) => {
10736
10507
  )
10737
10508
  ] }) }) });
10738
10509
  };
10739
- const variantItemSchema = objectType({
10740
- quantity: numberType(),
10741
- unit_price: unionType([numberType(), stringType()])
10742
- });
10743
- const CustomItem = ({ item, preview, currencyCode }) => {
10744
- const [editing, setEditing] = React.useState(false);
10745
- const { quantity, unit_price, title } = item;
10510
+ const StackedModalTrigger$1 = ({
10511
+ type,
10512
+ setModalContent
10513
+ }) => {
10514
+ const { setIsOpen } = useStackedModal();
10515
+ const onClick = React.useCallback(() => {
10516
+ setModalContent(type);
10517
+ setIsOpen(STACKED_MODAL_ID, true);
10518
+ }, [setModalContent, setIsOpen, type]);
10519
+ 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" }) });
10520
+ };
10521
+ const VARIANT_PREFIX = "items";
10522
+ const LIMIT = 50;
10523
+ const ExistingItemsForm = ({ orderId, items }) => {
10524
+ const { setIsOpen } = useStackedModal();
10525
+ const [rowSelection, setRowSelection] = React.useState(
10526
+ items.reduce((acc, item) => {
10527
+ acc[item.variant_id] = true;
10528
+ return acc;
10529
+ }, {})
10530
+ );
10531
+ React.useEffect(() => {
10532
+ setRowSelection(
10533
+ items.reduce((acc, item) => {
10534
+ if (item.variant_id) {
10535
+ acc[item.variant_id] = true;
10536
+ }
10537
+ return acc;
10538
+ }, {})
10539
+ );
10540
+ }, [items]);
10541
+ const { q, order, offset } = useQueryParams(
10542
+ ["q", "order", "offset"],
10543
+ VARIANT_PREFIX
10544
+ );
10545
+ const { variants, count, isPending, isError, error } = useProductVariants(
10546
+ {
10547
+ q,
10548
+ order,
10549
+ offset: offset ? parseInt(offset) : void 0,
10550
+ limit: LIMIT
10551
+ },
10552
+ {
10553
+ placeholderData: reactQuery.keepPreviousData
10554
+ }
10555
+ );
10556
+ const columns = useColumns();
10557
+ const { mutateAsync } = useDraftOrderAddItems(orderId);
10558
+ const onSubmit = async () => {
10559
+ const ids = Object.keys(rowSelection).filter(
10560
+ (id) => !items.find((i) => i.variant_id === id)
10561
+ );
10562
+ await mutateAsync(
10563
+ {
10564
+ items: ids.map((id) => ({
10565
+ variant_id: id,
10566
+ quantity: 1
10567
+ }))
10568
+ },
10569
+ {
10570
+ onSuccess: () => {
10571
+ setRowSelection({});
10572
+ setIsOpen(STACKED_MODAL_ID, false);
10573
+ },
10574
+ onError: (e) => {
10575
+ ui.toast.error(e.message);
10576
+ }
10577
+ }
10578
+ );
10579
+ };
10580
+ if (isError) {
10581
+ throw error;
10582
+ }
10583
+ return /* @__PURE__ */ jsxRuntime.jsxs(
10584
+ StackedFocusModal.Content,
10585
+ {
10586
+ onOpenAutoFocus: (e) => {
10587
+ e.preventDefault();
10588
+ const searchInput = document.querySelector(
10589
+ "[data-modal-id='modal-search-input']"
10590
+ );
10591
+ if (searchInput) {
10592
+ searchInput.focus();
10593
+ }
10594
+ },
10595
+ children: [
10596
+ /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10597
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10598
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
10599
+ ] }),
10600
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10601
+ DataTable,
10602
+ {
10603
+ data: variants,
10604
+ columns,
10605
+ isLoading: isPending,
10606
+ getRowId: (row) => row.id,
10607
+ rowCount: count,
10608
+ prefix: VARIANT_PREFIX,
10609
+ layout: "fill",
10610
+ rowSelection: {
10611
+ state: rowSelection,
10612
+ onRowSelectionChange: setRowSelection,
10613
+ enableRowSelection: (row) => {
10614
+ return !items.find((i) => i.variant_id === row.original.id);
10615
+ }
10616
+ },
10617
+ autoFocusSearch: true
10618
+ }
10619
+ ) }),
10620
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10621
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10622
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
10623
+ ] }) })
10624
+ ]
10625
+ }
10626
+ );
10627
+ };
10628
+ const columnHelper = ui.createDataTableColumnHelper();
10629
+ const useColumns = () => {
10630
+ return React.useMemo(() => {
10631
+ return [
10632
+ columnHelper.select(),
10633
+ columnHelper.accessor("product.title", {
10634
+ header: "Product",
10635
+ cell: ({ row }) => {
10636
+ var _a, _b, _c;
10637
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
10638
+ /* @__PURE__ */ jsxRuntime.jsx(
10639
+ Thumbnail,
10640
+ {
10641
+ thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
10642
+ alt: (_b = row.original.product) == null ? void 0 : _b.title
10643
+ }
10644
+ ),
10645
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
10646
+ ] });
10647
+ },
10648
+ enableSorting: true
10649
+ }),
10650
+ columnHelper.accessor("title", {
10651
+ header: "Variant",
10652
+ enableSorting: true
10653
+ }),
10654
+ columnHelper.accessor("sku", {
10655
+ header: "SKU",
10656
+ cell: ({ getValue }) => {
10657
+ return getValue() ?? "-";
10658
+ },
10659
+ enableSorting: true
10660
+ }),
10661
+ columnHelper.accessor("updated_at", {
10662
+ header: "Updated",
10663
+ cell: ({ getValue }) => {
10664
+ return /* @__PURE__ */ jsxRuntime.jsx(
10665
+ ui.Tooltip,
10666
+ {
10667
+ content: getFullDate({ date: getValue(), includeTime: true }),
10668
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10669
+ }
10670
+ );
10671
+ },
10672
+ enableSorting: true,
10673
+ sortAscLabel: "Oldest first",
10674
+ sortDescLabel: "Newest first"
10675
+ }),
10676
+ columnHelper.accessor("created_at", {
10677
+ header: "Created",
10678
+ cell: ({ getValue }) => {
10679
+ return /* @__PURE__ */ jsxRuntime.jsx(
10680
+ ui.Tooltip,
10681
+ {
10682
+ content: getFullDate({ date: getValue(), includeTime: true }),
10683
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
10684
+ }
10685
+ );
10686
+ },
10687
+ enableSorting: true,
10688
+ sortAscLabel: "Oldest first",
10689
+ sortDescLabel: "Newest first"
10690
+ })
10691
+ ];
10692
+ }, []);
10693
+ };
10694
+ const CustomItemForm = ({ orderId, currencyCode }) => {
10695
+ const { setIsOpen } = useStackedModal();
10696
+ const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
10746
10697
  const form = reactHookForm.useForm({
10747
10698
  defaultValues: {
10748
- title,
10749
- quantity,
10750
- unit_price
10699
+ title: "",
10700
+ quantity: 1,
10701
+ unit_price: ""
10751
10702
  },
10752
10703
  resolver: zod.zodResolver(customItemSchema)
10753
10704
  });
10754
- React.useEffect(() => {
10755
- form.reset({
10756
- title,
10757
- quantity,
10758
- unit_price
10759
- });
10760
- }, [form, title, quantity, unit_price]);
10761
- const actionId = React.useMemo(() => {
10762
- var _a, _b;
10763
- return (_b = (_a = item.actions) == null ? void 0 : _a.find((a) => a.action === "ITEM_ADD")) == null ? void 0 : _b.id;
10764
- }, [item]);
10765
- const { mutateAsync: updateActionItem, isPending: isUpdatingActionItem } = useDraftOrderUpdateActionItem(preview.id);
10766
- const { mutateAsync: removeActionItem, isPending: isRemovingActionItem } = useDraftOrderRemoveActionItem(preview.id);
10767
- const { mutateAsync: updateOriginalItem, isPending: isUpdatingOriginalItem } = useDraftOrderUpdateItem(preview.id);
10768
- const isPending = isUpdatingActionItem || isUpdatingOriginalItem;
10769
10705
  const onSubmit = form.handleSubmit(async (data) => {
10770
- if (convertNumber(data.unit_price) === item.unit_price && data.quantity === item.quantity && data.title === item.title) {
10771
- setEditing(false);
10772
- return;
10773
- }
10774
- if (!actionId) {
10775
- await updateOriginalItem(
10776
- {
10777
- item_id: item.id,
10778
- quantity: data.quantity,
10779
- unit_price: convertNumber(data.unit_price)
10780
- },
10781
- {
10782
- onSuccess: () => {
10783
- setEditing(false);
10784
- },
10785
- onError: (e) => {
10786
- ui.toast.error(e.message);
10787
- }
10788
- }
10789
- );
10790
- return;
10791
- }
10792
- if (data.quantity === 0) {
10793
- await removeActionItem(actionId, {
10794
- onSuccess: () => {
10795
- setEditing(false);
10796
- },
10797
- onError: (e) => {
10798
- ui.toast.error(e.message);
10799
- }
10800
- });
10801
- return;
10802
- }
10803
- await updateActionItem(
10706
+ await addItems(
10804
10707
  {
10805
- action_id: actionId,
10806
- quantity: data.quantity,
10807
- unit_price: convertNumber(data.unit_price)
10708
+ items: [
10709
+ {
10710
+ title: data.title,
10711
+ quantity: data.quantity,
10712
+ unit_price: convertNumber(data.unit_price)
10713
+ }
10714
+ ]
10808
10715
  },
10809
10716
  {
10810
10717
  onSuccess: () => {
10811
- setEditing(false);
10718
+ setIsOpen(STACKED_MODAL_ID, false);
10812
10719
  },
10813
10720
  onError: (e) => {
10814
10721
  ui.toast.error(e.message);
@@ -10816,365 +10723,458 @@ const CustomItem = ({ item, preview, currencyCode }) => {
10816
10723
  }
10817
10724
  );
10818
10725
  });
10819
- 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: [
10820
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-3", children: [
10726
+ return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
10727
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
10728
+ /* @__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: [
10729
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10730
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
10731
+ /* @__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." }) })
10732
+ ] }),
10733
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10821
10734
  /* @__PURE__ */ jsxRuntime.jsx(
10822
- Thumbnail,
10735
+ Form$2.Field,
10823
10736
  {
10824
- thumbnail: item.thumbnail,
10825
- alt: item.title ?? void 0
10737
+ control: form.control,
10738
+ name: "title",
10739
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10740
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10741
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
10742
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
10743
+ ] }),
10744
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10745
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
10746
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10747
+ ] })
10748
+ ] }) })
10826
10749
  }
10827
10750
  ),
10828
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10751
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10752
+ /* @__PURE__ */ jsxRuntime.jsx(
10829
10753
  Form$2.Field,
10830
10754
  {
10831
10755
  control: form.control,
10832
- name: "title",
10833
- render: ({ field }) => {
10834
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }) });
10835
- }
10836
- }
10837
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.title })
10838
- ] }),
10839
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10840
- Form$2.Field,
10841
- {
10842
- control: form.control,
10843
- name: "quantity",
10844
- render: ({ field }) => {
10845
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(NumberInput, { ...field }) }) });
10756
+ name: "unit_price",
10757
+ render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10758
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10759
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
10760
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
10761
+ ] }),
10762
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10763
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10764
+ ui.CurrencyInput,
10765
+ {
10766
+ symbol: getNativeSymbol(currencyCode),
10767
+ code: currencyCode,
10768
+ onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
10769
+ ...field
10770
+ }
10771
+ ) }),
10772
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10773
+ ] })
10774
+ ] }) })
10846
10775
  }
10847
- }
10848
- ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "small", weight: "plus", children: item.quantity }),
10849
- editing ? /* @__PURE__ */ jsxRuntime.jsx(
10850
- Form$2.Field,
10851
- {
10852
- control: form.control,
10853
- name: "unit_price",
10854
- render: ({ field: { onChange, ...field } }) => {
10855
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
10856
- ui.CurrencyInput,
10857
- {
10858
- ...field,
10859
- symbol: getNativeSymbol(currencyCode),
10860
- code: currencyCode,
10861
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value)
10862
- }
10863
- ) }) });
10776
+ ),
10777
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
10778
+ /* @__PURE__ */ jsxRuntime.jsx(
10779
+ Form$2.Field,
10780
+ {
10781
+ control: form.control,
10782
+ name: "quantity",
10783
+ render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
10784
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
10785
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
10786
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
10787
+ ] }),
10788
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
10789
+ /* @__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" }) }) }),
10790
+ /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
10791
+ ] })
10792
+ ] }) })
10864
10793
  }
10865
- }
10866
- ) : /* @__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) }) }),
10867
- /* @__PURE__ */ jsxRuntime.jsx(
10868
- ui.IconButton,
10869
- {
10870
- type: "button",
10871
- size: "small",
10872
- onClick: editing ? onSubmit : () => {
10873
- setEditing(true);
10874
- },
10875
- disabled: isPending,
10876
- children: editing ? /* @__PURE__ */ jsxRuntime.jsx(icons.Check, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.PencilSquare, {})
10877
- }
10878
- )
10794
+ )
10795
+ ] }) }) }),
10796
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10797
+ /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10798
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
10799
+ ] }) })
10879
10800
  ] }) }) });
10880
10801
  };
10881
- const StackedModalTrigger$1 = ({
10882
- type,
10883
- setModalContent
10884
- }) => {
10885
- const { setIsOpen } = useStackedModal();
10886
- const onClick = React.useCallback(() => {
10887
- setModalContent(type);
10888
- setIsOpen(STACKED_MODAL_ID, true);
10889
- }, [setModalContent, setIsOpen, type]);
10890
- 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" }) });
10802
+ const customItemSchema = objectType({
10803
+ title: stringType().min(1),
10804
+ quantity: numberType(),
10805
+ unit_price: unionType([numberType(), stringType()])
10806
+ });
10807
+ const CustomItems = () => {
10808
+ return /* @__PURE__ */ jsxRuntime.jsxs(RouteDrawer, { children: [
10809
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Header, { children: /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Edit Custom Items" }) }) }),
10810
+ /* @__PURE__ */ jsxRuntime.jsx(CustomItemsForm, {})
10811
+ ] });
10891
10812
  };
10892
- const VARIANT_PREFIX = "items";
10893
- const LIMIT = 50;
10894
- const ExistingItemsForm = ({ orderId, items }) => {
10895
- const { setIsOpen } = useStackedModal();
10896
- const [rowSelection, setRowSelection] = React.useState(
10897
- items.reduce((acc, item) => {
10898
- acc[item.variant_id] = true;
10899
- return acc;
10900
- }, {})
10901
- );
10902
- React.useEffect(() => {
10903
- setRowSelection(
10904
- items.reduce((acc, item) => {
10905
- if (item.variant_id) {
10906
- acc[item.variant_id] = true;
10907
- }
10908
- return acc;
10909
- }, {})
10813
+ const CustomItemsForm = () => {
10814
+ const form = reactHookForm.useForm({
10815
+ resolver: zod.zodResolver(schema$3)
10816
+ });
10817
+ return /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Form, { form, children: /* @__PURE__ */ jsxRuntime.jsxs(KeyboundForm, { className: "flex flex-1 flex-col", children: [
10818
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Body, {}),
10819
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex justify-end gap-2", children: [
10820
+ /* @__PURE__ */ jsxRuntime.jsx(RouteDrawer.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
10821
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "submit", children: "Save" })
10822
+ ] }) })
10823
+ ] }) });
10824
+ };
10825
+ const schema$3 = objectType({
10826
+ email: stringType().email()
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",
10833
+ {
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",
10843
+ {
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
+ })
10848
+ }
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
+ }
10910
10860
  );
10911
- }, [items]);
10912
- const { q, order, offset } = useQueryParams(
10913
- ["q", "order", "offset"],
10914
- VARIANT_PREFIX
10915
- );
10916
- const { variants, count, isPending, isError, error } = useProductVariants(
10917
- {
10918
- q,
10919
- order,
10920
- offset: offset ? parseInt(offset) : void 0,
10921
- 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)
10922
10898
  },
10923
- {
10924
- placeholderData: reactQuery.keepPreviousData
10925
- }
10926
- );
10927
- const columns = useColumns();
10928
- const { mutateAsync } = useDraftOrderAddItems(orderId);
10929
- const onSubmit = async () => {
10930
- const ids = Object.keys(rowSelection).filter(
10931
- (id) => !items.find((i) => i.variant_id === id)
10932
- );
10899
+ resolver: zod.zodResolver(MetadataSchema)
10900
+ });
10901
+ const handleSubmit = form.handleSubmit(async (data) => {
10902
+ const parsedData = parseValues(data);
10933
10903
  await mutateAsync(
10934
10904
  {
10935
- items: ids.map((id) => ({
10936
- variant_id: id,
10937
- quantity: 1
10938
- }))
10905
+ metadata: parsedData
10939
10906
  },
10940
10907
  {
10941
10908
  onSuccess: () => {
10942
- setRowSelection({});
10943
- setIsOpen(STACKED_MODAL_ID, false);
10909
+ ui.toast.success("Metadata updated");
10910
+ handleSuccess();
10944
10911
  },
10945
- onError: (e) => {
10946
- ui.toast.error(e.message);
10912
+ onError: (error) => {
10913
+ ui.toast.error(error.message);
10947
10914
  }
10948
10915
  }
10949
10916
  );
10950
- };
10951
- if (isError) {
10952
- 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
+ }
10953
10931
  }
10954
- return /* @__PURE__ */ jsxRuntime.jsxs(
10955
- 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,
10956
10941
  {
10957
- onOpenAutoFocus: (e) => {
10958
- e.preventDefault();
10959
- const searchInput = document.querySelector(
10960
- "[data-modal-id='modal-search-input']"
10961
- );
10962
- if (searchInput) {
10963
- searchInput.focus();
10964
- }
10965
- },
10942
+ onSubmit: handleSubmit,
10943
+ className: "flex flex-1 flex-col overflow-hidden",
10966
10944
  children: [
10967
- /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Header, { children: [
10968
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Product Variants" }) }),
10969
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Description, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx("span", { className: "sr-only", children: "Choose product variants to add to the order." }) })
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 = "{ ... }";
10956
+ }
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." })
10970
11072
  ] }),
10971
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Body, { className: "flex-1 overflow-hidden", children: /* @__PURE__ */ jsxRuntime.jsx(
10972
- DataTable,
10973
- {
10974
- data: variants,
10975
- columns,
10976
- isLoading: isPending,
10977
- getRowId: (row) => row.id,
10978
- rowCount: count,
10979
- prefix: VARIANT_PREFIX,
10980
- layout: "fill",
10981
- rowSelection: {
10982
- state: rowSelection,
10983
- onRowSelectionChange: setRowSelection,
10984
- enableRowSelection: (row) => {
10985
- return !items.find((i) => i.variant_id === row.original.id);
10986
- }
10987
- },
10988
- autoFocusSearch: true
10989
- }
10990
- ) }),
10991
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
10992
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
10993
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Update items" })
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" })
10994
11076
  ] }) })
10995
11077
  ]
10996
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
+ }
10997
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
+ ] });
10998
11104
  };
10999
- const columnHelper = ui.createDataTableColumnHelper();
11000
- const useColumns = () => {
11001
- return React.useMemo(() => {
11105
+ const EDITABLE_TYPES = ["string", "number", "boolean"];
11106
+ function getDefaultValues(metadata) {
11107
+ if (!metadata || !Object.keys(metadata).length) {
11002
11108
  return [
11003
- columnHelper.select(),
11004
- columnHelper.accessor("product.title", {
11005
- header: "Product",
11006
- cell: ({ row }) => {
11007
- var _a, _b, _c;
11008
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-x-2", children: [
11009
- /* @__PURE__ */ jsxRuntime.jsx(
11010
- Thumbnail,
11011
- {
11012
- thumbnail: (_a = row.original.product) == null ? void 0 : _a.thumbnail,
11013
- alt: (_b = row.original.product) == null ? void 0 : _b.title
11014
- }
11015
- ),
11016
- /* @__PURE__ */ jsxRuntime.jsx("span", { children: (_c = row.original.product) == null ? void 0 : _c.title })
11017
- ] });
11018
- },
11019
- enableSorting: true
11020
- }),
11021
- columnHelper.accessor("title", {
11022
- header: "Variant",
11023
- enableSorting: true
11024
- }),
11025
- columnHelper.accessor("sku", {
11026
- header: "SKU",
11027
- cell: ({ getValue }) => {
11028
- return getValue() ?? "-";
11029
- },
11030
- enableSorting: true
11031
- }),
11032
- columnHelper.accessor("updated_at", {
11033
- header: "Updated",
11034
- cell: ({ getValue }) => {
11035
- return /* @__PURE__ */ jsxRuntime.jsx(
11036
- ui.Tooltip,
11037
- {
11038
- content: getFullDate({ date: getValue(), includeTime: true }),
11039
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11040
- }
11041
- );
11042
- },
11043
- enableSorting: true,
11044
- sortAscLabel: "Oldest first",
11045
- sortDescLabel: "Newest first"
11046
- }),
11047
- columnHelper.accessor("created_at", {
11048
- header: "Created",
11049
- cell: ({ getValue }) => {
11050
- return /* @__PURE__ */ jsxRuntime.jsx(
11051
- ui.Tooltip,
11052
- {
11053
- content: getFullDate({ date: getValue(), includeTime: true }),
11054
- children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: getFullDate({ date: getValue() }) })
11055
- }
11056
- );
11057
- },
11058
- enableSorting: true,
11059
- sortAscLabel: "Oldest first",
11060
- sortDescLabel: "Newest first"
11061
- })
11062
- ];
11063
- }, []);
11064
- };
11065
- const CustomItemForm = ({ orderId, currencyCode }) => {
11066
- const { setIsOpen } = useStackedModal();
11067
- const { mutateAsync: addItems } = useDraftOrderAddItems(orderId);
11068
- const form = reactHookForm.useForm({
11069
- defaultValues: {
11070
- title: "",
11071
- quantity: 1,
11072
- unit_price: ""
11073
- },
11074
- resolver: zod.zodResolver(customItemSchema)
11075
- });
11076
- const onSubmit = form.handleSubmit(async (data) => {
11077
- await addItems(
11078
- {
11079
- items: [
11080
- {
11081
- title: data.title,
11082
- quantity: data.quantity,
11083
- unit_price: convertNumber(data.unit_price)
11084
- }
11085
- ]
11086
- },
11087
11109
  {
11088
- onSuccess: () => {
11089
- setIsOpen(STACKED_MODAL_ID, false);
11090
- },
11091
- onError: (e) => {
11092
- ui.toast.error(e.message);
11093
- }
11110
+ key: "",
11111
+ value: "",
11112
+ disabled: false
11094
11113
  }
11095
- );
11096
- });
11097
- return /* @__PURE__ */ jsxRuntime.jsx(Form$2, { ...form, children: /* @__PURE__ */ jsxRuntime.jsx(KeyboundForm, { onSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(StackedFocusModal.Content, { children: [
11098
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Header, {}),
11099
- /* @__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: [
11100
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11101
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Title, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { children: "Add custom item" }) }),
11102
- /* @__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." }) })
11103
- ] }),
11104
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11105
- /* @__PURE__ */ jsxRuntime.jsx(
11106
- Form$2.Field,
11107
- {
11108
- control: form.control,
11109
- name: "title",
11110
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11111
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11112
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Title" }),
11113
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the title of the item" })
11114
- ] }),
11115
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11116
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Input, { ...field }) }),
11117
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11118
- ] })
11119
- ] }) })
11120
- }
11121
- ),
11122
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11123
- /* @__PURE__ */ jsxRuntime.jsx(
11124
- Form$2.Field,
11125
- {
11126
- control: form.control,
11127
- name: "unit_price",
11128
- render: ({ field: { onChange, ...field } }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11129
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11130
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Unit price" }),
11131
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the unit price of the item" })
11132
- ] }),
11133
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11134
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Control, { children: /* @__PURE__ */ jsxRuntime.jsx(
11135
- ui.CurrencyInput,
11136
- {
11137
- symbol: getNativeSymbol(currencyCode),
11138
- code: currencyCode,
11139
- onValueChange: (_value, _name, values) => onChange(values == null ? void 0 : values.value),
11140
- ...field
11141
- }
11142
- ) }),
11143
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11144
- ] })
11145
- ] }) })
11146
- }
11147
- ),
11148
- /* @__PURE__ */ jsxRuntime.jsx(ui.Divider, { variant: "dashed" }),
11149
- /* @__PURE__ */ jsxRuntime.jsx(
11150
- Form$2.Field,
11151
- {
11152
- control: form.control,
11153
- name: "quantity",
11154
- render: ({ field }) => /* @__PURE__ */ jsxRuntime.jsx(Form$2.Item, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
11155
- /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
11156
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Label, { children: "Quantity" }),
11157
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.Hint, { children: "Enter the quantity of the item" })
11158
- ] }),
11159
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full flex-1", children: [
11160
- /* @__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" }) }) }),
11161
- /* @__PURE__ */ jsxRuntime.jsx(Form$2.ErrorMessage, {})
11162
- ] })
11163
- ] }) })
11164
- }
11165
- )
11166
- ] }) }) }),
11167
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
11168
- /* @__PURE__ */ jsxRuntime.jsx(StackedFocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", variant: "secondary", type: "button", children: "Cancel" }) }),
11169
- /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { size: "small", type: "button", onClick: onSubmit, children: "Add item" })
11170
- ] }) })
11171
- ] }) }) });
11172
- };
11173
- const customItemSchema = objectType({
11174
- title: stringType().min(1),
11175
- quantity: numberType(),
11176
- unit_price: unionType([numberType(), stringType()])
11177
- });
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
+ };
11133
+ });
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
+ }
11167
+ });
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) => [
@@ -12348,226 +12348,23 @@ const CustomAmountField = ({
12348
12348
  render: ({ field: { onChange, ...field } }) => {
12349
12349
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "grid grid-cols-2 gap-x-3", children: [
12350
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,
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: [
@@ -13068,22 +13068,22 @@ const routeModule = {
13068
13068
  Component: BillingAddress,
13069
13069
  path: "/draft-orders/:id/billing-address"
13070
13070
  },
13071
- {
13072
- Component: CustomItems,
13073
- path: "/draft-orders/:id/custom-items"
13074
- },
13075
13071
  {
13076
13072
  Component: Email,
13077
13073
  path: "/draft-orders/:id/email"
13078
13074
  },
13079
- {
13080
- Component: Metadata,
13081
- path: "/draft-orders/:id/metadata"
13082
- },
13083
13075
  {
13084
13076
  Component: Items,
13085
13077
  path: "/draft-orders/:id/items"
13086
13078
  },
13079
+ {
13080
+ Component: CustomItems,
13081
+ path: "/draft-orders/:id/custom-items"
13082
+ },
13083
+ {
13084
+ Component: Metadata,
13085
+ path: "/draft-orders/:id/metadata"
13086
+ },
13087
13087
  {
13088
13088
  Component: Promotions,
13089
13089
  path: "/draft-orders/:id/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
  }