Skip to content

The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.

refactor(vendor): update user menu and search components to use seller data

Jakub Sieradzki2fea3bff94b1
diff --git a/packages/vendor/src/components/layout/user-menu/user-menu.tsx b/packages/vendor/src/components/layout/user-menu/user-menu.tsx
index 4b92b114d..f56e362cf 100644
--- a/packages/vendor/src/components/layout/user-menu/user-menu.tsx
+++ b/packages/vendor/src/components/layout/user-menu/user-menu.tsx
@@ -86,10 +86,9 @@ export const UserMenu = () => {
}
const UserBadge = () => {
- const { user, isPending, isError, error } = useMe()
+ const { seller, isPending, isError, error } = useMe()
- const name = [user?.first_name, user?.last_name].filter(Boolean).join(" ")
- const displayName = name || user?.email
+ const displayName = seller?.name || seller?.email
const fallback = displayName ? displayName[0].toUpperCase() : null
@@ -109,7 +108,7 @@ const UserBadge = () => {
return (
<div className="p-3">
<DropdownMenu.Trigger
- disabled={!user}
+ disabled={!seller}
className={clx(
"bg-ui-bg-subtle grid w-full cursor-pointer grid-cols-[24px_1fr_15px] items-center gap-2 rounded-md py-1 ps-0.5 pe-2 outline-none",
"hover:bg-ui-bg-subtle-hover",
@@ -295,18 +294,18 @@ const GlobalKeybindsModal = (props: {
}
const UserItem = () => {
- const { user, isPending, isError, error } = useMe()
+ const { seller, isPending, isError, error } = useMe()
- const loaded = !isPending && !!user
+ const loaded = !isPending && !!seller
if (!loaded) {
return <div></div>
}
- const name = [user.first_name, user.last_name].filter(Boolean).join(" ")
- const email = user.email
- const fallback = name ? name[0].toUpperCase() : email[0].toUpperCase()
- const avatar = user.avatar_url
+ const displayName = seller.name || seller.email
+ const email = seller.email
+ const fallback = displayName ? displayName[0].toUpperCase() : "S"
+ const avatar = seller.logo
if (isError) {
throw error
@@ -327,9 +326,9 @@ const UserItem = () => {
leading="compact"
className="overflow-hidden text-ellipsis whitespace-nowrap"
>
- {name || email}
+ {displayName}
</Text>
- {!!name && (
+ {!!email && displayName !== email && (
<Text
size="xsmall"
leading="compact"
diff --git a/packages/vendor/src/components/search/constants.ts b/packages/vendor/src/components/search/constants.ts
index 3b4397927..aa6a974b2 100644
--- a/packages/vendor/src/components/search/constants.ts
+++ b/packages/vendor/src/components/search/constants.ts
@@ -9,13 +9,9 @@ export const SEARCH_AREAS = [
"promotion",
"campaign",
"priceList",
- "region",
- "returnReason",
- "salesChannel",
"productType",
"productTag",
"location",
- "shippingProfile",
"command",
"navigation",
] as const
diff --git a/packages/vendor/src/components/search/use-search-results.tsx b/packages/vendor/src/components/search/use-search-results.tsx
index b3a204ece..1dab82e85 100644
--- a/packages/vendor/src/components/search/use-search-results.tsx
+++ b/packages/vendor/src/components/search/use-search-results.tsx
@@ -15,12 +15,8 @@ import {
useProductTags,
useProductTypes,
usePromotions,
- useRegions,
- useSalesChannels,
- useShippingProfiles,
useStockLocations,
} from "../../hooks/api"
-import { useReturnReasons } from "../../hooks/api/return-reasons"
import { Shortcut, ShortcutType } from "../../providers/keybind-provider"
import { useGlobalShortcuts } from "../../providers/keybind-provider/hooks"
import { DynamicSearchResult, SearchArea } from "./types"
@@ -207,42 +203,6 @@ const useDynamicSearchResults = (
}
)
- const regionResponse = useRegions(
- {
- q: debouncedSearch,
- limit,
- fields: "id,name",
- },
- {
- enabled: isAreaEnabled(currentArea, "region"),
- placeholderData: keepPreviousData,
- }
- )
-
- const returnReasonResponse = useReturnReasons(
- {
- q: debouncedSearch,
- limit,
- fields: "id,label,value",
- },
- {
- enabled: isAreaEnabled(currentArea, "returnReason"),
- placeholderData: keepPreviousData,
- }
- )
-
- const salesChannelResponse = useSalesChannels(
- {
- q: debouncedSearch,
- limit,
- fields: "id,name",
- },
- {
- enabled: isAreaEnabled(currentArea, "salesChannel"),
- placeholderData: keepPreviousData,
- }
- )
-
const productTypeResponse = useProductTypes(
{
q: debouncedSearch,
@@ -279,18 +239,6 @@ const useDynamicSearchResults = (
}
)
- const shippingProfileResponse = useShippingProfiles(
- {
- q: debouncedSearch,
- limit,
- fields: "id,name",
- },
- {
- enabled: isAreaEnabled(currentArea, "shippingProfile"),
- placeholderData: keepPreviousData,
- }
- )
-
const responseMap = useMemo(
() => ({
order: orderResponse,
@@ -302,13 +250,9 @@ const useDynamicSearchResults = (
promotion: promotionResponse,
campaign: campaignResponse,
priceList: priceListResponse,
- region: regionResponse,
- returnReason: returnReasonResponse,
- salesChannel: salesChannelResponse,
productType: productTypeResponse,
productTag: productTagResponse,
location: locationResponse,
- shippingProfile: shippingProfileResponse,
}),
[
orderResponse,
@@ -320,13 +264,9 @@ const useDynamicSearchResults = (
promotionResponse,
campaignResponse,
priceListResponse,
- regionResponse,
- returnReasonResponse,
- salesChannelResponse,
productTypeResponse,
productTagResponse,
locationResponse,
- shippingProfileResponse,
]
)
@@ -507,34 +447,6 @@ const transformMap: TransformMap = {
value: `priceList:${priceList.id}`,
}),
},
- region: {
- dataKey: "regions",
- transform: (region: HttpTypes.AdminRegion) => ({
- id: region.id,
- title: region.name,
- to: `/regions/${region.id}`,
- value: `region:${region.id}`,
- }),
- },
- returnReason: {
- dataKey: "return_reasons",
- transform: (returnReason: HttpTypes.AdminReturnReason) => ({
- id: returnReason.id,
- title: returnReason.label,
- subtitle: returnReason.value,
- to: `/return-reasons/${returnReason.id}/edit`,
- value: `returnReason:${returnReason.id}`,
- }),
- },
- salesChannel: {
- dataKey: "sales_channels",
- transform: (salesChannel: HttpTypes.AdminSalesChannel) => ({
- id: salesChannel.id,
- title: salesChannel.name,
- to: `/sales-channels/${salesChannel.id}`,
- value: `salesChannel:${salesChannel.id}`,
- }),
- },
productType: {
dataKey: "product_types",
transform: (productType: HttpTypes.AdminProductType) => ({
@@ -562,15 +474,6 @@ const transformMap: TransformMap = {
value: `location:${location.id}`,
}),
},
- shippingProfile: {
- dataKey: "shipping_profiles",
- transform: (shippingProfile: HttpTypes.AdminShippingProfile) => ({
- id: shippingProfile.id,
- title: shippingProfile.name,
- to: `/shipping-profiles/${shippingProfile.id}`,
- value: `shippingProfile:${shippingProfile.id}`,
- }),
- },
}
function transformDynamicSearchResults<T extends { count: number }>(
diff --git a/packages/vendor/src/providers/keybind-provider/hooks.tsx b/packages/vendor/src/providers/keybind-provider/hooks.tsx
index 3b3c8763d..97a172e3c 100644
--- a/packages/vendor/src/providers/keybind-provider/hooks.tsx
+++ b/packages/vendor/src/providers/keybind-provider/hooks.tsx
@@ -151,14 +151,6 @@ export const useGlobalShortcuts = () => {
type: "pageShortcut",
to: "/customers",
},
- {
- keys: {
- Mac: ["G", "G"],
- },
- label: t("app.keyboardShortcuts.navigation.goToCustomerGroups"),
- type: "pageShortcut",
- to: "/customer-groups",
- },
{
keys: {
Mac: ["G", "I"],
@@ -167,14 +159,6 @@ export const useGlobalShortcuts = () => {
type: "pageShortcut",
to: "/inventory",
},
- {
- keys: {
- Mac: ["G", "R"],
- },
- label: t("app.keyboardShortcuts.navigation.goToReservations"),
- type: "pageShortcut",
- to: "/reservations",
- },
{
keys: {
Mac: ["G", "L"],
@@ -224,30 +208,6 @@ export const useGlobalShortcuts = () => {
type: "settingShortcut",
to: "/settings/users",
},
- {
- keys: {
- Mac: ["G", ",", "R"],
- },
- label: t("app.keyboardShortcuts.settings.goToRegions"),
- type: "settingShortcut",
- to: "/settings/regions",
- },
- {
- keys: {
- Mac: ["G", ",", "T"],
- },
- label: t("app.keyboardShortcuts.settings.goToTaxRegions"),
- type: "settingShortcut",
- to: "/settings/tax-regions",
- },
- {
- keys: {
- Mac: ["G", ",", "A"],
- },
- label: t("app.keyboardShortcuts.settings.goToSalesChannels"),
- type: "settingShortcut",
- to: "/settings/sales-channels",
- },
{
keys: {
Mac: ["G", ",", "P"],
@@ -264,38 +224,6 @@ export const useGlobalShortcuts = () => {
type: "settingShortcut",
to: "/settings/locations",
},
- {
- keys: {
- Mac: ["G", ",", "M"],
- },
- label: t("app.keyboardShortcuts.settings.goToReturnReasons"),
- type: "settingShortcut",
- to: "/settings/return-reasons",
- },
- {
- keys: {
- Mac: ["G", ",", "J"],
- },
- label: t("app.keyboardShortcuts.settings.goToPublishableApiKeys"),
- type: "settingShortcut",
- to: "/settings/publishable-api-keys",
- },
- {
- keys: {
- Mac: ["G", ",", "K"],
- },
- label: t("app.keyboardShortcuts.settings.goToSecretApiKeys"),
- type: "settingShortcut",
- to: "/settings/secret-api-keys",
- },
- {
- keys: {
- Mac: ["G", ",", "W"],
- },
- label: t("app.keyboardShortcuts.settings.goToWorkflows"),
- type: "settingShortcut",
- to: "/settings/workflows",
- },
{
keys: {
Mac: ["G", ",", "M"],