fix(dashboard): Use ChipInput for option forms (#7603)
Resolves CORE-2069, CORE-2068
This commit is contained in:
@@ -19,6 +19,7 @@ type ChipInputProps = {
|
|||||||
allowDuplicates?: boolean
|
allowDuplicates?: boolean
|
||||||
showRemove?: boolean
|
showRemove?: boolean
|
||||||
variant?: "base" | "contrast"
|
variant?: "base" | "contrast"
|
||||||
|
placeholder?: string
|
||||||
className?: string
|
className?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,6 +34,7 @@ export const ChipInput = forwardRef<HTMLInputElement, ChipInputProps>(
|
|||||||
showRemove = true,
|
showRemove = true,
|
||||||
variant = "base",
|
variant = "base",
|
||||||
allowDuplicates = false,
|
allowDuplicates = false,
|
||||||
|
placeholder,
|
||||||
className,
|
className,
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
@@ -178,6 +180,8 @@ export const ChipInput = forwardRef<HTMLInputElement, ChipInputProps>(
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
name={name}
|
name={name}
|
||||||
ref={innerRef}
|
ref={innerRef}
|
||||||
|
placeholder={chips.length === 0 ? placeholder : undefined}
|
||||||
|
autoComplete="off"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -291,7 +291,9 @@
|
|||||||
"hint": "Options are used to define the color, size, etc. of the product",
|
"hint": "Options are used to define the color, size, etc. of the product",
|
||||||
"add": "Add option",
|
"add": "Add option",
|
||||||
"optionTitle": "Option title",
|
"optionTitle": "Option title",
|
||||||
"variations": "Variations (comma-separated)"
|
"optionTitlePlaceholder": "Color",
|
||||||
|
"variations": "Variations (comma-separated)",
|
||||||
|
"variantionsPlaceholder": "Red, Blue, Green"
|
||||||
},
|
},
|
||||||
"variants": {
|
"variants": {
|
||||||
"label": "Product variants",
|
"label": "Product variants",
|
||||||
|
|||||||
+13
-3
@@ -64,7 +64,7 @@ export const CreateProductOptionForm = ({
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
className="flex flex-1 flex-col overflow-hidden"
|
className="flex flex-1 flex-col overflow-hidden"
|
||||||
>
|
>
|
||||||
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-8 overflow-auto">
|
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-4 overflow-auto">
|
||||||
<Form.Field
|
<Form.Field
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="title"
|
name="title"
|
||||||
@@ -75,7 +75,12 @@ export const CreateProductOptionForm = ({
|
|||||||
{t("products.fields.options.optionTitle")}
|
{t("products.fields.options.optionTitle")}
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
<Form.Control>
|
<Form.Control>
|
||||||
<Input {...field} />
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder={t(
|
||||||
|
"products.fields.options.optionTitlePlaceholder"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
<Form.ErrorMessage />
|
<Form.ErrorMessage />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -92,7 +97,12 @@ export const CreateProductOptionForm = ({
|
|||||||
{t("products.fields.options.variations")}
|
{t("products.fields.options.variations")}
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
<Form.Control>
|
<Form.Control>
|
||||||
<ChipInput {...field} />
|
<ChipInput
|
||||||
|
{...field}
|
||||||
|
placeholder={t(
|
||||||
|
"products.fields.options.variantionsPlaceholder"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
<Form.ErrorMessage />
|
<Form.ErrorMessage />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|||||||
+7
-1
@@ -8,9 +8,9 @@ import {
|
|||||||
IconButton,
|
IconButton,
|
||||||
Input,
|
Input,
|
||||||
Label,
|
Label,
|
||||||
|
Switch,
|
||||||
Text,
|
Text,
|
||||||
clx,
|
clx,
|
||||||
Switch,
|
|
||||||
} from "@medusajs/ui"
|
} from "@medusajs/ui"
|
||||||
import {
|
import {
|
||||||
Controller,
|
Controller,
|
||||||
@@ -388,6 +388,9 @@ export const ProductCreateVariantsSection = ({
|
|||||||
{...form.register(
|
{...form.register(
|
||||||
`options.${index}.title` as const
|
`options.${index}.title` as const
|
||||||
)}
|
)}
|
||||||
|
placeholder={t(
|
||||||
|
"products.fields.options.optionTitlePlaceholder"
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
<div className="flex items-center px-2 py-1.5">
|
<div className="flex items-center px-2 py-1.5">
|
||||||
<Label
|
<Label
|
||||||
@@ -417,6 +420,9 @@ export const ProductCreateVariantsSection = ({
|
|||||||
{...field}
|
{...field}
|
||||||
variant="contrast"
|
variant="contrast"
|
||||||
onChange={handleValueChange}
|
onChange={handleValueChange}
|
||||||
|
placeholder={t(
|
||||||
|
"products.fields.options.variantionsPlaceholder"
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
|
|||||||
+16
-11
@@ -4,7 +4,9 @@ import { Button, Input } from "@medusajs/ui"
|
|||||||
import { useForm } from "react-hook-form"
|
import { useForm } from "react-hook-form"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import { z } from "zod"
|
import { z } from "zod"
|
||||||
|
|
||||||
import { Form } from "../../../../../components/common/form"
|
import { Form } from "../../../../../components/common/form"
|
||||||
|
import { ChipInput } from "../../../../../components/inputs/chip-input"
|
||||||
import {
|
import {
|
||||||
RouteDrawer,
|
RouteDrawer,
|
||||||
useRouteModal,
|
useRouteModal,
|
||||||
@@ -34,7 +36,7 @@ export const CreateProductOptionForm = ({
|
|||||||
resolver: zodResolver(CreateProductOptionSchema),
|
resolver: zodResolver(CreateProductOptionSchema),
|
||||||
})
|
})
|
||||||
|
|
||||||
const { mutateAsync, isLoading } = useUpdateProductOption(
|
const { mutateAsync, isPending } = useUpdateProductOption(
|
||||||
option.product_id,
|
option.product_id,
|
||||||
option.id
|
option.id
|
||||||
)
|
)
|
||||||
@@ -59,7 +61,7 @@ export const CreateProductOptionForm = ({
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
className="flex flex-1 flex-col overflow-hidden"
|
className="flex flex-1 flex-col overflow-hidden"
|
||||||
>
|
>
|
||||||
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-8 overflow-auto">
|
<RouteDrawer.Body className="flex flex-1 flex-col gap-y-4 overflow-auto">
|
||||||
<Form.Field
|
<Form.Field
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="title"
|
name="title"
|
||||||
@@ -70,7 +72,12 @@ export const CreateProductOptionForm = ({
|
|||||||
{t("products.fields.options.optionTitle")}
|
{t("products.fields.options.optionTitle")}
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
<Form.Control>
|
<Form.Control>
|
||||||
<Input {...field} />
|
<Input
|
||||||
|
{...field}
|
||||||
|
placeholder={t(
|
||||||
|
"products.fields.options.optionTitlePlaceholder"
|
||||||
|
)}
|
||||||
|
/>
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
<Form.ErrorMessage />
|
<Form.ErrorMessage />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
@@ -80,20 +87,18 @@ export const CreateProductOptionForm = ({
|
|||||||
<Form.Field
|
<Form.Field
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="values"
|
name="values"
|
||||||
render={({ field: { value, onChange, ...field } }) => {
|
render={({ field: { ...field } }) => {
|
||||||
return (
|
return (
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
<Form.Label>
|
<Form.Label>
|
||||||
{t("products.fields.options.variations")}
|
{t("products.fields.options.variations")}
|
||||||
</Form.Label>
|
</Form.Label>
|
||||||
<Form.Control>
|
<Form.Control>
|
||||||
<Input
|
<ChipInput
|
||||||
{...field}
|
{...field}
|
||||||
value={(value ?? []).join(",")}
|
placeholder={t(
|
||||||
onChange={(e) => {
|
"products.fields.options.variantionsPlaceholder"
|
||||||
const val = e.target.value
|
)}
|
||||||
onChange(val.split(",").map((v) => v.trim()))
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</Form.Control>
|
</Form.Control>
|
||||||
<Form.ErrorMessage />
|
<Form.ErrorMessage />
|
||||||
@@ -109,7 +114,7 @@ export const CreateProductOptionForm = ({
|
|||||||
{t("actions.cancel")}
|
{t("actions.cancel")}
|
||||||
</Button>
|
</Button>
|
||||||
</RouteDrawer.Close>
|
</RouteDrawer.Close>
|
||||||
<Button type="submit" size="small" isLoading={isLoading}>
|
<Button type="submit" size="small" isLoading={isPending}>
|
||||||
{t("actions.save")}
|
{t("actions.save")}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user