Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dashboard): shipping & location #7151

Merged
merged 41 commits into from May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
30db470
feat: initial commit, move things around
fPolic Apr 23, 2024
b913ab8
wip: details
fPolic Apr 24, 2024
7358378
wip: details fulfillment set logic
fPolic Apr 24, 2024
1fa8231
fix: chance key,rework create service zone
fPolic Apr 25, 2024
7d05674
feat: zones list rework
fPolic Apr 25, 2024
17939a5
feat: SO section
fPolic Apr 25, 2024
2039c67
feat: setup for SCs
fPolic Apr 25, 2024
151c5ce
feat: SC management
fPolic Apr 25, 2024
1976e3f
fix: temp. fields joining
fPolic Apr 26, 2024
a9330b1
feat: edit service zone
fPolic Apr 26, 2024
4bb9e00
fix: multiple query key issues and cache invalidations
fPolic Apr 26, 2024
e838f04
fix: build
fPolic Apr 26, 2024
4702151
wip: shipping options edit
fPolic Apr 26, 2024
3bd81ac
feat: finish shipping options edit
fPolic Apr 28, 2024
e24b979
Merge branch 'develop' into feat/shipping-refresh
fPolic Apr 29, 2024
e99330c
feat: remove old locations
fPolic Apr 29, 2024
affd759
feat: fulfillment providers listing, fix edit location
fPolic Apr 29, 2024
f3578be
feat: make region pricing work on create
fPolic Apr 29, 2024
884f121
feat: return options flows
fPolic Apr 29, 2024
b27ea97
fix: bg
fPolic Apr 29, 2024
56b0a47
Merge branch 'develop' into feat/shipping-refresh
fPolic Apr 29, 2024
e07f3b0
fix: missing delete todo, add confirm/toast
fPolic Apr 29, 2024
cb4c662
Merge branch 'develop' into feat/shipping-refresh
fPolic Apr 30, 2024
ad4935f
feat: handle rules on create/update, in store rule, fix boolean conve…
fPolic Apr 30, 2024
aee6fa3
feat: finalize prompts and toasts, fix wrong query keys
fPolic Apr 30, 2024
521de58
fix: query key collision
fPolic Apr 30, 2024
9acfaa4
fix: details
fPolic Apr 30, 2024
1a291d2
fix: toggling sets
fPolic Apr 30, 2024
a8467c9
fix: SC endpoints usage
fPolic Apr 30, 2024
ece4278
fix: zone queries
fPolic Apr 30, 2024
05f0801
fix: return `provider_id` for shipping options
fPolic Apr 30, 2024
588534b
Merge branch 'develop' into feat/shipping-refresh
fPolic May 2, 2024
9a234e5
fix: location redirect and border
fPolic May 2, 2024
793e6e0
fix: "pickup" typo
fPolic May 2, 2024
3f299cf
fix: adjust divider to follow design better
fPolic May 2, 2024
49dc946
feat: display connected channels on location list page
fPolic May 2, 2024
15764f9
feat: editing "in_store"
fPolic May 2, 2024
9790591
fix: query param
fPolic May 2, 2024
8ae3cab
Merge branch 'develop' into feat/shipping-refresh
fPolic May 2, 2024
f689f90
Merge branch 'develop' into feat/shipping-refresh
fPolic May 3, 2024
a23ab08
fix: nav highlighting
fPolic May 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -69,7 +69,10 @@
"remove": "Remove",
"revoke": "Revoke",
"cancel": "Cancel",
"enable": "Enable",
"disable": "Disable",
"complete": "Complete",
"viewDetails": "View details",
"back": "Back",
"close": "Close",
"continue": "Continue",
Expand Down Expand Up @@ -154,6 +157,9 @@
"required": "New owner is required."
}
},
"sales_channels": {
"availableIn": "Available in <0>{{x}}</0> of <1>{{y}}</1> sales channels"
},
"products": {
"domain": "Products",
"createProductTitle": "Create Product",
Expand Down Expand Up @@ -184,7 +190,6 @@
"noMediaLabel": "The product has no associated media."
},
"discountableHint": "When unchecked discounts will not be applied to this product.",
"availableInSalesChannels": "Available in <0>{{x}}</0> of <1>{{y}}</1> sales channels",
"noSalesChannels": "Not available in any sales channels",
"variantCount_one": "{{count}} variant",
"variantCount_other": "{{count}} variants",
Expand Down Expand Up @@ -623,15 +628,23 @@
}
},
"shipping": {
"title": "Shipping & Delivery",
"domain": "Shipping & Delivery",
"title": "Location & Shipping",
"domain": "Location & Shipping",
"description": "Choose where you ship and how much you charge for shipping at checkout. Define shipping options specific for your locations.",
"createLocation": "Create location",
"createLocationDetailsHint": "Specify the details of the location.",
"deleteLocation": "Delete location",
"from": "Shipping from",
"add": "Add shipping",
"connectProvider": "Connect provider",
"addZone": "Add shipping zone",
"enablePickup": "Enable pickup",
"enableDelivery": "Enable delivery",
"deleteLocation": {
"label": "Delete Location",
"confirm": "Are you sure you want to delete {{name}} location",
"success": "{{name}} location successfully deleted"
},
"noRecords": {
"action": "Add Location",
"title": "No inventory locations",
Expand All @@ -645,18 +658,25 @@
},
"fulfillmentSet": {
"placeholder": "Not covered by any shipping zones.",
"salesChannels": "Connected Sales Channels",
"delete": "Delete shipping",
"disableWarning": "Are you sure that you wnat to disable \"{{name}}\"? This will delete all assocciated service zones and shipping options.",
"create": {
"title": "Add service zone for {{fulfillmentSet}}"
},
"toast": {
"disable": "\"{{name}}\" disabled"
},
"addZone": "Add service zone",
"pickup": {
"title": "Pickup in",
"enable": "Enable pickup"
"title": "Pick up",
"enable": "Enable pickup",
"offers": "Offers pick up in"
},
"delivery": {
"title": "Shipping to",
"enable": "Enable delivery"
"title": "Shipping",
"enable": "Enable delivery",
"offers": "Offers shippping to"
}
},
"serviceZone": {
Expand All @@ -666,12 +686,21 @@
"description": "A service zone is a geographical region that can be shipped to from a specific location. You can later on add any number of shipping options to this zone. ",
"zoneName": "Zone name"
},
"edit":{
"title": "Edit Service Zone"
},
"deleteWarning": "Are you sure you want to delete \"{{name}}\". This will also delete all assocciated shipping options.",
"toast": {
"delete": "Zone \"{{name}}\" deleted successfully."
},
"editPrices": "Edit prices",
"editOption": "Edit option",
"optionsLength_one": "shipping option",
"optionsLength_other": "shipping options",
"returnOptionsLength_one": "return option",
"returnOptionsLength_other": "return options",
"shippingOptionsPlaceholder": "Not covered by any shipping options.",
"addShippingOptions": "Add shipping options",
"addOption": "Add option",
"shippingOptions": "Shipping options",
"returnOptions": "Return options",
"areas": {
Expand All @@ -683,7 +712,7 @@
},
"shippingOptions": {
"create": {
"title": "Create shipping options for {{zone}}",
"title": "Create a shipping option for {{zone}}",
"subtitle": "General information",
"description": "To start selling, all you need is a name and a price",
"details": "Details",
Expand All @@ -696,7 +725,26 @@
"calculated": "Calculated",
"calculatedDescription": "Shipping option's price is calculated by the fulfillment provider.",
"profile": "Shipping profile"
},
"deleteWarning": "Are you sure you want to delete \"{{name}}\"?",
"toast": {
"delete": "Shipping option \"{{name}}\" deleted successfully."
},
"inStore": "Store",
"edit": {
"title": "Edit Shipping Option",
"provider": "Fulfillment provider"
}
},
"returnOptions" : {
"create": {
"title": "Create a return option for {{zone}}"
}
},
"salesChannels": {
"title": "Connected Sales Channels",
"placeholder": "No connected channels yet.",
"connectChannels": "Connect Channels"
}
},
"shippingProfile": {
Expand Down Expand Up @@ -1195,10 +1243,8 @@
},
"locations": {
"domain": "Locations",
"createLocation": "Create location",
"editLocation": "Edit location",
"addSalesChannels": "Add sales channels",
"detailsHint": "Specify the details of the location.",
"noLocationsFound": "No locations found",
"selectLocations": "Select locations that stock the item.",
"deleteLocationWarning": "You are about to delete the location {{name}}. This action cannot be undone.",
Expand Down Expand Up @@ -1388,6 +1434,7 @@
"scheduled": "Scheduled",
"expired": "Expired",
"active": "Active",
"enabled": "Enabled",
"disabled": "Disabled"
},
"fields": {
Expand Down
Expand Up @@ -144,11 +144,6 @@ const useCoreRoutes = (): Omit<NavItemProps, "pathname">[] => {
label: t("pricing.domain"),
to: "/pricing",
},
{
icon: <Envelope />,
label: t("shipping.domain"),
to: "/shipping",
},
]
}

Expand Down
Expand Up @@ -58,7 +58,8 @@ export const NavItem = ({
"text-ui-fg-subtle hover:text-ui-fg-base transition-fg hover:bg-ui-bg-subtle-hover flex items-center gap-x-2 rounded-md px-2 py-2.5 outline-none md:py-1.5",
{
"bg-ui-bg-base hover:bg-ui-bg-base-hover shadow-elevation-card-rest":
location.pathname.startsWith(to),
location.pathname === to ||
location.pathname.startsWith(to + "/"), // TODO: utilise `NavLink` and `end` prop instead of this manual check
"max-md:hidden": items && items.length > 0,
}
)}
Expand Down
Expand Up @@ -57,6 +57,10 @@ const useSettingRoutes = (): NavItemProps[] => {
label: t("shippingProfile.domain"),
to: "/settings/shipping-profiles",
},
{
label: t("shipping.domain"),
to: "/settings/shipping",
},
],
[t]
)
Expand Down
@@ -0,0 +1,24 @@
import { QueryKey, useQuery, UseQueryOptions } from "@tanstack/react-query"
import { client } from "../../lib/client"
import { queryKeysFactory } from "../../lib/query-key-factory"

const FULFILLMENT_PROVIDERS_QUERY_KEY = "f_providers" as const
export const fulfillmentProvidersQueryKeys = queryKeysFactory(
FULFILLMENT_PROVIDERS_QUERY_KEY
)

export const useFulfillmentProviders = (
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<any, Error, any, QueryKey>,
"queryFn" | "queryKey"
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => client.fulfillmentProviders.list(query),
queryKey: fulfillmentProvidersQueryKeys.list(query),
...options,
})

return { ...data, ...rest }
}
52 changes: 48 additions & 4 deletions packages/admin-next/dashboard/src/hooks/api/shipping-options.ts
@@ -1,14 +1,39 @@
import { useMutation, UseMutationOptions } from "@tanstack/react-query"
import {
QueryKey,
useMutation,
UseMutationOptions,
useQuery,
UseQueryOptions,
} from "@tanstack/react-query"

import {
ShippingOptionDeleteRes,
ShippingOptionRes,
} from "../../types/api-responses"
import { CreateShippingOptionReq } from "../../types/api-payloads"
import {
CreateShippingOptionReq,
UpdateShippingOptionReq,
} from "../../types/api-payloads"
import { stockLocationsQueryKeys } from "./stock-locations"
import { queryClient } from "../../lib/medusa"
import { client } from "../../lib/client"

export const useShippingOptions = (
query?: Record<string, any>,
options?: Omit<
UseQueryOptions<any, Error, any, QueryKey>,
"queryFn" | "queryKey"
>
) => {
const { data, ...rest } = useQuery({
queryFn: () => client.shippingOptions.list(query),
queryKey: stockLocationsQueryKeys.all,
...options,
})

return { ...data, ...rest }
}

export const useCreateShippingOptions = (
options?: UseMutationOptions<
ShippingOptionRes,
Expand All @@ -20,9 +45,28 @@ export const useCreateShippingOptions = (
mutationFn: (payload) => client.shippingOptions.create(payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: stockLocationsQueryKeys.lists(),
queryKey: stockLocationsQueryKeys.all,
})
options?.onSuccess?.(data, variables, context)
},
...options,
})
}

export const useUpdateShippingOptions = (
id: string,
options?: UseMutationOptions<
ShippingOptionRes,
Error,
UpdateShippingOptionReq
>
) => {
return useMutation({
mutationFn: (payload) => client.shippingOptions.update(id, payload),
onSuccess: (data, variables, context) => {
queryClient.invalidateQueries({
queryKey: stockLocationsQueryKeys.all,
})
options?.onSuccess?.(data, variables, context)
},
...options,
Expand All @@ -37,7 +81,7 @@ export const useDeleteShippingOption = (
mutationFn: () => client.shippingOptions.delete(optionId),
onSuccess: (data: any, variables: any, context: any) => {
queryClient.invalidateQueries({
queryKey: stockLocationsQueryKeys.lists(),
queryKey: stockLocationsQueryKeys.all,
})

options?.onSuccess?.(data, variables, context)
Expand Down