-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(medusa,dahsboard): Initial work on pricing domain (#6633)
**What** - Initial work on pricing domain. - List page - Details page - Partial edit form - Fixes admin/price-lists/:id/products endpoint to allow filtering products by multiple ids. **Note** Pushing this now as the current design need a bit of tweaking so we display all relevant data to users. Future PR will include completed Edit moda, Create modal, Edit prices modal and Add prices modal.
- Loading branch information
1 parent
b8bedb8
commit e124762
Showing
39 changed files
with
1,192 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@medusajs/client-types": patch | ||
"@medusajs/medusa": patch | ||
--- | ||
|
||
fix(medusa): Allows to filter price list products by multiple ids. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ export const useProductTableQuery = ({ | |
"tags", | ||
"type_id", | ||
"status", | ||
"id", | ||
], | ||
prefix | ||
) | ||
|
20 changes: 0 additions & 20 deletions
20
packages/admin-next/dashboard/src/hooks/use-form-prompt.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/admin-next/dashboard/src/routes/pricing/common/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Re-implementation of enum from `@medusajs/medusa` as it cannot be imported | ||
*/ | ||
export enum PriceListStatus { | ||
ACTIVE = "active", | ||
DRAFT = "draft", | ||
} | ||
|
||
/** | ||
* Re-implementation of enum from `@medusajs/medusa` as it cannot be imported | ||
*/ | ||
export enum PriceListType { | ||
SALE = "sale", | ||
OVERRIDE = "override", | ||
} |
48 changes: 48 additions & 0 deletions
48
packages/admin-next/dashboard/src/routes/pricing/common/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { PriceList } from "@medusajs/medusa" | ||
import { TFunction } from "i18next" | ||
import { PriceListStatus } from "./constants" | ||
|
||
const getValues = (priceList: PriceList) => { | ||
const startsAt = priceList.starts_at | ||
const endsAt = priceList.ends_at | ||
|
||
const isExpired = endsAt ? new Date(endsAt) < new Date() : false | ||
const isScheduled = startsAt ? new Date(startsAt) > new Date() : false | ||
const isDraft = priceList.status === PriceListStatus.DRAFT | ||
|
||
return { | ||
isExpired, | ||
isScheduled, | ||
isDraft, | ||
} | ||
} | ||
|
||
export const getPriceListStatus = ( | ||
t: TFunction<"translation">, | ||
priceList: PriceList | ||
) => { | ||
const { isExpired, isScheduled, isDraft } = getValues(priceList) | ||
|
||
let text = t("pricing.status.active") | ||
let color: "red" | "grey" | "orange" | "green" = "green" | ||
|
||
if (isScheduled) { | ||
color = "orange" | ||
text = t("pricing.status.scheduled") | ||
} | ||
|
||
if (isDraft) { | ||
color = "grey" | ||
text = t("pricing.status.draft") | ||
} | ||
|
||
if (isExpired) { | ||
color = "red" | ||
text = t("pricing.status.expired") | ||
} | ||
|
||
return { | ||
color, | ||
text, | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
packages/admin-next/dashboard/src/routes/pricing/details/details.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/admin-next/dashboard/src/routes/pricing/details/index.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/admin-next/dashboard/src/routes/pricing/list/list.tsx
This file was deleted.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
...t/dashboard/src/routes/pricing/pricing-detail/components/pricing-general-section/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./pricing-general-section" |
148 changes: 148 additions & 0 deletions
148
...tes/pricing/pricing-detail/components/pricing-general-section/pricing-general-section.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import { PencilSquare, Trash } from "@medusajs/icons" | ||
import { PriceList } from "@medusajs/medusa" | ||
import { | ||
Container, | ||
Heading, | ||
StatusBadge, | ||
Text, | ||
Tooltip, | ||
usePrompt, | ||
} from "@medusajs/ui" | ||
import { useAdminDeletePriceList } from "medusa-react" | ||
import { useTranslation } from "react-i18next" | ||
import { useNavigate } from "react-router-dom" | ||
import { ActionMenu } from "../../../../../components/common/action-menu" | ||
import { getPriceListStatus } from "../../../common/utils" | ||
|
||
type PricingGeneralSectionProps = { | ||
priceList: PriceList | ||
} | ||
|
||
export const PricingGeneralSection = ({ | ||
priceList, | ||
}: PricingGeneralSectionProps) => { | ||
const { t } = useTranslation() | ||
const navigate = useNavigate() | ||
const prompt = usePrompt() | ||
|
||
const { mutateAsync } = useAdminDeletePriceList(priceList.id) | ||
|
||
const overrideCount = priceList.prices?.length || 0 | ||
const firstCustomerGroups = priceList.customer_groups?.slice(0, 3) | ||
const remainingCustomerGroups = priceList.customer_groups?.slice(3) | ||
|
||
const { color, text } = getPriceListStatus(t, priceList) | ||
|
||
const handleDelete = async () => { | ||
const res = await prompt({ | ||
title: t("general.areYouSure"), | ||
description: t("pricing.deletePriceListWarning", { | ||
name: priceList.name, | ||
}), | ||
confirmText: t("actions.delete"), | ||
cancelText: t("actions.cancel"), | ||
}) | ||
|
||
if (!res) { | ||
return | ||
} | ||
|
||
await mutateAsync(undefined, { | ||
onSuccess: () => { | ||
navigate("..", { replace: true }) | ||
}, | ||
}) | ||
} | ||
|
||
const type = | ||
priceList.type === "sale" | ||
? t("pricing.type.sale") | ||
: t("pricing.type.override") | ||
|
||
return ( | ||
<Container className="divide-y p-0"> | ||
<div className="flex items-center justify-between px-6 py-4"> | ||
<Heading>{priceList.name}</Heading> | ||
<div className="flex items-center gap-x-4"> | ||
<StatusBadge color={color}>{text}</StatusBadge> | ||
<ActionMenu | ||
groups={[ | ||
{ | ||
actions: [ | ||
{ | ||
label: t("actions.edit"), | ||
to: "edit", | ||
icon: <PencilSquare />, | ||
}, | ||
], | ||
}, | ||
{ | ||
actions: [ | ||
{ | ||
label: t("actions.delete"), | ||
onClick: handleDelete, | ||
icon: <Trash />, | ||
}, | ||
], | ||
}, | ||
]} | ||
/> | ||
</div> | ||
</div> | ||
<div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4"> | ||
<Text leading="compact" size="small" weight="plus"> | ||
{t("fields.type")} | ||
</Text> | ||
<Text size="small" className="text-pretty"> | ||
{type} | ||
</Text> | ||
</div> | ||
<div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4"> | ||
<Text leading="compact" size="small" weight="plus"> | ||
{t("fields.description")} | ||
</Text> | ||
<Text size="small" className="text-pretty"> | ||
{priceList.description} | ||
</Text> | ||
</div> | ||
<div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4"> | ||
<Text leading="compact" size="small" weight="plus"> | ||
{t("pricing.settings.customerGroupsLabel")} | ||
</Text> | ||
<Text size="small" className="text-pretty"> | ||
<span> | ||
{firstCustomerGroups.length > 0 | ||
? firstCustomerGroups.join(", ") | ||
: "-"} | ||
</span> | ||
{remainingCustomerGroups.length > 0 && ( | ||
<Tooltip | ||
content={ | ||
<ul> | ||
{remainingCustomerGroups.map((cg) => ( | ||
<li key={cg.id}>{cg.name}</li> | ||
))} | ||
</ul> | ||
} | ||
> | ||
<span className="text-ui-fg-muted"> | ||
{" "} | ||
{t("general.plusCountMore", { | ||
count: remainingCustomerGroups.length, | ||
})} | ||
</span> | ||
</Tooltip> | ||
)} | ||
</Text> | ||
</div> | ||
<div className="text-ui-fg-subtle grid grid-cols-2 items-center px-6 py-4"> | ||
<Text leading="compact" size="small" weight="plus"> | ||
{t("pricing.settings.priceOverridesLabel")} | ||
</Text> | ||
<Text size="small" className="text-pretty"> | ||
{overrideCount || "-"} | ||
</Text> | ||
</div> | ||
</Container> | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
...t/dashboard/src/routes/pricing/pricing-detail/components/pricing-product-section/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./pricing-product-section" |
Oops, something went wrong.