medusa-plugin-complaints 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
1
  import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
- import { Container, Heading, Button, Text, Badge, clx, createDataTableColumnHelper, createDataTableCommandHelper, usePrompt, createDataTableFilterHelper, useDataTable, DataTable, FocusModal, Input, toast, DropdownMenu, IconButton, Textarea, Tooltip, Avatar, Drawer, Label, Select } from "@medusajs/ui";
2
+ import { Container, Heading, Button, Text, Badge, clx, createDataTableColumnHelper, createDataTableCommandHelper, usePrompt, createDataTableFilterHelper, useDataTable, DataTable, FocusModal, Input, toast, Select, Textarea, DropdownMenu, IconButton, Tooltip, Avatar, Drawer, Label } from "@medusajs/ui";
3
3
  import { defineWidgetConfig, defineRouteConfig } from "@medusajs/admin-sdk";
4
4
  import { useQuery, useQueryClient, useMutation } from "@tanstack/react-query";
5
- import { useNavigate, Outlet, Link, useBlocker, useParams, useSearchParams } from "react-router-dom";
5
+ import { useNavigate, Outlet, Link, useBlocker, useSearchParams, useParams } from "react-router-dom";
6
6
  import Medusa from "@medusajs/js-sdk";
7
7
  import React, { useState, useMemo, useEffect } from "react";
8
8
  import { FaceDisappointed, EllipsisHorizontal, PencilSquare, Trash } from "@medusajs/icons";
@@ -6495,6 +6495,258 @@ const ComplaintStatsPage = () => {
6495
6495
  /* @__PURE__ */ jsx("div", { className: "px-6 py-8", children: /* @__PURE__ */ jsx(Button, { variant: "primary", onClick: () => mutate(void 0, { onSuccess: () => toast.success("Complaint stats updated successfully"), onError: () => toast.error("Failed to update complaint stats") }), isLoading: isPending, children: "Recalculate Complaint Stats" }) })
6496
6496
  ] });
6497
6497
  };
6498
+ const schema$3 = object({
6499
+ description: string().min(1, "Required"),
6500
+ customer_id: string().min(1, "Required"),
6501
+ order_id: string().min(1, "Required"),
6502
+ product_id: string().min(1, "Required"),
6503
+ tag_ids: array(string()).optional()
6504
+ });
6505
+ const CreateComplaintModal = ({
6506
+ open,
6507
+ setOpen,
6508
+ customerId,
6509
+ orderId
6510
+ }) => {
6511
+ var _a2, _b;
6512
+ const navigate = useNavigate();
6513
+ const { mutate: createComplaint, isPending } = useCreateComplaint();
6514
+ const prompt = usePrompt();
6515
+ const form = useForm({
6516
+ resolver: t(schema$3),
6517
+ defaultValues: {
6518
+ description: "",
6519
+ customer_id: customerId,
6520
+ order_id: orderId ?? "",
6521
+ product_id: "",
6522
+ tag_ids: []
6523
+ }
6524
+ });
6525
+ const { formState } = form;
6526
+ const { isDirty } = formState;
6527
+ const selectedOrderId = useWatch({ control: form.control, name: "order_id" });
6528
+ const { data: customerData, isLoading: customerLoading } = useCustomerWithOrders(customerId);
6529
+ const customerOrders = (customerData == null ? void 0 : customerData.customer.orders) ?? [];
6530
+ const { data: orderData, isLoading: orderLoading } = useOrder(selectedOrderId);
6531
+ const orderProducts = Object.values(
6532
+ (((_a2 = orderData == null ? void 0 : orderData.order) == null ? void 0 : _a2.items) ?? []).reduce(
6533
+ (acc, item) => {
6534
+ if (item.product_id && !acc[item.product_id]) {
6535
+ acc[item.product_id] = { id: item.product_id, title: item.product_title ?? "" };
6536
+ }
6537
+ return acc;
6538
+ },
6539
+ {}
6540
+ )
6541
+ );
6542
+ const { data: tagsData } = useComplaintTags();
6543
+ const [selectedTagIds, setSelectedTagIds] = useState([]);
6544
+ const [tagSelectValue, setTagSelectValue] = useState("");
6545
+ const [success, setSuccess] = useState(false);
6546
+ let blocker = useBlocker(
6547
+ ({ currentLocation, nextLocation }) => isDirty && formState.dirtyFields.description === true && currentLocation.pathname !== nextLocation.pathname
6548
+ );
6549
+ const handleNavigate = async () => {
6550
+ if (blocker.state !== "blocked") return;
6551
+ if (success) {
6552
+ blocker.proceed();
6553
+ return;
6554
+ }
6555
+ const confirmed = await prompt({
6556
+ title: "Are you sure you want to leave this form?",
6557
+ description: "You have unsaved changes that will be lost if you exit this form.",
6558
+ confirmText: "Continue",
6559
+ cancelText: "Cancel",
6560
+ variant: "confirmation"
6561
+ });
6562
+ if (confirmed) {
6563
+ blocker.proceed();
6564
+ } else {
6565
+ blocker.reset();
6566
+ }
6567
+ };
6568
+ useEffect(() => {
6569
+ if (blocker.state === "blocked") {
6570
+ handleNavigate();
6571
+ }
6572
+ }, [isDirty, open, blocker]);
6573
+ const handleSubmit = form.handleSubmit((data) => {
6574
+ createComplaint(data, {
6575
+ onSuccess: (result) => {
6576
+ toast.success("Complaint created successfully");
6577
+ setSuccess(true);
6578
+ form.reset();
6579
+ navigate(`/complaints/${result.complaint.id}`);
6580
+ },
6581
+ onError: () => toast.error("Failed to create complaint")
6582
+ });
6583
+ });
6584
+ if (!customerId) {
6585
+ return /* @__PURE__ */ jsx(FocusModal, { open, children: /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
6586
+ /* @__PURE__ */ jsx(FocusModal.Header, { children: /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Error" }) }),
6587
+ /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx(Text, { children: "Customer ID is required to create a complaint." }) })
6588
+ ] }) });
6589
+ }
6590
+ return /* @__PURE__ */ jsx(FocusModal, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsx(FocusModal.Content, { children: /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex h-full flex-col overflow-hidden", children: [
6591
+ /* @__PURE__ */ jsx(FocusModal.Header, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
6592
+ /* @__PURE__ */ jsx(FocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
6593
+ /* @__PURE__ */ jsx(Button, { type: "submit", size: "small", isLoading: isPending, children: "Save" })
6594
+ ] }) }),
6595
+ /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full max-w-[720px] flex-col gap-y-8 px-2 py-16", children: [
6596
+ /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Heading, { className: "capitalize", children: "Create Complaint" }) }),
6597
+ /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4", children: [
6598
+ /* @__PURE__ */ jsx(
6599
+ Controller,
6600
+ {
6601
+ control: form.control,
6602
+ name: "customer_id",
6603
+ render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
6604
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Customer ID" }),
6605
+ /* @__PURE__ */ jsx(Input, { ...field, disabled: true })
6606
+ ] })
6607
+ }
6608
+ ),
6609
+ /* @__PURE__ */ jsx(
6610
+ Controller,
6611
+ {
6612
+ control: form.control,
6613
+ name: "order_id",
6614
+ rules: { required: "Order is required" },
6615
+ render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
6616
+ /* @__PURE__ */ jsxs(Text, { size: "small", weight: "plus", children: [
6617
+ "Order ",
6618
+ /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
6619
+ ] }),
6620
+ customerLoading ? /* @__PURE__ */ jsx(Text, { size: "small", children: "Loading orders..." }) : /* @__PURE__ */ jsxs(
6621
+ Select,
6622
+ {
6623
+ value: field.value,
6624
+ onValueChange: (value) => {
6625
+ field.onChange(value);
6626
+ form.setValue("product_id", "");
6627
+ },
6628
+ children: [
6629
+ /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select an order from this customer" }) }),
6630
+ /* @__PURE__ */ jsx(Select.Content, { children: customerOrders.map((order) => /* @__PURE__ */ jsxs(Select.Item, { value: order.id, children: [
6631
+ new Date(order.created_at).toLocaleString(
6632
+ "en-US",
6633
+ {
6634
+ year: "numeric",
6635
+ month: "short",
6636
+ day: "numeric"
6637
+ }
6638
+ ),
6639
+ " ",
6640
+ "- #",
6641
+ order.display_id
6642
+ ] }, order.id)) })
6643
+ ]
6644
+ }
6645
+ )
6646
+ ] })
6647
+ }
6648
+ ),
6649
+ /* @__PURE__ */ jsx(
6650
+ Controller,
6651
+ {
6652
+ control: form.control,
6653
+ name: "product_id",
6654
+ render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
6655
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Product" }),
6656
+ orderLoading ? /* @__PURE__ */ jsx(Text, { size: "small", children: "Loading..." }) : /* @__PURE__ */ jsxs(
6657
+ Select,
6658
+ {
6659
+ value: field.value,
6660
+ onValueChange: field.onChange,
6661
+ children: [
6662
+ /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select a product" }) }),
6663
+ /* @__PURE__ */ jsx(Select.Content, { children: orderProducts == null ? void 0 : orderProducts.map((product) => /* @__PURE__ */ jsx(Select.Item, { value: product.id, children: product.title }, product.id)) })
6664
+ ]
6665
+ }
6666
+ )
6667
+ ] })
6668
+ }
6669
+ ),
6670
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
6671
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Tags" }),
6672
+ selectedTagIds.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2 mb-2", children: selectedTagIds.map((tagId) => {
6673
+ var _a3;
6674
+ const tag = (_a3 = tagsData == null ? void 0 : tagsData.complaint_tags) == null ? void 0 : _a3.find(
6675
+ (t2) => t2.id === tagId
6676
+ );
6677
+ return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
6678
+ /* @__PURE__ */ jsx(Badge, { size: "xsmall", color: "blue", children: (tag == null ? void 0 : tag.value) ?? tagId }),
6679
+ /* @__PURE__ */ jsx(
6680
+ "button",
6681
+ {
6682
+ type: "button",
6683
+ onClick: () => setSelectedTagIds(
6684
+ (prev) => prev.filter((id) => id !== tagId)
6685
+ ),
6686
+ className: "text-ui-fg-subtle hover:text-ui-fg-base text-xs",
6687
+ "aria-label": `Remove tag ${tag == null ? void 0 : tag.value}`,
6688
+ children: "✕"
6689
+ }
6690
+ )
6691
+ ] }, tagId);
6692
+ }) }),
6693
+ /* @__PURE__ */ jsxs(
6694
+ Select,
6695
+ {
6696
+ value: tagSelectValue,
6697
+ onValueChange: (value) => {
6698
+ if (value && !selectedTagIds.includes(value)) {
6699
+ setSelectedTagIds((prev) => [...prev, value]);
6700
+ }
6701
+ form.setValue("tag_ids", [...selectedTagIds, value], {
6702
+ shouldDirty: true
6703
+ });
6704
+ setTagSelectValue("");
6705
+ },
6706
+ children: [
6707
+ /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Add a tag..." }) }),
6708
+ /* @__PURE__ */ jsx(Select.Content, { children: (_b = tagsData == null ? void 0 : tagsData.complaint_tags) == null ? void 0 : _b.filter((tag) => !selectedTagIds.includes(tag.id)).map((tag) => /* @__PURE__ */ jsx(Select.Item, { value: tag.id, children: tag.value }, tag.id)) })
6709
+ ]
6710
+ }
6711
+ )
6712
+ ] }),
6713
+ /* @__PURE__ */ jsx(
6714
+ Controller,
6715
+ {
6716
+ control: form.control,
6717
+ name: "description",
6718
+ render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
6719
+ /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Description" }),
6720
+ /* @__PURE__ */ jsx(Textarea, { ...field })
6721
+ ] })
6722
+ }
6723
+ )
6724
+ ] })
6725
+ ] }) }) })
6726
+ ] }) }) }) });
6727
+ };
6728
+ const CreateComplaintPage = () => {
6729
+ const [searchParams] = useSearchParams();
6730
+ const navigate = useNavigate();
6731
+ const customerId = searchParams.get("customer_id") ?? "";
6732
+ const orderId = searchParams.get("order_id") ?? "";
6733
+ const [createOpen, setCreateOpen] = useState(true);
6734
+ const handleOpenChange = (open) => {
6735
+ setCreateOpen(open);
6736
+ if (!open) {
6737
+ navigate("/complaints", { replace: true });
6738
+ }
6739
+ };
6740
+ return /* @__PURE__ */ jsx(
6741
+ CreateComplaintModal,
6742
+ {
6743
+ customerId,
6744
+ orderId,
6745
+ open: createOpen,
6746
+ setOpen: handleOpenChange
6747
+ }
6748
+ );
6749
+ };
6498
6750
  const ActionMenu = ({ groups }) => {
6499
6751
  return /* @__PURE__ */ jsxs(DropdownMenu, { children: [
6500
6752
  /* @__PURE__ */ jsx(DropdownMenu.Trigger, { asChild: true, children: /* @__PURE__ */ jsx(IconButton, { size: "small", variant: "transparent", children: /* @__PURE__ */ jsx(EllipsisHorizontal, {}) }) }),
@@ -8207,7 +8459,7 @@ const useDate = () => {
8207
8459
  getRelativeDate
8208
8460
  };
8209
8461
  };
8210
- const schema$3 = object({
8462
+ const schema$2 = object({
8211
8463
  note: string().min(1, "Required")
8212
8464
  });
8213
8465
  const ComplaintNoteModal = ({
@@ -8220,7 +8472,7 @@ const ComplaintNoteModal = ({
8220
8472
  const { mutate: updateNote } = useUpdateNote(complaintId, note == null ? void 0 : note.id);
8221
8473
  const prompt = usePrompt();
8222
8474
  const form = useForm({
8223
- resolver: t(schema$3),
8475
+ resolver: t(schema$2),
8224
8476
  defaultValues: {
8225
8477
  note: (note == null ? void 0 : note.note) || ""
8226
8478
  }
@@ -8412,7 +8664,7 @@ const ComplaintActivity = ({ complaint }) => {
8412
8664
  )
8413
8665
  ] });
8414
8666
  };
8415
- const schema$2 = object({
8667
+ const schema$1 = object({
8416
8668
  order_id: string().min(1, "Required"),
8417
8669
  product_id: string().min(1, "Required"),
8418
8670
  number: number(),
@@ -8426,7 +8678,7 @@ const EditComplaintDrawer = ({ complaint, open, setOpen }) => {
8426
8678
  const updateMutation = useUpdateComplaint(complaint.id);
8427
8679
  const prompt = usePrompt();
8428
8680
  const form = useForm({
8429
- resolver: t(schema$2),
8681
+ resolver: t(schema$1),
8430
8682
  defaultValues: {
8431
8683
  number: 0,
8432
8684
  status: "open",
@@ -8724,258 +8976,6 @@ const ComplaintDetailPage = () => {
8724
8976
  /* @__PURE__ */ jsx(EditComplaintDrawer, { complaint, open: editOpen, setOpen: setEditOpen })
8725
8977
  ] });
8726
8978
  };
8727
- const schema$1 = object({
8728
- description: string().min(1, "Required"),
8729
- customer_id: string().min(1, "Required"),
8730
- order_id: string().min(1, "Required"),
8731
- product_id: string().min(1, "Required"),
8732
- tag_ids: array(string()).optional()
8733
- });
8734
- const CreateComplaintModal = ({
8735
- open,
8736
- setOpen,
8737
- customerId,
8738
- orderId
8739
- }) => {
8740
- var _a2, _b;
8741
- const navigate = useNavigate();
8742
- const { mutate: createComplaint, isPending } = useCreateComplaint();
8743
- const prompt = usePrompt();
8744
- const form = useForm({
8745
- resolver: t(schema$1),
8746
- defaultValues: {
8747
- description: "",
8748
- customer_id: customerId,
8749
- order_id: orderId ?? "",
8750
- product_id: "",
8751
- tag_ids: []
8752
- }
8753
- });
8754
- const { formState } = form;
8755
- const { isDirty } = formState;
8756
- const selectedOrderId = useWatch({ control: form.control, name: "order_id" });
8757
- const { data: customerData, isLoading: customerLoading } = useCustomerWithOrders(customerId);
8758
- const customerOrders = (customerData == null ? void 0 : customerData.customer.orders) ?? [];
8759
- const { data: orderData, isLoading: orderLoading } = useOrder(selectedOrderId);
8760
- const orderProducts = Object.values(
8761
- (((_a2 = orderData == null ? void 0 : orderData.order) == null ? void 0 : _a2.items) ?? []).reduce(
8762
- (acc, item) => {
8763
- if (item.product_id && !acc[item.product_id]) {
8764
- acc[item.product_id] = { id: item.product_id, title: item.product_title ?? "" };
8765
- }
8766
- return acc;
8767
- },
8768
- {}
8769
- )
8770
- );
8771
- const { data: tagsData } = useComplaintTags();
8772
- const [selectedTagIds, setSelectedTagIds] = useState([]);
8773
- const [tagSelectValue, setTagSelectValue] = useState("");
8774
- const [success, setSuccess] = useState(false);
8775
- let blocker = useBlocker(
8776
- ({ currentLocation, nextLocation }) => isDirty && formState.dirtyFields.description === true && currentLocation.pathname !== nextLocation.pathname
8777
- );
8778
- const handleNavigate = async () => {
8779
- if (blocker.state !== "blocked") return;
8780
- if (success) {
8781
- blocker.proceed();
8782
- return;
8783
- }
8784
- const confirmed = await prompt({
8785
- title: "Are you sure you want to leave this form?",
8786
- description: "You have unsaved changes that will be lost if you exit this form.",
8787
- confirmText: "Continue",
8788
- cancelText: "Cancel",
8789
- variant: "confirmation"
8790
- });
8791
- if (confirmed) {
8792
- blocker.proceed();
8793
- } else {
8794
- blocker.reset();
8795
- }
8796
- };
8797
- useEffect(() => {
8798
- if (blocker.state === "blocked") {
8799
- handleNavigate();
8800
- }
8801
- }, [isDirty, open, blocker]);
8802
- const handleSubmit = form.handleSubmit((data) => {
8803
- createComplaint(data, {
8804
- onSuccess: (result) => {
8805
- toast.success("Complaint created successfully");
8806
- setSuccess(true);
8807
- form.reset();
8808
- navigate(`/complaints/${result.complaint.id}`);
8809
- },
8810
- onError: () => toast.error("Failed to create complaint")
8811
- });
8812
- });
8813
- if (!customerId) {
8814
- return /* @__PURE__ */ jsx(FocusModal, { open, children: /* @__PURE__ */ jsxs(FocusModal.Content, { children: [
8815
- /* @__PURE__ */ jsx(FocusModal.Header, { children: /* @__PURE__ */ jsx(Heading, { level: "h2", children: "Error" }) }),
8816
- /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx(Text, { children: "Customer ID is required to create a complaint." }) })
8817
- ] }) });
8818
- }
8819
- return /* @__PURE__ */ jsx(FocusModal, { open, onOpenChange: setOpen, children: /* @__PURE__ */ jsx(FocusModal.Content, { children: /* @__PURE__ */ jsx(FormProvider, { ...form, children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit, className: "flex h-full flex-col overflow-hidden", children: [
8820
- /* @__PURE__ */ jsx(FocusModal.Header, { children: /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-end gap-x-2", children: [
8821
- /* @__PURE__ */ jsx(FocusModal.Close, { asChild: true, children: /* @__PURE__ */ jsx(Button, { size: "small", variant: "secondary", children: "Cancel" }) }),
8822
- /* @__PURE__ */ jsx(Button, { type: "submit", size: "small", isLoading: isPending, children: "Save" })
8823
- ] }) }),
8824
- /* @__PURE__ */ jsx(FocusModal.Body, { children: /* @__PURE__ */ jsx("div", { className: "flex flex-1 flex-col items-center overflow-y-auto", children: /* @__PURE__ */ jsxs("div", { className: "mx-auto flex w-full max-w-[720px] flex-col gap-y-8 px-2 py-16", children: [
8825
- /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Heading, { className: "capitalize", children: "Create Complaint" }) }),
8826
- /* @__PURE__ */ jsxs("div", { className: "grid grid-cols-1 gap-4", children: [
8827
- /* @__PURE__ */ jsx(
8828
- Controller,
8829
- {
8830
- control: form.control,
8831
- name: "customer_id",
8832
- render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
8833
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Customer ID" }),
8834
- /* @__PURE__ */ jsx(Input, { ...field, disabled: true })
8835
- ] })
8836
- }
8837
- ),
8838
- /* @__PURE__ */ jsx(
8839
- Controller,
8840
- {
8841
- control: form.control,
8842
- name: "order_id",
8843
- rules: { required: "Order is required" },
8844
- render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
8845
- /* @__PURE__ */ jsxs(Text, { size: "small", weight: "plus", children: [
8846
- "Order ",
8847
- /* @__PURE__ */ jsx("span", { className: "text-red-500", children: "*" })
8848
- ] }),
8849
- customerLoading ? /* @__PURE__ */ jsx(Text, { size: "small", children: "Loading orders..." }) : /* @__PURE__ */ jsxs(
8850
- Select,
8851
- {
8852
- value: field.value,
8853
- onValueChange: (value) => {
8854
- field.onChange(value);
8855
- form.setValue("product_id", "");
8856
- },
8857
- children: [
8858
- /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select an order from this customer" }) }),
8859
- /* @__PURE__ */ jsx(Select.Content, { children: customerOrders.map((order) => /* @__PURE__ */ jsxs(Select.Item, { value: order.id, children: [
8860
- new Date(order.created_at).toLocaleString(
8861
- "en-US",
8862
- {
8863
- year: "numeric",
8864
- month: "short",
8865
- day: "numeric"
8866
- }
8867
- ),
8868
- " ",
8869
- "- #",
8870
- order.display_id
8871
- ] }, order.id)) })
8872
- ]
8873
- }
8874
- )
8875
- ] })
8876
- }
8877
- ),
8878
- /* @__PURE__ */ jsx(
8879
- Controller,
8880
- {
8881
- control: form.control,
8882
- name: "product_id",
8883
- render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
8884
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Product" }),
8885
- orderLoading ? /* @__PURE__ */ jsx(Text, { size: "small", children: "Loading..." }) : /* @__PURE__ */ jsxs(
8886
- Select,
8887
- {
8888
- value: field.value,
8889
- onValueChange: field.onChange,
8890
- children: [
8891
- /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Select a product" }) }),
8892
- /* @__PURE__ */ jsx(Select.Content, { children: orderProducts == null ? void 0 : orderProducts.map((product) => /* @__PURE__ */ jsx(Select.Item, { value: product.id, children: product.title }, product.id)) })
8893
- ]
8894
- }
8895
- )
8896
- ] })
8897
- }
8898
- ),
8899
- /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
8900
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Tags" }),
8901
- selectedTagIds.length > 0 && /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2 mb-2", children: selectedTagIds.map((tagId) => {
8902
- var _a3;
8903
- const tag = (_a3 = tagsData == null ? void 0 : tagsData.complaint_tags) == null ? void 0 : _a3.find(
8904
- (t2) => t2.id === tagId
8905
- );
8906
- return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
8907
- /* @__PURE__ */ jsx(Badge, { size: "xsmall", color: "blue", children: (tag == null ? void 0 : tag.value) ?? tagId }),
8908
- /* @__PURE__ */ jsx(
8909
- "button",
8910
- {
8911
- type: "button",
8912
- onClick: () => setSelectedTagIds(
8913
- (prev) => prev.filter((id) => id !== tagId)
8914
- ),
8915
- className: "text-ui-fg-subtle hover:text-ui-fg-base text-xs",
8916
- "aria-label": `Remove tag ${tag == null ? void 0 : tag.value}`,
8917
- children: "✕"
8918
- }
8919
- )
8920
- ] }, tagId);
8921
- }) }),
8922
- /* @__PURE__ */ jsxs(
8923
- Select,
8924
- {
8925
- value: tagSelectValue,
8926
- onValueChange: (value) => {
8927
- if (value && !selectedTagIds.includes(value)) {
8928
- setSelectedTagIds((prev) => [...prev, value]);
8929
- }
8930
- form.setValue("tag_ids", [...selectedTagIds, value], {
8931
- shouldDirty: true
8932
- });
8933
- setTagSelectValue("");
8934
- },
8935
- children: [
8936
- /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(Select.Value, { placeholder: "Add a tag..." }) }),
8937
- /* @__PURE__ */ jsx(Select.Content, { children: (_b = tagsData == null ? void 0 : tagsData.complaint_tags) == null ? void 0 : _b.filter((tag) => !selectedTagIds.includes(tag.id)).map((tag) => /* @__PURE__ */ jsx(Select.Item, { value: tag.id, children: tag.value }, tag.id)) })
8938
- ]
8939
- }
8940
- )
8941
- ] }),
8942
- /* @__PURE__ */ jsx(
8943
- Controller,
8944
- {
8945
- control: form.control,
8946
- name: "description",
8947
- render: ({ field }) => /* @__PURE__ */ jsxs("div", { className: "flex flex-col space-y-2", children: [
8948
- /* @__PURE__ */ jsx(Text, { size: "small", weight: "plus", children: "Description" }),
8949
- /* @__PURE__ */ jsx(Textarea, { ...field })
8950
- ] })
8951
- }
8952
- )
8953
- ] })
8954
- ] }) }) })
8955
- ] }) }) }) });
8956
- };
8957
- const CreateComplaintPage = () => {
8958
- const [searchParams] = useSearchParams();
8959
- const navigate = useNavigate();
8960
- const customerId = searchParams.get("customer_id") ?? "";
8961
- const orderId = searchParams.get("order_id") ?? "";
8962
- const [createOpen, setCreateOpen] = useState(true);
8963
- const handleOpenChange = (open) => {
8964
- setCreateOpen(open);
8965
- if (!open) {
8966
- navigate("/complaints", { replace: true });
8967
- }
8968
- };
8969
- return /* @__PURE__ */ jsx(
8970
- CreateComplaintModal,
8971
- {
8972
- customerId,
8973
- orderId,
8974
- open: createOpen,
8975
- setOpen: handleOpenChange
8976
- }
8977
- );
8978
- };
8979
8979
  const schema = object({
8980
8980
  value: string().min(1, "Required")
8981
8981
  });
@@ -9138,16 +9138,16 @@ const routeModule = {
9138
9138
  path: "/settings/complaint-stats",
9139
9139
  handle: handle$2
9140
9140
  },
9141
+ {
9142
+ Component: CreateComplaintPage,
9143
+ path: "/complaints/create"
9144
+ },
9141
9145
  {
9142
9146
  Component: ComplaintDetailPage,
9143
9147
  path: "/complaints/:id",
9144
9148
  handle: handle$1,
9145
9149
  loader: loader$1
9146
9150
  },
9147
- {
9148
- Component: CreateComplaintPage,
9149
- path: "/complaints/create"
9150
- },
9151
9151
  {
9152
9152
  Component: ComplaintTagDetailPage,
9153
9153
  path: "/settings/complaint-tags/:id",
@@ -23,8 +23,8 @@ export declare const ComplaintActivity: import("@medusajs/framework/utils").DmlE
23
23
  tags: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
24
24
  id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
25
25
  value: import("@medusajs/framework/utils").TextProperty;
26
- complaints: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<any>, "complaint">>;
26
+ complaints: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "complaint">>;
27
27
  }>, "complaint_tag">>;
28
- activity: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<any>, "complaint_activity">>;
28
+ activity: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "complaint_activity">>;
29
29
  }>, "complaint">, undefined>;
30
30
  }>, "complaint_activity">;
@@ -12,14 +12,14 @@ export declare const ComplaintTag: import("@medusajs/framework/utils").DmlEntity
12
12
  serial_number_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
13
13
  stock_lot_id: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
14
14
  metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
15
- tags: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<any>, "complaint_tag">>;
15
+ tags: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "complaint_tag">>;
16
16
  activity: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
17
17
  id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
18
18
  type: import("@medusajs/framework/utils").EnumProperty<typeof import("./complaint-activity").ComplaintActivityType>;
19
19
  user_id: import("@medusajs/framework/utils").TextProperty;
20
20
  note: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
21
21
  metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
22
- complaint: import("@medusajs/framework/utils").BelongsTo<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<any>, "complaint">, undefined>;
22
+ complaint: import("@medusajs/framework/utils").BelongsTo<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "complaint">, undefined>;
23
23
  }>, "complaint_activity">>;
24
24
  }>, "complaint">>;
25
25
  }>, "complaint_tag">;
@@ -16,7 +16,7 @@ export declare const Complaint: import("@medusajs/framework/utils").DmlEntity<im
16
16
  tags: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
17
17
  id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
18
18
  value: import("@medusajs/framework/utils").TextProperty;
19
- complaints: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<any>, "complaint">>;
19
+ complaints: import("@medusajs/framework/utils").ManyToMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "complaint">>;
20
20
  }>, "complaint_tag">>;
21
21
  activity: import("@medusajs/framework/utils").HasMany<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<{
22
22
  id: import("@medusajs/framework/utils").PrimaryKeyModifier<string, import("@medusajs/framework/utils").IdProperty>;
@@ -24,6 +24,6 @@ export declare const Complaint: import("@medusajs/framework/utils").DmlEntity<im
24
24
  user_id: import("@medusajs/framework/utils").TextProperty;
25
25
  note: import("@medusajs/framework/utils").NullableModifier<string, import("@medusajs/framework/utils").TextProperty>;
26
26
  metadata: import("@medusajs/framework/utils").NullableModifier<Record<string, unknown>, import("@medusajs/framework/utils").JSONProperty>;
27
- complaint: import("@medusajs/framework/utils").BelongsTo<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder<any>, "complaint">, undefined>;
27
+ complaint: import("@medusajs/framework/utils").BelongsTo<() => import("@medusajs/framework/utils").DmlEntity<import("@medusajs/framework/utils").DMLEntitySchemaBuilder</*elided*/ any>, "complaint">, undefined>;
28
28
  }>, "complaint_activity">>;
29
29
  }>, "complaint">;