import { useLoaderData, Link } from "react-router";
import { boundary } from "@shopify/shopify-app-react-router/server";
import { authenticate } from "../shopify.server";
import { getQRCodes } from "../models/QRCode.server";
export async function loader({ request }) {
const { admin, session } = await authenticate.admin(request);
const qrCodes = await getQRCodes(session.shop, admin.graphql);
return {
qrCodes,
};
}
const EmptyQRCodeState = () => (
Create unique QR codes for your products
Allow customers to scan codes and buy products using their phones.
Create QR code
);
function truncate(str, { length = 25 } = {}) {
if (!str) return "";
if (str.length <= length) return str;
return str.slice(0, length) + "…";
}
const QRTable = ({ qrCodes }) => (
Title
Product
Date created
Scans
{qrCodes.map((qrCode) => (
))}
);
const QRTableRow = ({ qrCode }) => (
{qrCode.productImage ? (
) : (
)}
{truncate(qrCode.title)}
{qrCode.productDeleted ? (
Product has been deleted
) : (
truncate(qrCode.productTitle)
)}
{new Date(qrCode.createdAt).toDateString()}
{qrCode.scans}
);
export default function Index() {
const { qrCodes } = useLoaderData();
return (
Create QR code
{qrCodes.length === 0 ? (
) : (
)}
);
}
export const headers = (headersArgs) => {
return boundary.headers(headersArgs);
};