Skip to content

Commit

Permalink
feat: better schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sadmann7 committed May 26, 2024
1 parent dee9435 commit d335bca
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 21 deletions.
13 changes: 11 additions & 2 deletions src/app/(dashboard)/onboarding/_components/connect-stripe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react"
import { useRouter } from "next/navigation"
import { motion } from "framer-motion"

import { Button } from "@/components/ui/button"
import { ConnectStoreToStripeButton } from "@/components/connect-store-to-stripe-button"

interface ConnectStripeProps {
Expand Down Expand Up @@ -48,10 +49,11 @@ export function ConnectStripe({ storeId }: ConnectStripeProps) {
},
}}
>
Now connect your store to Stripe
Now let's connect your store to Stripe
</motion.h1>
{storeId && (
<motion.div
className="flex flex-col-reverse gap-2 pt-2.5 sm:flex-row sm:justify-end"
variants={{
hidden: { opacity: 0, x: 100 },
show: {
Expand All @@ -61,7 +63,14 @@ export function ConnectStripe({ storeId }: ConnectStripeProps) {
},
}}
>
<ConnectStoreToStripeButton storeId={storeId} />
<ConnectStoreToStripeButton storeId={storeId} className="w-full" />
<Button
variant="outline"
onClick={() => router.push(`/store/${storeId}`)}
className="w-full"
>
Skip for now
</Button>
</motion.div>
)}
</motion.div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ export function CreateStoreForm({
<FormItem>
<FormLabel>Name</FormLabel>
<FormControl>
<Input placeholder="Type store name here." {...field} />
<Input
placeholder="Type store name here."
autoFocus
{...field}
/>
</FormControl>
<FormMessage />
</FormItem>
Expand Down
9 changes: 7 additions & 2 deletions src/components/connect-store-to-stripe-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,25 @@ import * as React from "react"
import { toast } from "sonner"

import { createAccountLink } from "@/lib/actions/stripe"
import { Button } from "@/components/ui/button"
import { cn } from "@/lib/utils"
import { Button, type ButtonProps } from "@/components/ui/button"
import { Icons } from "@/components/icons"

interface ConnectToStripeButtonProps {
interface ConnectToStripeButtonProps extends ButtonProps {
storeId: string
}

export function ConnectStoreToStripeButton({
storeId,
className,
...props
}: ConnectToStripeButtonProps) {
const [loading, setLoading] = React.useState(false)

return (
<Button
aria-label="Connect to Stripe"
className={cn(className)}
onClick={async () => {
setLoading(true)

Expand All @@ -38,6 +42,7 @@ export function ConnectStoreToStripeButton({
}
}}
disabled={loading}
{...props}
>
{loading && (
<Icons.spinner
Expand Down
4 changes: 2 additions & 2 deletions src/db/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export * from "./notifications"
export * from "./orders"
export * from "./payments"
export * from "./products"
export * from "./stores"
export * from "./stocks"
export * from "./stores"
export * from "./subcategories"
export * from "./tags"
// export * from "./variants"
export * from "./variants"
4 changes: 2 additions & 2 deletions src/db/schema/stocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const stocks = pgTable(
.$defaultFn(() => generateId())
.primaryKey(),
productVariantId: varchar("product_variant_id", { length: 30 })
.references(() => productVariants.variantId, { onDelete: "cascade" })
.references(() => productVariants.id, { onDelete: "cascade" })
.notNull(),
quantity: integer("quantity").notNull().default(0),
...lifecycleDates,
Expand All @@ -28,7 +28,7 @@ export const stocks = pgTable(
export const stocksRelations = relations(stocks, ({ one }) => ({
productVariant: one(productVariants, {
fields: [stocks.productVariantId],
references: [productVariants.variantId],
references: [productVariants.id],
}),
productVariantValues: one(productVariantValues, {
fields: [stocks.productVariantId],
Expand Down
9 changes: 4 additions & 5 deletions src/db/schema/variants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export type NewVariant = typeof variants.$inferInsert
export const productVariants = pgTable(
"product_variants",
{
id: varchar("id", { length: 30 })
.$defaultFn(() => generateId())
.primaryKey(),
productId: varchar("product_id", { length: 30 })
.references(() => products.id, { onDelete: "cascade" })
.notNull(),
Expand All @@ -56,10 +59,6 @@ export const productVariants = pgTable(
...lifecycleDates,
},
(table) => ({
pk: primaryKey({
name: "product_variants_pk",
columns: [table.productId, table.variantId],
}),
productIdIdx: index("product_variants_product_id_idx").on(table.productId),
variantIdIdx: index("product_variants_variant_id_idx").on(table.variantId),
})
Expand Down Expand Up @@ -87,7 +86,7 @@ export const productVariantValues = pgTable(
"product_variant_values",
{
productVariantId: varchar("product_variant_id", { length: 30 })
.references(() => productVariants.productId, { onDelete: "cascade" })
.references(() => productVariants.id, { onDelete: "cascade" })
.notNull(),
value: text("value").notNull(),
price: decimal("price", { precision: 10, scale: 2 }).notNull(),
Expand Down
7 changes: 0 additions & 7 deletions src/lib/actions/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
type Product,
type Subcategory,
} from "@/db/schema"
import { auth } from "@clerk/nextjs/server"
import { faker } from "@faker-js/faker"
import { eq } from "drizzle-orm"

Expand Down Expand Up @@ -70,12 +69,6 @@ export async function seedProducts({
storeId: string
count?: number
}) {
const { userId } = auth()

if (!userId) {
throw new Error("User not found")
}

const productCount = count ?? 10

const data: Product[] = []
Expand Down

0 comments on commit d335bca

Please sign in to comment.