- Scanning the QR code app redicts to page - Option to chose if we want to redirect to page or checkout
31 lines
760 B
JavaScript
31 lines
760 B
JavaScript
import invariant from "tiny-invariant";
|
|
import { useLoaderData } from "react-router";
|
|
|
|
import db from "../db.server";
|
|
import { getQRCodeImage } from "../models/QRCode.server";
|
|
|
|
export const loader = async ({ params }) => {
|
|
invariant(params.id, "Could not find QR code destination");
|
|
|
|
const id = Number(params.id);
|
|
const qrCode = await db.qRCode.findFirst({ where: { id } });
|
|
|
|
invariant(qrCode, "Could not find QR code destination");
|
|
|
|
return {
|
|
title: qrCode.title,
|
|
image: await getQRCodeImage(id),
|
|
};
|
|
};
|
|
|
|
export default function QRCode() {
|
|
const { image, title } = useLoaderData();
|
|
|
|
return (
|
|
<>
|
|
<h1>{title}</h1>
|
|
<img src={image} alt={`QR Code for product`} />
|
|
</>
|
|
);
|
|
}
|