Skip to content

Commit 2eca81e

Browse files
authored
feat(dashboard): add input field for tracking_url and label_url in shipment form (medusajs#13787)
* fix: fix label init logic * feat(dashboard): add input field for tracking_url and label_url in shipment form * fix: cleanup leftovers * chore: update schema * fix: filter out empty rows * chore: remove unrelated change * fix: allow any filled field
1 parent cc2614d commit 2eca81e

File tree

4 files changed

+103
-28
lines changed

4 files changed

+103
-28
lines changed

.changeset/sour-schools-return.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@medusajs/dashboard": patch
3+
---
4+
5+
add input field for tracking_url and label_url in shipment form

packages/admin/dashboard/src/i18n/translations/$schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5081,6 +5081,12 @@
50815081
"trackingNumber": {
50825082
"type": "string"
50835083
},
5084+
"trackingUrl": {
5085+
"type": "string"
5086+
},
5087+
"labelUrl": {
5088+
"type": "string"
5089+
},
50845090
"addTracking": {
50855091
"type": "string"
50865092
},
@@ -5097,6 +5103,8 @@
50975103
"required": [
50985104
"title",
50995105
"trackingNumber",
5106+
"trackingUrl",
5107+
"labelUrl",
51005108
"addTracking",
51015109
"sendNotification",
51025110
"sendNotificationHint",

packages/admin/dashboard/src/i18n/translations/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,8 @@
13501350
"shipment": {
13511351
"title": "Mark fulfillment shipped",
13521352
"trackingNumber": "Tracking number",
1353+
"trackingUrl": "Tracking URL",
1354+
"labelUrl": "Label URL",
13531355
"addTracking": "Add tracking number",
13541356
"sendNotification": "Send notification",
13551357
"sendNotificationHint": "Notify the customer about this shipment.",

packages/admin/dashboard/src/routes/orders/order-create-shipment/components/order-create-shipment-form/order-create-shipment-form.tsx

Lines changed: 88 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useTranslation } from "react-i18next"
33
import * as zod from "zod"
44

55
import { AdminFulfillment, AdminOrder } from "@medusajs/types"
6-
import { Button, Heading, Input, Switch, toast } from "@medusajs/ui"
6+
import { Button, clx, Heading, Input, Switch, toast } from "@medusajs/ui"
77
import { useFieldArray, useForm } from "react-hook-form"
88

99
import { Form } from "../../../../../components/common/form"
@@ -44,11 +44,11 @@ export function OrderCreateShipmentForm({
4444

4545
const handleSubmit = form.handleSubmit(async (data) => {
4646
const addedLabels = data.labels
47-
.filter((l) => !!l.tracking_number)
47+
.filter((l) => !!l.tracking_number || !!l.tracking_url || !!l.label_url)
4848
.map((l) => ({
4949
tracking_number: l.tracking_number,
50-
tracking_url: "#",
51-
label_url: "#",
50+
tracking_url: l.tracking_url || "#",
51+
label_url: l.label_url || "#",
5252
}))
5353

5454
await createShipment(
@@ -89,33 +89,93 @@ export function OrderCreateShipmentForm({
8989
{t("orders.shipment.title")}
9090
</Heading>
9191

92-
{labels.map((label, index) => (
93-
<Form.Field
94-
key={label.id}
95-
control={form.control}
96-
name={`labels.${index}.tracking_number`}
97-
render={({ field }) => {
98-
return (
99-
<Form.Item className="mb-4">
100-
{index === 0 && (
101-
<Form.Label>
102-
{t("orders.shipment.trackingNumber")}
103-
</Form.Label>
104-
)}
105-
<Form.Control>
106-
<Input {...field} placeholder="123-456-789" />
107-
</Form.Control>
108-
<Form.ErrorMessage />
109-
</Form.Item>
110-
)
111-
}}
112-
/>
113-
))}
92+
<div className="flex flex-col max-md:gap-y-2 max-md:divide-y">
93+
{labels.map((label, index) => (
94+
<div
95+
key={label.id}
96+
className={clx(
97+
"grid grid-cols-1 gap-x-4 md:grid-cols-3",
98+
{ "max-md:pt-4": index > 0 }
99+
)}
100+
>
101+
<Form.Field
102+
control={form.control}
103+
name={`labels.${index}.tracking_number`}
104+
render={({ field }) => {
105+
return (
106+
<Form.Item className="mb-2">
107+
<Form.Label
108+
className={clx({ "md:hidden": index > 0 })}
109+
>
110+
{t("orders.shipment.trackingNumber")}
111+
</Form.Label>
112+
113+
<Form.Control>
114+
<Input {...field} placeholder="123-456-789" />
115+
</Form.Control>
116+
<Form.ErrorMessage />
117+
</Form.Item>
118+
)
119+
}}
120+
/>
121+
<Form.Field
122+
control={form.control}
123+
name={`labels.${index}.tracking_url`}
124+
render={({ field }) => {
125+
return (
126+
<Form.Item className="mb-2">
127+
<Form.Label
128+
className={clx({ "md:hidden": index > 0 })}
129+
>
130+
{t("orders.shipment.trackingUrl")}
131+
</Form.Label>
132+
<Form.Control>
133+
<Input
134+
{...field}
135+
placeholder="https://example.com/tracking/123"
136+
/>
137+
</Form.Control>
138+
<Form.ErrorMessage />
139+
</Form.Item>
140+
)
141+
}}
142+
/>
143+
<Form.Field
144+
control={form.control}
145+
name={`labels.${index}.label_url`}
146+
render={({ field }) => {
147+
return (
148+
<Form.Item className="mb-2">
149+
<Form.Label
150+
className={clx({ "md:hidden": index > 0 })}
151+
>
152+
{t("orders.shipment.labelUrl")}
153+
</Form.Label>
154+
<Form.Control>
155+
<Input
156+
{...field}
157+
placeholder="https://example.com/label/123"
158+
/>
159+
</Form.Control>
160+
<Form.ErrorMessage />
161+
</Form.Item>
162+
)
163+
}}
164+
/>
165+
</div>
166+
))}
167+
</div>
114168

115169
<Button
116170
type="button"
117-
onClick={() => append({ tracking_number: "" })}
118-
className="self-end"
171+
onClick={() =>
172+
append({
173+
tracking_number: "",
174+
label_url: "",
175+
tracking_url: "",
176+
})
177+
}
178+
className="mt-2 self-end"
119179
variant="secondary"
120180
>
121181
{t("orders.shipment.addTracking")}

0 commit comments

Comments
 (0)