fix: ability to update price list status on admin (#7699)
This commit is contained in:
@@ -1257,7 +1257,11 @@
|
|||||||
"pricesHeader": "Prices"
|
"pricesHeader": "Prices"
|
||||||
},
|
},
|
||||||
"fields": {
|
"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.",
|
"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.",
|
"saleTypeHint": "Sale prices are temporary price changes for products.",
|
||||||
"overrideTypeHint": "Overrides are usually used to create customer-specific prices.",
|
"overrideTypeHint": "Overrides are usually used to create customer-specific prices.",
|
||||||
"startDateLabel": "Price list has a start date?",
|
"startDateLabel": "Price list has a start date?",
|
||||||
|
|||||||
@@ -6,6 +6,11 @@ export enum PriceListStatus {
|
|||||||
DRAFT = "draft",
|
DRAFT = "draft",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum PriceListDateStatus {
|
||||||
|
SCHEDULED = "scheduled",
|
||||||
|
EXPIRED = "expired",
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Re-implementation of enum from `@medusajs/medusa` as it cannot be imported
|
* 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 { TFunction } from "i18next"
|
||||||
import { PriceListStatus } from "./constants"
|
import { PriceListDateStatus, PriceListStatus } from "./constants"
|
||||||
|
|
||||||
const getValues = (priceList: PriceListDTO) => {
|
const getValues = (priceList: PriceListDTO) => {
|
||||||
const startsAt = priceList.starts_at
|
const startsAt = priceList.starts_at
|
||||||
@@ -25,25 +25,30 @@ export const getPriceListStatus = (
|
|||||||
|
|
||||||
let text = t("pricing.status.active")
|
let text = t("pricing.status.active")
|
||||||
let color: "red" | "grey" | "orange" | "green" = "green"
|
let color: "red" | "grey" | "orange" | "green" = "green"
|
||||||
|
let status: string = PriceListStatus.ACTIVE
|
||||||
if (isScheduled) {
|
|
||||||
color = "orange"
|
|
||||||
text = t("pricing.status.scheduled")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDraft) {
|
if (isDraft) {
|
||||||
color = "grey"
|
color = "grey"
|
||||||
text = t("pricing.status.draft")
|
text = t("pricing.status.draft")
|
||||||
|
status = PriceListStatus.DRAFT
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isExpired) {
|
if (isExpired) {
|
||||||
color = "red"
|
color = "red"
|
||||||
text = t("pricing.status.expired")
|
text = t("pricing.status.expired")
|
||||||
|
status = PriceListDateStatus.EXPIRED
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isScheduled) {
|
||||||
|
color = "orange"
|
||||||
|
text = t("pricing.status.scheduled")
|
||||||
|
status = PriceListDateStatus.SCHEDULED
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
color,
|
color,
|
||||||
text,
|
text,
|
||||||
|
status,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+37
-2
@@ -10,13 +10,14 @@ import {
|
|||||||
useRouteModal,
|
useRouteModal,
|
||||||
} from "../../../../../components/route-modal"
|
} from "../../../../../components/route-modal"
|
||||||
import { useUpdatePriceList } from "../../../../../hooks/api/price-lists"
|
import { useUpdatePriceList } from "../../../../../hooks/api/price-lists"
|
||||||
import { PriceListType } from "../../../common/constants"
|
import { PriceListStatus, PriceListType } from "../../../common/constants"
|
||||||
|
|
||||||
type EditPriceListFormProps = {
|
type EditPriceListFormProps = {
|
||||||
priceList: PriceListDTO
|
priceList: PriceListDTO
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditPriceListFormSchema = z.object({
|
const EditPriceListFormSchema = z.object({
|
||||||
|
status: z.nativeEnum(PriceListStatus),
|
||||||
type: z.nativeEnum(PriceListType),
|
type: z.nativeEnum(PriceListType),
|
||||||
title: z.string().min(1),
|
title: z.string().min(1),
|
||||||
description: 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>>({
|
const form = useForm<z.infer<typeof EditPriceListFormSchema>>({
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
type: priceList.type,
|
type: priceList.type as PriceListType,
|
||||||
title: priceList.title,
|
title: priceList.title,
|
||||||
description: priceList.description,
|
description: priceList.description,
|
||||||
|
status: priceList.status as PriceListStatus,
|
||||||
},
|
},
|
||||||
resolver: zodResolver(EditPriceListFormSchema),
|
resolver: zodResolver(EditPriceListFormSchema),
|
||||||
})
|
})
|
||||||
@@ -52,6 +54,39 @@ export const EditPriceListForm = ({ priceList }: EditPriceListFormProps) => {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
>
|
>
|
||||||
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-8 overflow-auto">
|
<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
|
<Form.Field
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="type"
|
name="type"
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export type CreateShippingProfileReq = CreateShippingProfileDTO
|
|||||||
|
|
||||||
// Price Lists
|
// Price Lists
|
||||||
export type CreatePriceListReq = CreatePriceListDTO
|
export type CreatePriceListReq = CreatePriceListDTO
|
||||||
export type UpdatePriceListReq = UpdatePriceListDTO
|
export type UpdatePriceListReq = Omit<UpdatePriceListDTO, "id">
|
||||||
export type AddPriceListPricesReq = {
|
export type AddPriceListPricesReq = {
|
||||||
prices: {
|
prices: {
|
||||||
currency_code: string
|
currency_code: string
|
||||||
|
|||||||
@@ -38,6 +38,10 @@ export interface PriceListDTO {
|
|||||||
* The price list's title.
|
* The price list's title.
|
||||||
*/
|
*/
|
||||||
title?: string
|
title?: string
|
||||||
|
/**
|
||||||
|
* The price list's description.
|
||||||
|
*/
|
||||||
|
description?: string
|
||||||
/**
|
/**
|
||||||
* The price list is enabled starting from this date.
|
* The price list is enabled starting from this date.
|
||||||
*/
|
*/
|
||||||
@@ -46,6 +50,10 @@ export interface PriceListDTO {
|
|||||||
* The price list's status.
|
* The price list's status.
|
||||||
*/
|
*/
|
||||||
status?: PriceListStatus
|
status?: PriceListStatus
|
||||||
|
/**
|
||||||
|
* The price list's type.
|
||||||
|
*/
|
||||||
|
type?: PriceListType
|
||||||
/**
|
/**
|
||||||
* The price list expires after this date.
|
* The price list expires after this date.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user