Tally UI

ReceiptEmailForm

ReceiptEmailForm is WCPOS v2's receipt email form, the one ReceiptSheet draws, for apps that draw the receipt inline.

Import

import { ReceiptEmailForm } from '@tallyui/components';

Usage

import { useState } from 'react';
import { Button, ReceiptEmailForm, ReceiptPreview, Text } from '@tallyui/components';

function ReceiptView({ order, online }) {
  const [round, setRound] = useState(0);
  return (
    <>
      <ReceiptPreview items={order.items} subtotal={order.subtotal} tax={order.tax} total={order.total} />
      <ReceiptEmailForm
        key={round}
        email={{ defaultAddress: order.billing.email, offline: !online, onSend: ({ address }) => sendReceipt(order.id, address) }}
      />
      <Button onPress={() => setRound((n) => n + 1)}><Text>Email again</Text></Button>
    </>
  );
}

It draws the form ReceiptSheet draws: an "Email Address" field prefilled from defaultAddress, a "Save email to the customer" switch (off) when saveToCustomer is set, v2's offline notice when offline is set, and Send, which reads "Send when online" when offline. Send refuses an address that is not name@domain (one @, no spaces) inline ("Enter an email address.") and otherwise calls onSend({ address, saveToCustomer }) with the trimmed address. A returned string shows as an alert in the form, and so does the message of an Error that onSend throws or rejects with (anything else thrown or rejected, an empty string and an empty message show "Could not send the receipt."); while a promise is pending Send shows a spinner and cannot be pressed.

After onSend returns null, the form draws "Email sent" in its own place, or "Receipt email queued" when offline is set (keys receipt.email_sent and receipt.email_queued, testID receipt-email-sent), and calls onDone. It keeps showing that line until it is unmounted; give it a new key to send again.

Props

PropTypeDefaultDescription
emailReceiptSheetEmailrequiredThe address, offline and save options and onSend; the shape is on ReceiptSheet
onDone(queued: boolean) => void—Called once after a send, with true when it was queued offline

On this page