Skip to content

Commit

Permalink
feat: move invoices to membership layout (#1495)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacjones93 authored Dec 4, 2024
1 parent c7c2b26 commit 4cf0bfc
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 31 deletions.
19 changes: 19 additions & 0 deletions src/app/user/membership/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Invoices from '@/components/invoices'

export default async function MembershipPageLayout({
children,
}: {
children: React.ReactNode
}) {
return (
<div className="w-full">
<h2 className="pb-3 md:pb-4 text-lg font-medium md:font-normal md:text-xl leading-none">
Membership
</h2>
<div className="min-h-[200px] flex justify-center items-center">
{children}
</div>
<Invoices headingAs="h3" />
</div>
)
}
13 changes: 4 additions & 9 deletions src/app/user/membership/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,10 @@ const Membership = () => {
)
case hasStripeAccount:
return (
<div className="w-full">
<ItemWrapper title="Membership">
<SubscriptionDetails
stripeCustomerId={account.stripe_customer_id}
slug={account.slug}
/>
</ItemWrapper>
<Invoices headingAs="h3" />
</div>
<SubscriptionDetails
stripeCustomerId={account.stripe_customer_id}
slug={account.slug}
/>
)
case isTeamMember:
return (
Expand Down
26 changes: 7 additions & 19 deletions src/components/invoices/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client'

import * as React from 'react'
import axios from '@/utils/configured-axios'
import {isEmpty} from 'lodash'
import {format, parseISO} from 'date-fns'
import {trpc} from '@/app/_trpc/client'

type HeadingProps = React.ComponentPropsWithoutRef<any> & {
headingAs?: 'h1' | 'h2' | 'h3' | 'h4' | 'p'
Expand All @@ -10,31 +11,18 @@ type HeadingProps = React.ComponentPropsWithoutRef<any> & {
const Invoices: React.FunctionComponent<
React.PropsWithChildren<HeadingProps>
> = ({headingAs}) => {
const [transactions, setTransactions] = React.useState([])
const [transactionsLoading, setTransactionsLoading] = React.useState(true)
const {data: transactions, status} =
trpc.user.transactionsForCurrent.useQuery()

const Heading = headingAs ?? 'p'

React.useEffect(() => {
axios
.get(`${process.env.NEXT_PUBLIC_AUTH_DOMAIN}/api/v1/transactions`)
.then(({data}) => {
setTransactionsLoading(false)
setTransactions(data)
})
}, [])

return (
<main className="mt-16">
{transactionsLoading ? (
{status === 'loading' ? (
<div></div>
) : (
<div>
{isEmpty(transactions) ? (
<Heading className="text-lg font-medium md:font-normal md:text-xl leading-none">
No Transactions
</Heading>
) : (
{!transactions ? null : (
<div className="flex flex-col space-y-8">
<Heading className="text-lg font-medium md:font-normal md:text-xl leading-none">
Transactions
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/user/components/subscription-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const SubscriptionDetails: React.FunctionComponent<
}

return (
<div className="w-full">
<div>
{subscriptionName ? (
<div className="md:w-[75ch] mx-auto">
<div className="w-full leading-relaxed mt-4 text-center space-y-4">
Expand All @@ -228,7 +228,7 @@ const SubscriptionDetails: React.FunctionComponent<
</div>
</div>
) : (
<div className="w-full">
<div>
{(viewer.is_pro || viewer.is_instructor) && (
<p>
You still have access to a Pro Membership. If you feel this is in
Expand Down
4 changes: 3 additions & 1 deletion src/pages/invoices/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ const InvoicesPage: React.FunctionComponent<
> = () => {
return (
<LoginRequired>
<Invoices headingAs="h1" />
<div className="min-h-[75vh] mx-auto">
<Invoices headingAs="h1" />
</div>
</LoginRequired>
)
}
Expand Down
5 changes: 5 additions & 0 deletions src/server/routers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export const userRouter = router({
},
).then((res) => res.json())) || []

if (transactions?.error) {
console.error('error fetching transactions: ', transactions.error)
return null
}

return transactionsSchema.parse(transactions)
}),
accountsForCurrent: baseProcedure.query(async ({input, ctx}) => {
Expand Down

0 comments on commit 4cf0bfc

Please sign in to comment.