import { useAdminRegions } from "medusa-react" import React, { useCallback, useEffect } from "react" import { useNavigate } from "react-router-dom" import { useTranslation } from "react-i18next" import Fade from "../../../../components/atoms/fade-wrapper" import Button from "../../../../components/fundamentals/button" import PlusIcon from "../../../../components/fundamentals/icons/plus-icon" import RadioGroup from "../../../../components/organisms/radio-group" import Section from "../../../../components/organisms/section" import useToggleState from "../../../../hooks/use-toggle-state" import { useAnalytics } from "../../../../providers/analytics-provider" import NewRegion from "../new" import RegionCard from "./region-card" type Props = { id?: string } const RegionOverview = ({ id }: Props) => { const { t } = useTranslation() const navigate = useNavigate() const { trackRegions } = useAnalytics() const { regions } = useAdminRegions(undefined, { onSuccess: ({ regions, count }) => { trackRegions({ regions: regions.map((r) => r.name), count }) }, }) const [selectedRegion, setSelectedRegion] = React.useState< string | undefined >(id) const handleChange = useCallback( (id: string) => { if (id !== selectedRegion) { setSelectedRegion(id) navigate(`/a/settings/regions/${id}`, { replace: true, }) } }, [navigate, selectedRegion] ) useEffect(() => { if (id) { handleChange(id) } if (!id && regions && regions.length > 0) { handleChange(regions[0].id) } }, [handleChange, id, regions]) const { state, toggle, close } = useToggleState() return ( <> } className="h-full" > {t( "region-overview-manage-the-markets-that-you-will-operate-within", "Manage the markets that you will operate within." )} {regions?.map((region) => ( ))} > ) } export default RegionOverview
{t( "region-overview-manage-the-markets-that-you-will-operate-within", "Manage the markets that you will operate within." )}