Skip to content

Commit

Permalink
feat: product details sidebar, refactor sidebar link
Browse files Browse the repository at this point in the history
  • Loading branch information
fPolic committed Jan 9, 2025
1 parent 22a4633 commit 53f60aa
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./sidebar-link"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ReactNode } from "react"
import { Link } from "react-router-dom"

import { IconAvatar } from "../icon-avatar"
import { Text } from "@medusajs/ui"
import { TriangleRightMini } from "@medusajs/icons"

export interface SidebarLinkProps {
to: string
labelKey: string
descriptionKey: string
icon: ReactNode
}

export const SidebarLink = ({
to,
labelKey,
descriptionKey,
icon,
}: SidebarLinkProps) => {
return (
<Link to={to} className="group outline-none">
<div className="flex flex-col gap-2 px-2 pb-2">
<div className="shadow-elevation-card-rest bg-ui-bg-component transition-fg hover:bg-ui-bg-component-hover active:bg-ui-bg-component-pressed group-focus-visible:shadow-borders-interactive-with-active rounded-md px-4 py-2">
<div className="flex items-center gap-4">
<IconAvatar>{icon}</IconAvatar>
<div className="flex flex-1 flex-col">
<Text size="small" leading="compact" weight="plus">
{labelKey}
</Text>
<Text
size="small"
leading="compact"
className="text-ui-fg-subtle"
>
{descriptionKey}
</Text>
</div>
<div className="flex size-7 items-center justify-center">
<TriangleRightMini className="text-ui-fg-muted" />
</div>
</div>
</div>
</div>
</Link>
)
}
13 changes: 13 additions & 0 deletions packages/admin/dashboard/src/i18n/translations/$schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2666,6 +2666,18 @@
],
"additionalProperties": false
},
"shippingProfile": {
"type": "object",
"properties": {
"header": {
"type": "string"
}
},
"required": [
"header"
],
"additionalProperties": false
},
"toasts": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2738,6 +2750,7 @@
"variant",
"options",
"organization",
"shippingProfile",
"toasts"
],
"additionalProperties": false
Expand Down
3 changes: 3 additions & 0 deletions packages/admin/dashboard/src/i18n/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,9 @@
}
}
},
"shippingProfile": {
"header": "Shipping configuration"
},
"toasts": {
"delete": {
"success": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { IconAvatar } from "../../../components/common/icon-avatar"
import { TwoColumnPage } from "../../../components/layout/pages"
import { useDashboardExtension } from "../../../extensions"
import { LocationListHeader } from "./components/location-list-header"
import { SidebarLink } from "../../../components/common/sidebar-link/sidebar-link"

export function LocationList() {
const initialData = useLoaderData() as Awaited<
Expand Down Expand Up @@ -61,47 +62,6 @@ export function LocationList() {
)
}

interface SidebarLinkProps {
to: string
labelKey: string
descriptionKey: string
icon: ReactNode
}

const SidebarLink = ({
to,
labelKey,
descriptionKey,
icon,
}: SidebarLinkProps) => {
return (
<Link to={to} className="group outline-none">
<div className="flex flex-col gap-2 px-2 pb-2">
<div className="shadow-elevation-card-rest bg-ui-bg-component transition-fg hover:bg-ui-bg-component-hover active:bg-ui-bg-component-pressed group-focus-visible:shadow-borders-interactive-with-active rounded-md px-4 py-2">
<div className="flex items-center gap-4">
<IconAvatar>{icon}</IconAvatar>
<div className="flex flex-1 flex-col">
<Text size="small" leading="compact" weight="plus">
{labelKey}
</Text>
<Text
size="small"
leading="compact"
className="text-ui-fg-subtle"
>
{descriptionKey}
</Text>
</div>
<div className="flex size-7 items-center justify-center">
<TriangleRightMini className="text-ui-fg-muted" />
</div>
</div>
</div>
</div>
</Link>
)
}

const LinksSection = () => {
const { t } = useTranslation()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export const ProductOrganizationSection = ({
const { t } = useTranslation()
const { getDisplays } = useDashboardExtension()

console.log("product", product)

return (
<Container className="divide-y p-0">
<div className="flex items-center justify-between px-6 py-4">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./product-shipping-profile-section"
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { PencilSquare, ShoppingBag } from "@medusajs/icons"
import { HttpTypes } from "@medusajs/types"
import { Container, Heading } from "@medusajs/ui"
import { useTranslation } from "react-i18next"

import { SidebarLink } from "../../../../../components/common/sidebar-link/sidebar-link"
import { ActionMenu } from "../../../../../components/common/action-menu"

type ProductShippingProfileSectionProps = {
product: HttpTypes.AdminProduct & {
shipping_profile: HttpTypes.AdminShippingProfile
}
}

export const ProductShippingProfileSection = ({
product,
}: ProductShippingProfileSectionProps) => {
const { t } = useTranslation()

const shippingProfile = product.shipping_profile

if (!shippingProfile) {
return null
}

return (
<Container className="p-0">
<div className="flex items-center justify-between px-6 py-4">
<Heading level="h2">{t("products.shippingProfile.header")}</Heading>
<ActionMenu
groups={[
{
actions: [
{
label: t("actions.edit"),
to: "shipping-profile",
icon: <PencilSquare />,
},
],
},
]}
/>
</div>

<SidebarLink
to={`/settings/locations/shipping-profiles/${shippingProfile.id}`}
labelKey={shippingProfile.name}
descriptionKey={shippingProfile.type}
icon={<ShoppingBag />}
/>
</Container>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { PRODUCT_DETAIL_FIELDS } from "./constants"
import { productLoader } from "./loader"

import { useDashboardExtension } from "../../../extensions"
import { ProductShippingProfileSection } from "./components/product-shipping-profile-section"

export const ProductDetail = () => {
const initialData = useLoaderData() as Awaited<
Expand Down Expand Up @@ -71,6 +72,7 @@ export const ProductDetail = () => {
</TwoColumnPage.Main>
<TwoColumnPage.Sidebar>
<ProductSalesChannelSection product={product} />
<ProductShippingProfileSection product={product} />
<ProductOrganizationSection product={product} />
<ProductAttributeSection product={product} />
</TwoColumnPage.Sidebar>
Expand Down

0 comments on commit 53f60aa

Please sign in to comment.