fix: ability to update price list status on admin (#7699)
This commit is contained in:
@@ -1257,7 +1257,11 @@
|
||||
"pricesHeader": "Prices"
|
||||
},
|
||||
"fields": {
|
||||
"statusTooltip": "Status can also be expired or scheduled depending on the start and end date.",
|
||||
"typeHint": "Choose the type of price you want to create.",
|
||||
"statusHint": "Choose if price should be published to users",
|
||||
"draftTypeHint": "Prices will not be visible to users in a draft state",
|
||||
"activeTypeHint": "Prices are visibile to users in an active state",
|
||||
"saleTypeHint": "Sale prices are temporary price changes for products.",
|
||||
"overrideTypeHint": "Overrides are usually used to create customer-specific prices.",
|
||||
"startDateLabel": "Price list has a start date?",
|
||||
|
||||
@@ -6,6 +6,11 @@ export enum PriceListStatus {
|
||||
DRAFT = "draft",
|
||||
}
|
||||
|
||||
export enum PriceListDateStatus {
|
||||
SCHEDULED = "scheduled",
|
||||
EXPIRED = "expired",
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-implementation of enum from `@medusajs/medusa` as it cannot be imported
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PriceListDTO, HttpTypes } from "@medusajs/types"
|
||||
import { HttpTypes, PriceListDTO } from "@medusajs/types"
|
||||
import { TFunction } from "i18next"
|
||||
import { PriceListStatus } from "./constants"
|
||||
import { PriceListDateStatus, PriceListStatus } from "./constants"
|
||||
|
||||
const getValues = (priceList: PriceListDTO) => {
|
||||
const startsAt = priceList.starts_at
|
||||
@@ -25,25 +25,30 @@ export const getPriceListStatus = (
|
||||
|
||||
let text = t("pricing.status.active")
|
||||
let color: "red" | "grey" | "orange" | "green" = "green"
|
||||
|
||||
if (isScheduled) {
|
||||
color = "orange"
|
||||
text = t("pricing.status.scheduled")
|
||||
}
|
||||
let status: string = PriceListStatus.ACTIVE
|
||||
|
||||
if (isDraft) {
|
||||
color = "grey"
|
||||
text = t("pricing.status.draft")
|
||||
status = PriceListStatus.DRAFT
|
||||
}
|
||||
|
||||
if (isExpired) {
|
||||
color = "red"
|
||||
text = t("pricing.status.expired")
|
||||
status = PriceListDateStatus.EXPIRED
|
||||
}
|
||||
|
||||
if (isScheduled) {
|
||||
color = "orange"
|
||||
text = t("pricing.status.scheduled")
|
||||
status = PriceListDateStatus.SCHEDULED
|
||||
}
|
||||
|
||||
return {
|
||||
color,
|
||||
text,
|
||||
status,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,13 +10,14 @@ import {
|
||||
useRouteModal,
|
||||
} from "../../../../../components/route-modal"
|
||||
import { useUpdatePriceList } from "../../../../../hooks/api/price-lists"
|
||||
import { PriceListType } from "../../../common/constants"
|
||||
import { PriceListStatus, PriceListType } from "../../../common/constants"
|
||||
|
||||
type EditPriceListFormProps = {
|
||||
priceList: PriceListDTO
|
||||
}
|
||||
|
||||
const EditPriceListFormSchema = z.object({
|
||||
status: z.nativeEnum(PriceListStatus),
|
||||
type: z.nativeEnum(PriceListType),
|
||||
title: z.string().min(1),
|
||||
description: z.string().min(1),
|
||||
@@ -28,9 +29,10 @@ export const EditPriceListForm = ({ priceList }: EditPriceListFormProps) => {
|
||||
|
||||
const form = useForm<z.infer<typeof EditPriceListFormSchema>>({
|
||||
defaultValues: {
|
||||
type: priceList.type,
|
||||
type: priceList.type as PriceListType,
|
||||
title: priceList.title,
|
||||
description: priceList.description,
|
||||
status: priceList.status as PriceListStatus,
|
||||
},
|
||||
resolver: zodResolver(EditPriceListFormSchema),
|
||||
})
|
||||
@@ -52,6 +54,39 @@ export const EditPriceListForm = ({ priceList }: EditPriceListFormProps) => {
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-8 overflow-auto">
|
||||
<Form.Field
|
||||
control={form.control}
|
||||
name="status"
|
||||
render={({ field: { onChange, ...field } }) => {
|
||||
return (
|
||||
<Form.Item>
|
||||
<div>
|
||||
<Form.Label tooltip={t("pricing.fields.statusTooltip")}>
|
||||
{t("fields.status")}
|
||||
</Form.Label>
|
||||
<Form.Hint>{t("pricing.fields.statusHint")}</Form.Hint>
|
||||
</div>
|
||||
|
||||
<Form.Control>
|
||||
<RadioGroup {...field} onValueChange={onChange}>
|
||||
<RadioGroup.ChoiceBox
|
||||
value={PriceListStatus.DRAFT}
|
||||
label={t("pricing.status.draft")}
|
||||
description={t("pricing.fields.draftTypeHint")}
|
||||
/>
|
||||
|
||||
<RadioGroup.ChoiceBox
|
||||
value={PriceListStatus.ACTIVE}
|
||||
label={t("pricing.status.active")}
|
||||
description={t("pricing.fields.activeTypeHint")}
|
||||
/>
|
||||
</RadioGroup>
|
||||
</Form.Control>
|
||||
</Form.Item>
|
||||
)
|
||||
}}
|
||||
/>
|
||||
|
||||
<Form.Field
|
||||
control={form.control}
|
||||
name="type"
|
||||
|
||||
@@ -89,7 +89,7 @@ export type CreateShippingProfileReq = CreateShippingProfileDTO
|
||||
|
||||
// Price Lists
|
||||
export type CreatePriceListReq = CreatePriceListDTO
|
||||
export type UpdatePriceListReq = UpdatePriceListDTO
|
||||
export type UpdatePriceListReq = Omit<UpdatePriceListDTO, "id">
|
||||
export type AddPriceListPricesReq = {
|
||||
prices: {
|
||||
currency_code: string
|
||||
|
||||
@@ -38,6 +38,10 @@ export interface PriceListDTO {
|
||||
* The price list's title.
|
||||
*/
|
||||
title?: string
|
||||
/**
|
||||
* The price list's description.
|
||||
*/
|
||||
description?: string
|
||||
/**
|
||||
* The price list is enabled starting from this date.
|
||||
*/
|
||||
@@ -46,6 +50,10 @@ export interface PriceListDTO {
|
||||
* The price list's status.
|
||||
*/
|
||||
status?: PriceListStatus
|
||||
/**
|
||||
* The price list's type.
|
||||
*/
|
||||
type?: PriceListType
|
||||
/**
|
||||
* The price list expires after this date.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user