This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Commerce from "@chec/commerce.js"; | |
const commercePublicKey = process.env.COMMERCEJS_PUBLIC_KEY; | |
export const commerce = new Commerce(commercePublicKey); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import PlausibleProvider from "next-plausible"; | |
function MyApp({ Component, pageProps }: AppProps) { | |
return ( | |
<PlausibleProvider domain="best-ecommercesite.com"> | |
<Component {...pageProps} /> | |
</PlausibleProvider> | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleAddToCart = async () => { | |
try { | |
const { cart } = await commerce.cart.add(product.id, quantity) | |
setCart(cart) | |
plausible("addProductToCart", { | |
props: { | |
productName: product.name, | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const handleAddToCart = async (productId: string, quantity: number) => { | |
const { cart } = await commerce.cart.add(productId, quantity) | |
setCart(cart) | |
plausible("addProductToCart") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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< |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
build() { | |
mint build --skip-service-worker --skip-icons | |
} | |
copy_icon() { | |
cp icon.png ./dist | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import styled from 'styled-components'; | |
const StyledTitle = styled.h1` | |
font-size: 1.5em; | |
text-align: center; | |
color: palevioletred; | |
`; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ThemeProvider } from 'styled-components'; | |
const theme = { | |
primary: PRIMARY_COLOR, | |
error: ERROR_COLOR, | |
}; | |
return ( | |
<ThemeProvider theme={theme}> | |
<App /> |
NewerOlder