Skip to content

Commit

Permalink
feat(proaws): events as products (#177)
Browse files Browse the repository at this point in the history
* feat: adds event CRUD

* feat: an "edit product" button

clicking the event i the product from the list links to a bad place

* feat: clicking an event in a product resource list will open that event edit page

* chore: debug clearing

* changeset added

* meh
  • Loading branch information
joelhooks committed May 13, 2024
1 parent a939e2b commit 2d2be35
Show file tree
Hide file tree
Showing 62 changed files with 1,266 additions and 243 deletions.
9 changes: 9 additions & 0 deletions .changeset/silver-impalas-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@coursebuilder/adapter-drizzle": patch
"@coursebuilder/commerce-next": patch
"@coursebuilder/core": patch
"@coursebuilder/next": patch
"@coursebuilder/ui": patch
---

adding events as products to proaws
4 changes: 4 additions & 0 deletions apps/pro-aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@fontsource/inter": "^5.0.16",
"@heroicons/react": "^2.0.18",
"@hookform/resolvers": "^3.3.2",
"@internationalized/date": "^3.5.2",
"@lezer/highlight": "^1.2.0",
"@mdx-js/loader": "^3.0.0",
"@mdx-js/mdx": "^2.3.0",
Expand Down Expand Up @@ -115,6 +116,7 @@
"codemirror": "^6.0.1",
"crypto": "^1.0.1",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.1",
"dotenv-flow": "^4.1.0",
"drizzle-orm": "0.30.2",
"formik": "2.2.9",
Expand Down Expand Up @@ -148,13 +150,15 @@
"prism-react-renderer": "^2.2.0",
"query-string": "^9.0.0",
"react": "18.3.1",
"react-aria": "^3.32.1",
"react-dom": "18.3.1",
"react-gravatar": "^2.6.3",
"react-hook-form": "^7.48.0",
"react-hot-toast": "^2.4.1",
"react-icons": "^4.11.0",
"react-markdown": "^9.0.0",
"react-resizable-panels": "^2.0.12",
"react-stately": "^3.30.1",
"react-wrap-balancer": "^0.2.4",
"rehype-raw": "^6.1.1",
"rehype-slug": "^5.1.0",
Expand Down
2 changes: 0 additions & 2 deletions apps/pro-aws/src/ability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ export function defineRulesForPurchases(
can('read', 'Content')
}

console.log({ rules })

return rules
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ async function getChargeDetails(merchantChargeId: string) {
? await getProduct(purchase?.productId)
: null

console.log({ charge, product, bulkCoupon, purchase, merchantSession })

if (product && charge && purchase) {
return {
state: 'SUCCESS' as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function ProductPricing({
purchasedProductIds: string[]
hasPurchasedCurrentProduct?: boolean
}) {
console.log({ product, quantityAvailable, commerceProps, pricingDataLoader })
return (
<>
{product && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,13 @@ function EditProductFormDesktop({
}) {
const onSubmit = async (values: z.infer<typeof resourceSchema>) => {
const updatedResource = await updateResource(values)
console.log({ updatedResource })
if (updatedResource) {
onSave(updatedResource)
}
}

const onArchive = async (values: z.infer<typeof resourceSchema>) => {
const updatedResource = await archiveProduct(values)
console.log({ updatedResource })
if (updatedResource) {
onSave(updatedResource)
}
Expand Down
17 changes: 0 additions & 17 deletions apps/pro-aws/src/app/(commerce)/products/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ async function ProductCommerce({
const { session, ability } = await getServerAuthSession()
const user = session?.user
const product = await productLoader
console.log({ product })
if (!product) return null
const pricingDataLoader = getPricingData(product?.id)
let productProps: any
Expand Down Expand Up @@ -143,8 +142,6 @@ async function ProductCommerce({
commerceProps,
}

console.log({ baseProps })

productProps = baseProps

if (user && purchaseForProduct) {
Expand All @@ -154,18 +151,6 @@ async function ProductCommerce({
user.id,
)

console.log({ purchase, existingPurchase })
console.log('🎈', {
...baseProps,
hasPurchasedCurrentProduct: Boolean(purchase),
...(Boolean(existingPurchase)
? {
purchasedProductIds: [existingPurchase?.productId, '72', 69],
existingPurchase: existingPurchase,
}
: {}),
})

productProps = {
...baseProps,
hasPurchasedCurrentProduct: Boolean(purchase),
Expand All @@ -178,8 +163,6 @@ async function ProductCommerce({
}
}

console.log({ productProps })

return (
<Suspense>
<ProductPricing {...productProps} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ export function CreateProductForm({
}
}

console.log(form.formState.isValid, form.formState.errors)

return (
<Form {...form}>
<form
Expand All @@ -57,7 +55,6 @@ export function CreateProductForm({
control={form.control}
name="name"
render={({ field, fieldState }) => {
console.log('name', { fieldState })
return (
<FormItem>
<FormLabel className="text-lg font-bold">Name</FormLabel>
Expand All @@ -77,7 +74,6 @@ export function CreateProductForm({
control={form.control}
name="quantityAvailable"
render={({ field, fieldState }) => {
console.log('quantityAvailable', { fieldState })
return (
<FormItem>
<FormLabel className="text-lg font-bold">
Expand All @@ -98,7 +94,6 @@ export function CreateProductForm({
control={form.control}
name="price"
render={({ field, fieldState }) => {
console.log('price', { fieldState })
return (
<FormItem>
<FormLabel className="text-lg font-bold">Price</FormLabel>
Expand Down
2 changes: 0 additions & 2 deletions apps/pro-aws/src/app/(commerce)/products/new/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export const dynamic = 'force-dynamic'
export default async function NewEventPage() {
const { ability } = await getServerAuthSession()

console.log({ ability })

if (!ability.can('create', 'Content')) {
notFound()
}
Expand Down
4 changes: 3 additions & 1 deletion apps/pro-aws/src/app/(commerce)/products/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react'
import Link from 'next/link'
import { db } from '@/db'
import { getServerAuthSession } from '@/server/auth'
import { and } from 'drizzle-orm'

import {
Button,
Expand All @@ -14,7 +15,8 @@ import {
export default async function EventIndexPage() {
const { ability } = await getServerAuthSession()
const products = await db.query.products.findMany({
where: (products, { eq }) => eq(products.status, 1),
where: (products, { eq, and }) =>
and(eq(products.status, 1), eq(products.type, 'self-paced')),
})

return (
Expand Down
14 changes: 0 additions & 14 deletions apps/pro-aws/src/app/(commerce)/thanks/purchase/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const getServerSideProps = async (session_id: string) => {
courseBuilderAdapter,
)

console.log({ purchaseInfo })

const {
email,
chargeIdentifier,
Expand Down Expand Up @@ -106,16 +104,6 @@ export default async function ThanksPurchasePage({
stripeProductName,
} = await getServerSideProps(session_id)

console.log({
purchase,
email,
seatsPurchased,
purchaseType,
bulkCouponId,
product,
stripeProductName,
})

return (
<ThanksVerify
email={email}
Expand Down Expand Up @@ -158,8 +146,6 @@ const ThanksVerify: React.FC<
/>
)

console.log({ purchase })

switch (purchaseType) {
case NEW_INDIVIDUAL_PURCHASE:
loginLink = LoginLink
Expand Down
20 changes: 0 additions & 20 deletions apps/pro-aws/src/app/(commerce)/welcome/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const getServerSideProps = async (query: {
}
})

console.log({ providers })

let purchaseId = query.purchaseId

const session_id = query.session_id
Expand All @@ -57,14 +55,10 @@ const getServerSideProps = async (query: {
}
}

console.log({ user, purchaseId })

if (user && isString(purchaseId) && isString(user?.id)) {
const { purchase, existingPurchase, availableUpgrades } =
await courseBuilderAdapter.getPurchaseDetails(purchaseId, user?.id)

console.log({ purchase, existingPurchase, availableUpgrades })

if (purchase) {
const product = await courseBuilderAdapter.getProduct(purchase.productId)

Expand Down Expand Up @@ -124,20 +118,6 @@ const Welcome = async ({

const isGithubConnected = await githubAccountsForCurrentUser()

console.log({
isGithubConnected,
product,
purchase,
existingPurchase,
upgrade,
providers,
hasCharge,
redemptionsLeft,
isTransferAvailable,
purchaseUserTransfers,
userEmail: session?.user?.email,
})

return (
<div>
<WelcomePage
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as React from 'react'
import { Event } from '@/lib/events'
import { formatInTimeZone } from 'date-fns-tz'

export const EventDetails: React.FC<{
event: Event
}> = ({ event }) => {
const { startsAt, endsAt, timezone } = event.fields
const PT = 'America/Los_Angeles'
const eventDate =
startsAt && `${formatInTimeZone(new Date(startsAt), PT, 'MMMM d, yyyy')}`

const eventTime =
startsAt &&
endsAt &&
`${formatInTimeZone(new Date(startsAt), PT, 'h:mm a')}${formatInTimeZone(
new Date(endsAt),
PT,
'h:mm a',
)}`

interface GroupedEvents {
[title: string]: {
dates: string[]
time: string
}
}

return (
<div className="mt-5 flex flex-col border-t pt-5">
<h2 className="px-5 pb-4 text-xl font-semibold">Event Details</h2>

<div className="flex flex-col text-base font-semibold opacity-90">
<div className="flex items-center gap-2 px-5 py-2">
{/*<CalendarIcon className="h-5 w-5 flex-shrink-0 text-gray-600 dark:text-blue-300" />{' '}*/}
{eventDate}
</div>
<div className="flex items-baseline gap-2 px-5 py-2">
{/*<ClockIcon className="relative h-5 w-5 flex-shrink-0 translate-y-1 text-gray-600 dark:text-blue-300" />{' '}*/}
<div>
{eventTime} (Pacific time){' '}
{timezone && (
<a
href={timezone}
rel="noopener noreferrer"
target="_blank"
className="font-normal underline"
>
timezones
</a>
)}
</div>
</div>
<div className="flex items-center gap-2 px-5 py-2">
{/*<LocationMarkerIcon className="h-5 w-5 text-gray-600 dark:text-blue-300" />{' '}*/}
Zoom (online remote)
</div>
</div>
</div>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Event } from '@/lib/events'
import { PricingData } from '@/lib/pricing-query'
import { MDXRemoteSerializeResult } from 'next-mdx-remote'

import { CommerceProps } from '@coursebuilder/commerce-next/utils/commerce-props'
import { Product, Purchase } from '@coursebuilder/core/schemas'

export type EventPageProps = {
event: Event
quantityAvailable: number
totalQuantity: number
purchaseCount: number
product?: Product
mdx?: MDXRemoteSerializeResult
hasPurchasedCurrentProduct?: boolean
availableBonuses: any[]
existingPurchase?: (Purchase & { product?: Product | null }) | null
purchases?: Purchase[]
userId?: string
pricingDataLoader: Promise<PricingData>
} & CommerceProps
Loading

0 comments on commit 2d2be35

Please sign in to comment.