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
import { Trash } from "@medusajs/icons"
import { AdminShippingProfileResponse } from "@medusajs/types"
import { Container, Heading, toast, usePrompt } from "@medusajs/ui"
import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
import { ActionMenu } from "../../../../../components/common/action-menu"
import { SectionRow } from "../../../../../components/common/section"
import { useDeleteShippingProfile } from "../../../../../hooks/api/shipping-profiles"
type ShippingProfileGeneralSectionProps = {
profile: AdminShippingProfileResponse["shipping_profile"]
}
export const ShippingProfileGeneralSection = ({
profile,
}: ShippingProfileGeneralSectionProps) => {
const { t } = useTranslation()
const prompt = usePrompt()
const navigate = useNavigate()
const { mutateAsync } = useDeleteShippingProfile(profile.id)
const handleDelete = async () => {
const res = await prompt({
title: t("shippingProfile.delete.title"),
description: t("shippingProfile.delete.description", {
name: profile.name,
}),
verificationText: profile.name,
verificationInstruction: t("general.typeToConfirm"),
confirmText: t("actions.delete"),
cancelText: t("actions.cancel"),
})
if (!res) {
return
}
await mutateAsync(undefined, {
onSuccess: () => {
toast.success(
t("shippingProfile.delete.successToast", {
name: profile.name,
})
)
navigate("/settings/locations/shipping-profiles", { replace: true })
},
onError: (error) => {
toast.error(error.message)
},
})
}
return (
<Container className="divide-y p-0" data-testid="shipping-profile-general-section-container">
<div className="flex items-center justify-between px-6 py-4" data-testid="shipping-profile-general-section-header">
<Heading data-testid="shipping-profile-general-section-heading">{profile.name}</Heading>
<ActionMenu
groups={[
{
actions: [
{
icon: <Trash />,
permission: "shipping_profiles:manage",
label: t("actions.delete"),
onClick: handleDelete,
},
],
},
]}
data-testid="shipping-profile-general-section-action-menu"
/>
</div>
<SectionRow title={t("fields.type")} value={profile.type} data-testid="shipping-profile-general-section-type-row" />
</Container>
)
}