import { PencilSquare, Trash } from "@medusajs/icons" import { HttpTypes } from "@medusajs/types" import { Container, Heading, StatusBadge, Text, toast, usePrompt, } from "@medusajs/ui" import { useTranslation } from "react-i18next" import { useNavigate } from "react-router-dom" import { ActionGroup, ActionMenu, } from "../../../../../components/common/action-menu" import { useDeleteCustomer } from "../../../../../hooks/api/customers" import { useCustomerPermissions } from "../../../../../hooks/use-resource-permissions" type CustomerGeneralSectionProps = { customer: HttpTypes.AdminCustomer } export const CustomerGeneralSection = ({ customer, }: CustomerGeneralSectionProps) => { const { t } = useTranslation() const prompt = usePrompt() const navigate = useNavigate() const { canUpdate, canDelete } = useCustomerPermissions() const { mutateAsync } = useDeleteCustomer(customer.id) const name = [customer.first_name, customer.last_name] .filter(Boolean) .join(" ") const statusColor = customer.has_account ? "green" : "orange" const statusText = customer.has_account ? t("customers.fields.registered") : t("customers.fields.guest") const handleDelete = async () => { const res = await prompt({ title: t("customers.delete.title"), description: t("customers.delete.description", { email: customer.email, }), verificationInstruction: t("general.typeToConfirm"), verificationText: customer.email, confirmText: t("actions.delete"), cancelText: t("actions.cancel"), }) if (!res) { return } await mutateAsync(undefined, { onSuccess: () => { toast.success( t("customers.delete.successToast", { email: customer.email, }) ) navigate("/customers", { replace: true }) }, onError: (error) => { toast.error(error.message) }, }) } const groups: ActionGroup[] = [] if (canUpdate) { groups.push({ actions: [ { label: t("actions.edit"), icon: , to: "edit", }, ], }) } if (canDelete) { groups.push({ actions: [ { label: t("actions.delete"), icon: , onClick: handleDelete, }, ], }) } return (
{customer.email}
{statusText} {groups.length > 0 && }
{t("fields.name")} {name || "-"}
{t("fields.company")} {customer.company_name || "-"}
{t("fields.phone")} {customer.phone || "-"}
) }