Skip to content

Instantly share code, notes, and snippets.

import { connectToDatabase } from 'utils/db';
import { withAuth } from 'utils/auth';
import User from 'utils/db/user';
const handler = async (req, res) => {
// Ensure that we're connected to the database
await assertDBConnection()
// Find all users and return them as JSON
const users = await User.find({})
import Commerce from "@chec/commerce.js";
const commercePublicKey = process.env.COMMERCEJS_PUBLIC_KEY;
export const commerce = new Commerce(commercePublicKey);
import PlausibleProvider from "next-plausible";
function MyApp({ Component, pageProps }: AppProps) {
return (
<PlausibleProvider domain="best-ecommercesite.com">
<Component {...pageProps} />
</PlausibleProvider>
);
}
const handleAddToCart = async () => {
try {
const { cart } = await commerce.cart.add(product.id, quantity)
setCart(cart)
plausible("addProductToCart", {
props: {
productName: product.name,
}
})
import { usePlausible } from "next-plausible"
import { commerce } from "libs/commercejs"
import { useCart } from "context/cart"
function AddToCartButton({ product, quantity }) {
const { setCart } = useCart() // <-- a custom hook to manage cart state
const plausible = usePlausible() // <-- access the plausible API
const handleAddToCart = async () => {
const { cart } = await commerce.cart.add(product.id, quantity)
const handleAddToCart = async (productId: string, quantity: number) => {
const { cart } = await commerce.cart.add(productId, quantity)
setCart(cart)
plausible("addProductToCart")
}
import type { ReactNode } from "react";
import type { Props as ReactIntlFormattedMessageProps } from "react-intl/src/components/message";
import { FormattedMessage as ReactIntlFormattedMessage } from "react-intl";
import enMessages from "./en.json";
// Our new union type of all available message IDs.
type IntlMessageKeys = keyof typeof enMessages;
// Extend the original FormattedMessage props.
type FormattedMessageProps = ReactIntlFormattedMessageProps<
#!/bin/bash
build() {
mint build --skip-service-worker --skip-icons
}
copy_icon() {
cp icon.png ./dist
}
import React from 'react';
import styled from 'styled-components';
const StyledTitle = styled.h1`
font-size: 1.5em;
text-align: center;
color: palevioletred;
`;
import { ThemeProvider } from 'styled-components';
const theme = {
primary: PRIMARY_COLOR,
error: ERROR_COLOR,
};
return (
<ThemeProvider theme={theme}>
<App />