diff --git a/.changeset/four-kings-drive.md b/.changeset/four-kings-drive.md new file mode 100644 index 0000000000..f278c7438f --- /dev/null +++ b/.changeset/four-kings-drive.md @@ -0,0 +1,5 @@ +--- +"@medusajs/dashboard": patch +--- + +fix(dashboard):replace native select Element in CountrySelect & ProvinceSelect with Select(Medusa UI). diff --git a/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx b/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx index 7ccec4e0ce..07d8904c0c 100644 --- a/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx +++ b/packages/admin/dashboard/src/components/inputs/country-select/country-select.tsx @@ -4,75 +4,50 @@ import { useImperativeHandle, useRef, } from "react" - -import { TrianglesMini } from "@medusajs/icons" -import { clx } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { countries } from "../../../lib/data/countries" +import { Select } from "@medusajs/ui" export const CountrySelect = forwardRef< - HTMLSelectElement, - ComponentPropsWithoutRef<"select"> & { + HTMLButtonElement, + ComponentPropsWithoutRef & { placeholder?: string - value?: string defaultValue?: string + onChange?: (value: string) => void } ->( - ( - { className, disabled, placeholder, value, defaultValue, ...props }, - ref - ) => { - const { t } = useTranslation() - const innerRef = useRef(null) +>(({ disabled, placeholder, defaultValue, onChange, ...field }, ref) => { + const { t } = useTranslation() + const innerRef = useRef(null) - useImperativeHandle(ref, () => innerRef.current as HTMLSelectElement) + useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement) + + return ( +
+ +
+ ) +}) - const isPlaceholder = innerRef.current?.value === "" - - return ( -
- - -
- ) - } -) CountrySelect.displayName = "CountrySelect" diff --git a/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx b/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx index 6813b44816..d1c60d95ec 100644 --- a/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx +++ b/packages/admin/dashboard/src/components/inputs/province-select/province-select.tsx @@ -4,47 +4,36 @@ import { useImperativeHandle, useRef, } from "react" - -import { TrianglesMini } from "@medusajs/icons" -import { clx } from "@medusajs/ui" +import { Select } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { getCountryProvinceObjectByIso2 } from "../../../lib/data/country-states" -interface ProvinceSelectProps extends ComponentPropsWithoutRef<"select"> { - /** - * ISO 3166-1 alpha-2 country code - */ - country_code: string - /** - * Whether to use the ISO 3166-1 alpha-2 code or the name of the province as the value - * - * @default "iso_2" - */ - valueAs?: "iso_2" | "name" - placeholder?: string -} - export const ProvinceSelect = forwardRef< - HTMLSelectElement, - ProvinceSelectProps + HTMLButtonElement, + ComponentPropsWithoutRef & { + placeholder?: string + defaultValue?: string + country_code: string + valueAs?: "iso_2" | "name" + onChange?: (value: string) => void + } >( ( { - className, disabled, placeholder, + defaultValue, country_code, valueAs = "iso_2", - ...props + onChange, + ...field }, ref ) => { const { t } = useTranslation() - const innerRef = useRef(null) + const innerRef = useRef(null) - useImperativeHandle(ref, () => innerRef.current as HTMLSelectElement) - - const isPlaceholder = innerRef.current?.value === "" + useImperativeHandle(ref, () => innerRef.current as HTMLButtonElement) const provinceObject = getCountryProvinceObjectByIso2(country_code) @@ -55,9 +44,12 @@ export const ProvinceSelect = forwardRef< const options = Object.entries(provinceObject?.options ?? {}).map( ([iso2, name]) => { return ( - + ) } ) @@ -66,46 +58,34 @@ export const ProvinceSelect = forwardRef< ? t(`taxRegions.fields.sublevels.placeholders.${provinceObject.type}`) : "" - const placeholderOption = provinceObject ? ( - - ) : null - return (
- - + + + + {options} +
) } ) -ProvinceSelect.displayName = "CountrySelect" +ProvinceSelect.displayName = "ProvinceSelect" diff --git a/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx b/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx index 26bb8ba9b6..291cb310e7 100644 --- a/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx +++ b/packages/admin/dashboard/src/routes/locations/location-edit/components/edit-location-form/edit-location-form.tsx @@ -4,12 +4,11 @@ import { Button, Input, toast } from "@medusajs/ui" import { useForm } from "react-hook-form" import { useTranslation } from "react-i18next" import * as zod from "zod" - import { Form } from "../../../../../components/common/form" -import { CountrySelect } from "../../../../../components/inputs/country-select" import { RouteDrawer, useRouteModal } from "../../../../../components/modals" import { KeyboundForm } from "../../../../../components/utilities/keybound-form" import { useUpdateStockLocation } from "../../../../../hooks/api/stock-locations" +import { CountrySelect } from "../../../../../components/inputs/country-select/country-select" type EditLocationFormProps = { location: HttpTypes.AdminStockLocation