import { useAdminCustomer } from "medusa-react" import moment from "moment" import { useState } from "react" import { useNavigate, useParams } from "react-router-dom" import { useTranslation } from "react-i18next" import Avatar from "../../../components/atoms/avatar" import BackButton from "../../../components/atoms/back-button" import Spinner from "../../../components/atoms/spinner" import WidgetContainer from "../../../components/extensions/widget-container" import EditIcon from "../../../components/fundamentals/icons/edit-icon" import StatusDot from "../../../components/fundamentals/status-indicator" import Actionables, { ActionType, } from "../../../components/molecules/actionables" import BodyCard from "../../../components/organisms/body-card" import RawJSON from "../../../components/organisms/raw-json" import Section from "../../../components/organisms/section" import CustomerOrdersTable from "../../../components/templates/customer-orders-table" import { useWidgets } from "../../../providers/widget-provider" import { getErrorStatus } from "../../../utils/get-error-status" import EditCustomerModal from "./edit" const CustomerDetail = () => { const { id } = useParams() const navigate = useNavigate() const { customer, isLoading, error } = useAdminCustomer(id!) const { t } = useTranslation() const [showEdit, setShowEdit] = useState(false) const customerName = () => { if (customer?.first_name && customer?.last_name) { return `${customer.first_name} ${customer.last_name}` } else { return customer?.email } } const actions: ActionType[] = [ { label: t("details-edit", "Edit"), onClick: () => setShowEdit(true), icon: , }, ] const { getWidgets } = useWidgets() if (error) { const errorStatus = getErrorStatus(error) if (errorStatus) { // If the product is not found, redirect to the 404 page if (errorStatus.status === 404) { navigate("/404") return null } } // Let the error boundary handle the error throw error } if (isLoading || !customer) { return (
) } return (
{getWidgets("customer.details.before").map((w, i) => { return ( ) })}

{customerName()}

{customer.email}

{t("details-first-seen", "First seen")}
{moment(customer.created_at).format("DD MMM YYYY")}
{t("details-phone", "Phone")}
{customer.phone || "N/A"}
{t("details-orders", "Orders")}
{customer.orders.length}
{t("details-user", "User")}
{getWidgets("customer.details.after").map((w, i) => { return ( ) })}
{showEdit && customer && ( setShowEdit(false)} /> )}
) } export default CustomerDetail