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 { ActionMenu } from "../../../../../components/common/action-menu" import { useDeleteCustomer } from "../../../../../hooks/api/customers" type CustomerGeneralSectionProps = { customer: HttpTypes.AdminCustomer } export const CustomerGeneralSection = ({ customer, }: CustomerGeneralSectionProps) => { const { t } = useTranslation() const prompt = usePrompt() const navigate = useNavigate() 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) }, }) } return (
{customer.email}
{statusText} , to: "edit", }, ], }, { actions: [ { label: t("actions.delete"), icon: , onClick: handleDelete, }, ], }, ]} />
{t("fields.name")} {name || "-"}
{t("fields.company")} {customer.company_name || "-"}
{t("fields.phone")} {customer.phone || "-"}
) }