({
searchParams,
}: PageProps)
| 16 | } |
| 17 | |
| 18 | const ThankYouPage = async ({ |
| 19 | searchParams, |
| 20 | }: PageProps) => { |
| 21 | const orderId = searchParams.orderId |
| 22 | const nextCookies = cookies() |
| 23 | |
| 24 | const { user } = await getServerSideUser(nextCookies) |
| 25 | const payload = await getPayloadClient() |
| 26 | |
| 27 | const { docs: orders } = await payload.find({ |
| 28 | collection: 'orders', |
| 29 | depth: 2, |
| 30 | where: { |
| 31 | id: { |
| 32 | equals: orderId, |
| 33 | }, |
| 34 | }, |
| 35 | }) |
| 36 | |
| 37 | const [order] = orders |
| 38 | |
| 39 | if (!order) return notFound() |
| 40 | |
| 41 | const orderUserId = |
| 42 | typeof order.user === 'string' |
| 43 | ? order.user |
| 44 | : order.user.id |
| 45 | |
| 46 | if (orderUserId !== user?.id) { |
| 47 | return redirect( |
| 48 | `/sign-in?origin=thank-you?orderId=${order.id}` |
| 49 | ) |
| 50 | } |
| 51 | |
| 52 | const products = order.products as Product[] |
| 53 | |
| 54 | const orderTotal = products.reduce((total, product) => { |
| 55 | return total + product.price |
| 56 | }, 0) |
| 57 | |
| 58 | return ( |
| 59 | <main className='relative lg:min-h-full'> |
| 60 | <div className='hidden lg:block h-80 overflow-hidden lg:absolute lg:h-full lg:w-1/2 lg:pr-4 xl:pr-12'> |
| 61 | <Image |
| 62 | fill |
| 63 | src='/checkout-thank-you.jpg' |
| 64 | className='h-full w-full object-cover object-center' |
| 65 | alt='thank you for your order' |
| 66 | /> |
| 67 | </div> |
| 68 | |
| 69 | <div> |
| 70 | <div className='mx-auto max-w-2xl px-4 py-16 sm:px-6 sm:py-24 lg:grid lg:max-w-7xl lg:grid-cols-2 lg:gap-x-8 lg:px-8 lg:py-32 xl:gap-x-24'> |
| 71 | <div className='lg:col-start-2'> |
| 72 | <p className='text-sm font-medium text-blue-600'> |
| 73 | Order successful |
| 74 | </p> |
| 75 | <h1 className='mt-2 text-4xl font-bold tracking-tight text-gray-900 sm:text-5xl'> |
nothing calls this directly
no test coverage detected