Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AdminPrintAction component #2040

Merged
merged 1 commit into from
Jun 10, 2024
Merged

Add AdminPrintAction component #2040

merged 1 commit into from
Jun 10, 2024

Conversation

elanalynn
Copy link
Contributor

Background

Closes https://github.com/Shopify/app-ui/issues/1178

Adds new admin component for the admin print action extension: AdminPrintAction

Solution

Add component type, docs, and examples for vanilla and react components.

🎩

  • Run the print demo app
  • In the this branch of ui-extensions run yarn build-consumer print-demo-app
  • Confirm that you can import the AdminPrintAction component and run your extension

Sample extension code

import {
  reactExtension,
  useApi,
  AdminPrintAction,
  BlockStack,
  Checkbox,
  Text,
 } from '@shopify/ui-extensions-react/admin';
import { useEffect, useState } from 'react';
 
const TARGET = 'admin.order-details.print-action.render';

export default reactExtension(TARGET, () => <App />);

function App() {
  const {i18n, data} = useApi(TARGET);
  const [appUrl,setAppUrl] = useState(" ");
  const [src,setSrc] = useState("");
  const [printInvoice, setPrintInvoice] = useState(true);
  const [printPackingSlip, setPrintPackingSlip] = useState(false);
  const [printWarranty, setPrintWarranty] = useState(false);

  console.log({data})

  useEffect(()=>{ 
    const fetchData = async () => {
          const response = await fetch('/');
          const responseUrl = response.url;
          setAppUrl(responseUrl);
    };  
    fetchData();

  },[]);  
    
  useEffect(()=>{
    const printTypes = []
    if (printInvoice) {
      printTypes.push("Invoice");
    } ;
    if (printPackingSlip) {
      printTypes.push("Packing Slip");
    };
    if (printWarranty) {
      printTypes.push("Warranty");
    };

    const fullSrc = appUrl+'print?printType='+printTypes.join(",");
    setSrc(fullSrc);
  }, [appUrl, printInvoice, printPackingSlip, printWarranty]);
 
  return ( 
    <AdminPrintAction src={src}> 
      <BlockStack>
        <Text>{i18n.translate('choose')}</Text> 
        <Checkbox name="Invoice" checked={printInvoice} onChange={(value)=>{setPrintInvoice(value)}}>
          Invoice
        </Checkbox>
        <Checkbox name="Packing Slips" checked={printPackingSlip} onChange={(value)=>{setPrintPackingSlip(value)}}>
          Packing Slips
        </Checkbox>
        <Checkbox name="Warranty" checked={printWarranty} onChange={(value)=>setPrintWarranty(value)}>
          Warranty
        </Checkbox> 
      </BlockStack>
    </AdminPrintAction>
  ); 
}

Checklist

  • I have 🎩'd these changes
  • I have updated relevant documentation

This comment has been minimized.

@elanalynn elanalynn force-pushed the 1178-adminprintaction branch 2 times, most recently from 9713a50 to 92c50ff Compare May 30, 2024 16:47
Copy link
Contributor

@MitchLillie MitchLillie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎩, added a few comments

@MitchLillie
Copy link
Contributor

Also one other note: We should probably wait to ship this PR. As soon as it is merged, the component will be available on unstable and we will need to document it.

Copy link
Contributor

@MitchLillie MitchLillie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@elanalynn elanalynn merged commit dcb76f7 into unstable Jun 10, 2024
5 checks passed
@elanalynn elanalynn deleted the 1178-adminprintaction branch June 10, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants