The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
fix(admin): align offer condition forms with dashboard form conventions (#1661)
Viktor Holike63729233941
diff --git a/packages/admin/src/i18n/translations/$schema.json b/packages/admin/src/i18n/translations/$schema.jsonindex 1c3f8146c..981f80e00 100644--- a/packages/admin/src/i18n/translations/$schema.json+++ b/packages/admin/src/i18n/translations/$schema.json@@ -4641,9 +4641,6 @@"gotIt": {"type": "string"},- "storeLocationWarning": {- "type": "string"- },"errors": {"type": "object","properties": {@@ -13494,9 +13491,6 @@"subtitle": {"type": "string"},- "enabledHint": {- "type": "string"- },"create": {"type": "object","properties": {@@ -13559,11 +13553,15 @@"label": {"type": "object","properties": {+ "label": {+ "type": "string"+ },"placeholder": {"type": "string"}},"required": [+ "label","placeholder"],"additionalProperties": false@@ -13571,20 +13569,40 @@"code": {"type": "object","properties": {+ "label": {+ "type": "string"+ },"placeholder": {"type": "string"},- "hint": {+ "tooltip": {"type": "string"}},"required": [+ "label","placeholder",- "hint"+ "tooltip"],"additionalProperties": false},"rank": {+ "type": "object",+ "properties": {+ "label": {+ "type": "string"+ },+ "tooltip": {+ "type": "string"+ }+ },+ "required": [+ "label",+ "tooltip"+ ],+ "additionalProperties": false+ },+ "isActive": {"type": "object","properties": {"label": {@@ -13604,7 +13622,8 @@"required": ["label","code",- "rank"+ "rank",+ "isActive"],"additionalProperties": false}@@ -13612,7 +13631,6 @@"required": ["domain","subtitle",- "enabledHint","create","edit","delete",diff --git a/packages/admin/src/i18n/translations/en.json b/packages/admin/src/i18n/translations/en.jsonindex 9b7eb795b..c2511b946 100644--- a/packages/admin/src/i18n/translations/en.json+++ b/packages/admin/src/i18n/translations/en.json@@ -3570,16 +3570,15 @@},"offerConditions": {"domain": "Offer Conditions",- "subtitle": "Manage the conditions sellers can list their offers under.",- "enabledHint": "Sellers can only list new offers under enabled conditions. Existing offers keep their condition.",+ "subtitle": "Manage the conditions sellers can list offers under.","create": {"header": "Create Offer Condition",- "subtitle": "Define a condition sellers can list their offers under, e.g. new or refurbished.",+ "subtitle": "Specify the conditions sellers can list their offers under.","successToast": "Offer condition {{label}} was successfully created."},"edit": {"header": "Edit Offer Condition",- "subtitle": "Edit the offer condition details.",+ "subtitle": "Edit the details of the offer condition.","successToast": "Offer condition {{label}} was successfully updated."},"delete": {@@ -3588,15 +3587,21 @@},"fields": {"label": {+ "label": "Label","placeholder": "Refurbished"},"code": {+ "label": "Code","placeholder": "refurbished",- "hint": "Sellers and integrations reference the condition by this code."+ "tooltip": "The code should be a unique identifier for the offer condition."},"rank": {"label": "Rank",- "hint": "Conditions with a lower rank are listed first."+ "tooltip": "Conditions with a lower rank are listed first."+ },+ "isActive": {+ "label": "Enabled",+ "hint": "When disabled, sellers can't list new offers under this condition."}}},diff --git a/packages/admin/src/pages/offer-conditions/offer-condition-create/components/offer-condition-create-form/offer-condition-create-form.tsx b/packages/admin/src/pages/offer-conditions/offer-condition-create/components/offer-condition-create-form/offer-condition-create-form.tsxindex 5be1c093d..706321bef 100644--- a/packages/admin/src/pages/offer-conditions/offer-condition-create/components/offer-condition-create-form/offer-condition-create-form.tsx+++ b/packages/admin/src/pages/offer-conditions/offer-condition-create/components/offer-condition-create-form/offer-condition-create-form.tsx@@ -1,5 +1,5 @@import { zodResolver } from "@hookform/resolvers/zod"-import { Button, Heading, Input, Switch, Text, toast } from "@medusajs/ui"+import { Button, Heading, Input, Text, toast } from "@medusajs/ui"import {Form,KeyboundForm,@@ -10,6 +10,7 @@ import { useForm } from "react-hook-form"import { useTranslation } from "react-i18next"import { z } from "zod"+import { SwitchBox } from "../../../../../components/common/switch-box"import { useCreateOfferCondition } from "../../../../../hooks/api"const OfferConditionCreateSchema = z.object({@@ -86,108 +87,106 @@ export const OfferConditionCreateForm = () => {</Text></RouteFocusModal.Description></div>- <div className="grid grid-cols-1 gap-4 md:grid-cols-2">+ <div className="grid gap-4 md:grid-cols-2"><Form.Fieldcontrol={form.control}name="label"- render={({ field }) => (- <Form.Item>- <Form.Label>{t("fields.label")}</Form.Label>- <Form.Control>- <Input- {...field}- placeholder={t(- "offerConditions.fields.label.placeholder"- )}- data-testid="offer-condition-create-form-label-input"- onChange={(e) => {- if (- !form.getFieldState("code").isTouched ||- !form.getValues("code")- ) {- form.setValue(- "code",- generateCodeFromLabel(e.target.value)- )- }- field.onChange(e)- }}- />- </Form.Control>- <Form.ErrorMessage />- </Form.Item>- )}+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label>+ {t("offerConditions.fields.label.label")}+ </Form.Label>+ <Form.Control>+ <Input+ {...field}+ placeholder={t(+ "offerConditions.fields.label.placeholder"+ )}+ data-testid="offer-condition-create-form-label-input"+ onChange={(e) => {+ if (+ !form.getFieldState("code").isTouched ||+ !form.getValues("code")+ ) {+ form.setValue(+ "code",+ generateCodeFromLabel(e.target.value)+ )+ }+ field.onChange(e)+ }}+ />+ </Form.Control>+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}/><Form.Fieldcontrol={form.control}name="code"- render={({ field }) => (- <Form.Item>- <Form.Label>{t("fields.code")}</Form.Label>- <Form.Control>- <Input- {...field}- placeholder={t(- "offerConditions.fields.code.placeholder"- )}- data-testid="offer-condition-create-form-code-input"- />- </Form.Control>- <Form.Hint>{t("offerConditions.fields.code.hint")}</Form.Hint>- <Form.ErrorMessage />- </Form.Item>- )}+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label+ tooltip={t("offerConditions.fields.code.tooltip")}+ >+ {t("offerConditions.fields.code.label")}+ </Form.Label>+ <Form.Control>+ <Input+ {...field}+ placeholder={t(+ "offerConditions.fields.code.placeholder"+ )}+ data-testid="offer-condition-create-form-code-input"+ />+ </Form.Control>+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}/><Form.Fieldcontrol={form.control}name="rank"- render={({ field }) => (- <Form.Item>- <Form.Label optional>- {t("offerConditions.fields.rank.label")}- </Form.Label>- <Form.Control>- <Input- {...field}- type="number"- min={0}- value={field.value ?? ""}- onChange={(e) =>- field.onChange(- e.target.value === "" ? undefined : Number(e.target.value)- )- }- data-testid="offer-condition-create-form-rank-input"- />- </Form.Control>- <Form.Hint>{t("offerConditions.fields.rank.hint")}</Form.Hint>- <Form.ErrorMessage />- </Form.Item>- )}+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label+ optional+ tooltip={t("offerConditions.fields.rank.tooltip")}+ >+ {t("offerConditions.fields.rank.label")}+ </Form.Label>+ <Form.Control>+ <Input+ {...field}+ type="number"+ min={0}+ value={field.value ?? ""}+ onChange={(e) =>+ field.onChange(+ e.target.value === ""+ ? undefined+ : Number(e.target.value)+ )+ }+ data-testid="offer-condition-create-form-rank-input"+ />+ </Form.Control>+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}/></div>- <Form.Field+ <SwitchBoxcontrol={form.control}name="is_active"- render={({ field: { onChange, value, ...field } }) => (- <Form.Item>- <div className="flex items-center justify-between">- <Form.Label>{t("general.enabled")}</Form.Label>- <Form.Control>- <Switch- dir="ltr"- className="rtl:rotate-180"- onCheckedChange={onChange}- checked={value}- {...field}- data-testid="offer-condition-create-form-enabled-switch"- />- </Form.Control>- </div>- <Form.Hint>{t("offerConditions.enabledHint")}</Form.Hint>- <Form.ErrorMessage />- </Form.Item>- )}+ label={t("offerConditions.fields.isActive.label")}+ description={t("offerConditions.fields.isActive.hint")}/></div></RouteFocusModal.Body>diff --git a/packages/admin/src/pages/offer-conditions/offer-condition-edit/components/offer-condition-edit-form/offer-condition-edit-form.tsx b/packages/admin/src/pages/offer-conditions/offer-condition-edit/components/offer-condition-edit-form/offer-condition-edit-form.tsxindex 831895680..1dbdcaf98 100644--- a/packages/admin/src/pages/offer-conditions/offer-condition-edit/components/offer-condition-edit-form/offer-condition-edit-form.tsx+++ b/packages/admin/src/pages/offer-conditions/offer-condition-edit/components/offer-condition-edit-form/offer-condition-edit-form.tsx@@ -1,5 +1,5 @@import { zodResolver } from "@hookform/resolvers/zod"-import { Button, Input, Switch, toast } from "@medusajs/ui"+import { Button, Input, toast } from "@medusajs/ui"import {Form,KeyboundForm,@@ -11,6 +11,7 @@ import { useForm } from "react-hook-form"import { useTranslation } from "react-i18next"import { z } from "zod"+import { SwitchBox } from "../../../../../components/common/switch-box"import { useUpdateOfferCondition } from "../../../../../hooks/api"type OfferConditionEditFormProps = {@@ -68,87 +69,87 @@ export const OfferConditionEditForm = ({<Form.Fieldcontrol={form.control}name="label"- render={({ field }) => (- <Form.Item>- <Form.Label>{t("fields.label")}</Form.Label>- <Form.Control>- <Input- {...field}- placeholder={t("offerConditions.fields.label.placeholder")}- data-testid="offer-condition-edit-form-label-input"- />- </Form.Control>- <Form.ErrorMessage />- </Form.Item>- )}+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label>+ {t("offerConditions.fields.label.label")}+ </Form.Label>+ <Form.Control>+ <Input+ {...field}+ placeholder={t(+ "offerConditions.fields.label.placeholder"+ )}+ data-testid="offer-condition-edit-form-label-input"+ />+ </Form.Control>+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}/><Form.Fieldcontrol={form.control}name="code"- render={({ field }) => (- <Form.Item>- <Form.Label>{t("fields.code")}</Form.Label>- <Form.Control>- <Input- {...field}- placeholder={t("offerConditions.fields.code.placeholder")}- data-testid="offer-condition-edit-form-code-input"- />- </Form.Control>- <Form.Hint>{t("offerConditions.fields.code.hint")}</Form.Hint>- <Form.ErrorMessage />- </Form.Item>- )}+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label+ tooltip={t("offerConditions.fields.code.tooltip")}+ >+ {t("offerConditions.fields.code.label")}+ </Form.Label>+ <Form.Control>+ <Input+ {...field}+ placeholder={t("offerConditions.fields.code.placeholder")}+ data-testid="offer-condition-edit-form-code-input"+ />+ </Form.Control>+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}/><Form.Fieldcontrol={form.control}name="rank"- render={({ field }) => (- <Form.Item>- <Form.Label optional>- {t("offerConditions.fields.rank.label")}- </Form.Label>- <Form.Control>- <Input- {...field}- type="number"- min={0}- value={field.value ?? ""}- onChange={(e) =>- field.onChange(- e.target.value === "" ? undefined : Number(e.target.value)- )- }- data-testid="offer-condition-edit-form-rank-input"- />- </Form.Control>- <Form.Hint>{t("offerConditions.fields.rank.hint")}</Form.Hint>- <Form.ErrorMessage />- </Form.Item>- )}- />- <Form.Field- control={form.control}- name="is_active"- render={({ field: { onChange, value, ...field } }) => (- <Form.Item>- <div className="flex items-center justify-between">- <Form.Label>{t("general.enabled")}</Form.Label>+ render={({ field }) => {+ return (+ <Form.Item>+ <Form.Label+ optional+ tooltip={t("offerConditions.fields.rank.tooltip")}+ >+ {t("offerConditions.fields.rank.label")}+ </Form.Label><Form.Control>- <Switch- dir="ltr"- className="rtl:rotate-180"- onCheckedChange={onChange}- checked={value}+ <Input{...field}- data-testid="offer-condition-edit-form-enabled-switch"+ type="number"+ min={0}+ value={field.value ?? ""}+ onChange={(e) =>+ field.onChange(+ e.target.value === ""+ ? undefined+ : Number(e.target.value)+ )+ }+ data-testid="offer-condition-edit-form-rank-input"/></Form.Control>- </div>- <Form.Hint>{t("offerConditions.enabledHint")}</Form.Hint>- <Form.ErrorMessage />- </Form.Item>- )}+ <Form.ErrorMessage />+ </Form.Item>+ )+ }}+ />+ <SwitchBox+ control={form.control}+ name="is_active"+ label={t("offerConditions.fields.isActive.label")}+ description={t("offerConditions.fields.isActive.hint")}/></RouteDrawer.Body><RouteDrawer.Footer data-testid="offer-condition-edit-form-footer">