import Button from "@material-ui/core/Button"; import Card from "@material-ui/core/Card"; import CardContent from "@material-ui/core/CardContent"; import { createStyles, Theme, withStyles, WithStyles } from "@material-ui/core/styles"; import Typography from "@material-ui/core/Typography"; import React from "react"; import CardTitle from "@saleor/components/CardTitle"; import ExternalLink from "@saleor/components/ExternalLink"; import Form from "@saleor/components/Form"; import Hr from "@saleor/components/Hr"; import Link from "@saleor/components/Link"; import SingleAutocompleteSelectField from "@saleor/components/SingleAutocompleteSelectField"; import Skeleton from "@saleor/components/Skeleton"; import { SearchCustomers_customers_edges_node } from "../../../containers/SearchCustomers/types/SearchCustomers"; import { customerUrl } from "../../../customers/urls"; import i18n from "../../../i18n"; import { createHref, maybe } from "../../../misc"; import { OrderDetails_order } from "../../types/OrderDetails"; const styles = (theme: Theme) => createStyles({ sectionHeader: { alignItems: "center", display: "flex", marginBottom: theme.spacing.unit * 3 }, sectionHeaderTitle: { flex: 1, fontWeight: 600 as 600, lineHeight: 1, textTransform: "uppercase" }, sectionHeaderToolbar: { marginRight: -theme.spacing.unit * 2 }, userEmail: { fontWeight: 600 as 600, marginBottom: theme.spacing.unit } }); export interface OrderCustomerProps extends WithStyles { order: OrderDetails_order; users?: SearchCustomers_customers_edges_node[]; loading?: boolean; canEditAddresses: boolean; canEditCustomer: boolean; fetchUsers?: (query: string) => void; onCustomerEdit?: (data: { user?: string; userEmail?: string }) => void; onProfileView: () => void; onBillingAddressEdit?: () => void; onShippingAddressEdit?: () => void; } const OrderCustomer = withStyles(styles, { name: "OrderCustomer" })( ({ classes, canEditAddresses, canEditCustomer, fetchUsers, loading, order, users, onCustomerEdit, onBillingAddressEdit, onProfileView, onShippingAddressEdit }: OrderCustomerProps) => { const [isInEditMode, setEditModeStatus] = React.useState(false); const toggleEditMode = () => setEditModeStatus(!isInEditMode); const billingAddress = maybe(() => order.billingAddress); const shippingAddress = maybe(() => order.shippingAddress); const user = maybe(() => order.user); return ( {i18n.t("Edit")} ) } /> {user === undefined ? ( ) : isInEditMode && canEditCustomer ? (
{({ change, data }) => { const handleChange = (event: React.ChangeEvent) => { change(event); onCustomerEdit({ [event.target.value.value.includes("@") ? "userEmail" : "user"]: event.target.value.value }); toggleEditMode(); }; return ( users, []).map(user => ({ label: user.email, value: user.id }))} fetchChoices={fetchUsers} loading={loading} placeholder={i18n.t("Search Customers")} onChange={handleChange} name="query" value={data.query} /> ); }} ) : user === null ? ( {i18n.t("Anonymous user")} ) : ( <> {user.email}
{i18n.t("View Profile")}
{/* TODO: Uncomment it after adding ability to filter orders by customer */} {/*
{i18n.t("View Orders")}
*/} )}

{i18n.t("Contact information")}
{maybe(() => order.userEmail) === undefined ? ( ) : order.userEmail === null ? ( {i18n.t("Not set")} ) : ( order.userEmail)}`} typographyProps={{ color: "primary" }} > {maybe(() => order.userEmail)} )}

{i18n.t("Shipping Address")} {canEditAddresses && (
)}
{shippingAddress === undefined ? ( ) : shippingAddress === null ? ( {i18n.t("Not set")} ) : ( <> {shippingAddress.companyName && ( {shippingAddress.companyName} )} {shippingAddress.firstName} {shippingAddress.lastName} {shippingAddress.streetAddress1}
{shippingAddress.streetAddress2}
{shippingAddress.postalCode} {shippingAddress.city} {shippingAddress.cityArea ? ", " + shippingAddress.cityArea : ""} {shippingAddress.countryArea ? shippingAddress.countryArea + ", " + shippingAddress.country.country : shippingAddress.country.country} {shippingAddress.phone} )}

{i18n.t("Billing Address")} {canEditAddresses && (
)}
{billingAddress === undefined ? ( ) : billingAddress === null ? ( {i18n.t("Not set")} ) : maybe(() => shippingAddress.id) === billingAddress.id ? ( {i18n.t("Same as shipping address")} ) : ( <> {billingAddress.companyName && ( {billingAddress.companyName} )} {billingAddress.firstName} {billingAddress.lastName} {billingAddress.streetAddress1}
{billingAddress.streetAddress2}
{billingAddress.postalCode} {billingAddress.city} {billingAddress.cityArea ? ", " + billingAddress.cityArea : ""} {billingAddress.countryArea ? billingAddress.countryArea + ", " + billingAddress.country.country : billingAddress.country.country} {billingAddress.phone} )}
); } ); OrderCustomer.displayName = "OrderCustomer"; export default OrderCustomer;