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 { FormattedMessage, useIntl } from "react-intl"; 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 useStateFromProps from "@saleor/hooks/useStateFromProps"; import { buttonMessages } from "@saleor/intl"; import createSingleAutocompleteSelectHandler from "@saleor/utils/handlers/singleAutocompleteSelectChangeHandler"; import { SearchCustomers_customers_edges_node } from "../../../containers/SearchCustomers/types/SearchCustomers"; import { customerUrl } from "../../../customers/urls"; 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 intl = useIntl(); const user = maybe(() => order.user); const [userDisplayName, setUserDisplayName] = useStateFromProps( maybe(() => user.email, "") ); const [isInEditMode, setEditModeStatus] = React.useState(false); const toggleEditMode = () => setEditModeStatus(!isInEditMode); const billingAddress = maybe(() => order.billingAddress); const shippingAddress = maybe(() => order.shippingAddress); return ( {intl.formatMessage(buttonMessages.edit)} ) } /> {user === undefined ? ( ) : isInEditMode && canEditCustomer ? (
{({ change, data }) => { const handleChange = (event: React.ChangeEvent) => { change(event); const value = event.target.value; onCustomerEdit({ [value.includes("@") ? "userEmail" : "user"]: value }); toggleEditMode(); }; const userChoices = maybe(() => users, []).map(user => ({ label: user.email, value: user.id })); const handleUserChange = createSingleAutocompleteSelectHandler( handleChange, setUserDisplayName, userChoices ); return ( ); }} ) : user === null ? ( ) : ( <> {user.email}
{/* TODO: Uncomment it after adding ability to filter orders by customer */} {/*
*/} )}

{maybe(() => order.userEmail) === undefined ? ( ) : order.userEmail === null ? ( ) : ( order.userEmail)}`} typographyProps={{ color: "primary" }} > {maybe(() => order.userEmail)} )}

{canEditAddresses && (
)}
{shippingAddress === undefined ? ( ) : shippingAddress === null ? ( ) : ( <> {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} )}

{canEditAddresses && (
)}
{billingAddress === undefined ? ( ) : billingAddress === null ? ( ) : maybe(() => shippingAddress.id) === billingAddress.id ? ( ) : ( <> {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;