import { StockLocationDTO } from "@medusajs/types" import { useAdminDeleteStockLocation } from "medusa-react" import React from "react" import { useTranslation } from "react-i18next" import IconBadge from "../../../../../components/fundamentals/icon-badge" import BuildingsIcon from "../../../../../components/fundamentals/icons/buildings-icon" import EditIcon from "../../../../../components/fundamentals/icons/edit-icon" import TrashIcon from "../../../../../components/fundamentals/icons/trash-icon" import Actionables, { ActionType, } from "../../../../../components/molecules/actionables" import useImperativeDialog from "../../../../../hooks/use-imperative-dialog" import useNotification from "../../../../../hooks/use-notification" import useToggleState from "../../../../../hooks/use-toggle-state" import { useFeatureFlag } from "../../../../../providers/feature-flag-provider" import { countryLookup } from "../../../../../utils/countries" import { getErrorMessage } from "../../../../../utils/error-messages" import LocationEditModal from "../../edit" import SalesChannelsSection from "../sales-channels-section" type Props = { location: StockLocationDTO } const LocationCard: React.FC = ({ location }) => { const { t } = useTranslation() const { mutate: deleteLocation } = useAdminDeleteStockLocation(location.id) const dialog = useImperativeDialog() const notification = useNotification() const { isFeatureEnabled } = useFeatureFlag() const { state: editLocationState, close: closeLocationEdit, open: openLocationEdit, } = useToggleState() const onDelete = async () => { const shouldDelete = await dialog({ heading: t("location-card-delete-location", "Delete Location"), text: t( "location-card-confirm-delete", "Are you sure you want to delete this location. This will also delete all inventory levels and reservations associated with this location." ), extraConfirmation: true, entityName: location.name, }) if (shouldDelete) { deleteLocation(undefined, { onSuccess: () => { notification( t("location-card-success", "Success"), t( "location-card-location-deleted-successfully", "Location deleted successfully" ), "success" ) }, onError: (err) => { notification( t("location-card-error", "Error"), getErrorMessage(err), "error" ) }, }) } } const DropdownActions: ActionType[] = [ { label: t("location-card-edit-details", "Edit details"), onClick: openLocationEdit, variant: "normal", icon: , }, { label: t("location-card-delete", "Delete"), onClick: onDelete, variant: "danger", icon: , }, ] return (
{location.name} {location.address && (
{location.address.city && {location.address.city}, } {countryLookup(location.address.country_code)}
)}
{isFeatureEnabled("sales_channels") && (

{t( "location-card-connected-sales-channels", "Connected sales channels" )}

)} {editLocationState && ( )}
) } export default LocationCard