Skip to content

Commit

Permalink
Refatory Spinner
Browse files Browse the repository at this point in the history
  • Loading branch information
clonglam committed Feb 26, 2024
1 parent d136269 commit c0e6800
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 68 deletions.
2 changes: 0 additions & 2 deletions scripts/fetchGraphQLSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ function fetchGraphQLSchema(url, options) {

const filePath = path.join(__dirname, "../graphql/schema/", "schema.graphql")

console.log()

console.log(
supagradient(
`🗞 Fetching GraphQL Schema from ${process.env.SUPABASE_PROJECT_REF} ...`
Expand Down
1 change: 0 additions & 1 deletion src/_actions/authAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const getUser = async ({ userId }: { userId: string }) => {
const { data, error } = await adminAuthClient.getUserById(userId)
return data
} catch (err) {
console.log(err)
throw new Error("There is an error")
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/_actions/products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type SearchProductsActionProps = {

export async function searchProductsAction(data: SearchProductsActionProps) {
const validate = SearchProductActionSchema.safeParse(data)
console.log("valu", validate)
if (!validate.success) throw new Error("Invalid input.")

const { query, sort, limit = 15 } = data
Expand Down Expand Up @@ -77,7 +76,6 @@ export async function searchProductsAction(data: SearchProductsActionProps) {
}
}
export const createProductAction = async (product: InsertProducts) => {
console.log("product", product)
createInsertSchema(products).parse(product)
const data = await db.insert(products).values(product).returning()
return data
Expand All @@ -94,7 +92,6 @@ export const updateProductAction = async (
.where(eq(products.id, productId))
.returning()

console.log("insertedProduct", insertedProduct)
return insertedProduct
}

Expand Down
1 change: 0 additions & 1 deletion src/app/(admin)/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ type AdminUsersPageProps = {

async function UsersPage({ searchParams }: AdminUsersPageProps) {
const currentUser = await getCurrentUser()
if (currentUser.role !== "ADMIN") console.log("you are not admin.")

const users = await listUsers({})

Expand Down
5 changes: 3 additions & 2 deletions src/app/(admin)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ type Props = { children: ReactNode }
async function AdminLayout({ children }: Props) {
const currentUser = await getCurrentUser()

if (!currentUser || currentUser.role !== "ADMIN") redirect(`/sign-in`)
// TODO: Attach the error at the end of the url
if (!currentUser || currentUser.role !== "ADMIN")
redirect(`/sign-in?error=Only authenticated users can access`)
// TODO: confirm can This error message displaty
return (
<main>
<Navbar adminLayout={true} />
Expand Down
1 change: 0 additions & 1 deletion src/app/(store)/orders/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ async function OrderPage() {
userId: user.id,
})

console.log("error", error)
if (!data) return notFound()

return (
Expand Down
1 change: 0 additions & 1 deletion src/app/api/create-checkout-session/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ export async function POST(request: Request) {

return NextResponse.json({ sessionId: session.id })
} catch (err) {
console.log("err", err)
return new NextResponse("Internal Error", { status: 500 })
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/app/api/medias/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,22 @@ export async function POST(request: NextRequest) {
Body: Buffer.from(await file.arrayBuffer()),
ContentType: file.type,
}
console.log("params.Key", params.Key)
try {
const s3Response = await uploadImage(params)
if (s3Response) {
const insertedMedia = await db
.insert(medias)
.values({ alt: file.name, key: params.Key })
.returning()
console.log("insertedMedia", insertedMedia)
return { index, medias: insertedMedia }
}
return null
} catch (err) {
console.log("error", err)
return null
}
})
)

console.log("uploadResponse", uploadResponse)

return NextResponse.json(uploadResponse, { status: 201 })
}

Expand Down
10 changes: 2 additions & 8 deletions src/app/api/webhook/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { env } from "@/env.mjs"
import { stripe } from "@/lib/stripe"
import db from "@/lib/supabase/db"
import { InsertOrders, PaymentStatus, orders } from "@/lib/supabase/schema"
import { PaymentStatus, address, orders } from "@/lib/supabase/schema"
import { eq } from "drizzle-orm"
import { headers } from "next/headers"
import { NextRequest, NextResponse } from "next/server"
import Stripe from "stripe"
import { address } from "@/lib/supabase/schema"
import { eq } from "drizzle-orm"

const relevantEvents = new Set([
"product.created",
Expand Down Expand Up @@ -72,8 +71,6 @@ export async function POST(request: NextRequest) {
})
.where(eq(orders.id, checkoutSession.client_reference_id))
.returning()

console.log("insertedOrder", updatedOrder)
} else {
const insertedOrder = await db
.update(orders)
Expand All @@ -85,12 +82,9 @@ export async function POST(request: NextRequest) {
})
.where(eq(orders.id, checkoutSession.client_reference_id))
.returning()

console.log("insertedOrder", insertedOrder)
}
break
default:
console.log("")
throw new Error("Unhandled relevant event!")
}
} catch (error) {
Expand Down
5 changes: 0 additions & 5 deletions src/components/admin/media/FeaturedImageField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const FeaturedImageField: FC<{
fetch(`/medias/${defaultValue}`)
.then((res) => res.json())
.then((data) => {
console.log("PreviewfileUrl", data)
setPreviewUrl(data.preview)
})
.catch((err) => {
Expand All @@ -29,8 +28,6 @@ export const FeaturedImageField: FC<{

const onDrop = useCallback(
async (acceptedFiles: FileWithPath[]) => {
console.log("acceptedFiles", acceptedFiles)

if (acceptedFiles.length > 0) {
const id = nanoid()
const formData = new FormData()
Expand All @@ -46,8 +43,6 @@ export const FeaturedImageField: FC<{
data: { imageUrl: string; featuredId: string }
preview: string
}

console.log("json", json)
setValue(name, json.data.featuredId)
setPreviewUrl(json.preview)
}
Expand Down
8 changes: 3 additions & 5 deletions src/components/admin/media/ImageDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function ImageDialog({
}

const onDrop = async (acceptedFiles: FileWithPath[]) => {
console.log("Recieved data", acceptedFiles)
// console.log("Recieved data", acceptedFiles)

const uploadFiles = acceptedFiles.map((file) =>
Object.assign(file, {
Expand All @@ -79,7 +79,7 @@ function ImageDialog({
media: SelectMedia
}[]

console.log("CLient Recieved Data", data)
// console.log("CLient Recieved Data", data)
if (data) {
// setUploadedFilesUrls(data.uploadedFilesUrls)
}
Expand Down Expand Up @@ -109,9 +109,7 @@ function ImageDialog({
{value ? (
<ImagePreviewCard
key={value}
onClick={() => {
console.log("")
}}
onClick={() => {}}
mediaId={value}
/>
) : (
Expand Down
3 changes: 2 additions & 1 deletion src/components/admin/media/UpdateMediaForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
import Spinner from "@/components/ui/spinner"

type UpdateMediaFormProps = {
media?: SelectMedia
Expand Down Expand Up @@ -161,7 +162,7 @@ function UpdateMediaForm({ media }: UpdateMediaFormProps) {
<Button disabled={isPending} variant={"outline"} form="project-form">
{media ? "Update" : "Create"}
{isPending && (
<Icons.spinner
<Spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/products/ProductForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import ImageDialog from "@/components/admin/media/ImageDialog"
import { createProductAction, updateProductAction } from "@/_actions/products"
import { useToast } from "@/components/ui/use-toast"
import { useRouter } from "next/navigation"
import Spinner from "@/components/ui/spinner"

type ProductsFormProps = {
product?: SelectProducts
Expand Down Expand Up @@ -79,7 +80,6 @@ function ProductFrom({ product }: ProductsFormProps) {
} catch (err) {
console.log("err", err)
console.log("unexpected Error Occured")
toast
}
})
})
Expand Down Expand Up @@ -242,7 +242,7 @@ function ProductFrom({ product }: ProductsFormProps) {
<Button disabled={isPending} variant={"outline"} form="project-form">
{product ? "Update" : "Create"}
{isPending && (
<Icons.spinner
<Spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
Expand Down
5 changes: 2 additions & 3 deletions src/components/admin/users/AdminUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import { Input } from "@/components/ui/input"

import { createUser } from "@/_actions/authAdmin"
import { PasswordInput } from "@/components/auth/PasswordInput"
import { Icons } from "@/components/icons"
import Spinner from "@/components/ui/spinner"
import { useToast } from "@/components/ui/use-toast"
import { createClient } from "@/lib/supabase/client"
import { SelectUserProfiles } from "@/lib/supabase/schema"
import { useRouter } from "next/navigation"
import { AdminUserFormData, adminUserShcema } from "./adminUserShema"
Expand Down Expand Up @@ -135,7 +134,7 @@ function AdminUserForm({ user }: AdminUserFormProps) {
<Button disabled={isPending} variant={"outline"} form="project-form">
{user ? "Update" : "Create"}
{isPending && (
<Icons.spinner
<Spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
Expand Down
4 changes: 2 additions & 2 deletions src/components/admin/users/UpdateUserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Button, buttonVariants } from "@/components/ui/button"
import { Input } from "@/components/ui/input"

import { PasswordInput } from "@/components/auth/PasswordInput"
import { Icons } from "@/components/icons"
import Spinner from "@/components/ui/spinner"
import { useToast } from "@/components/ui/use-toast"
import { User } from "@supabase/supabase-js"
import { useRouter } from "next/navigation"
Expand Down Expand Up @@ -132,7 +132,7 @@ function UpdateUserForm({ user }: AdminUserFormProps) {
<Button disabled={isPending} variant={"outline"} form="project-form">
{user ? "Update" : "Create"}
{isPending && (
<Icons.spinner
<Spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
Expand Down
21 changes: 7 additions & 14 deletions src/components/auth/OAuthLoginButtons.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
"use client"
import React, { useState } from "react"
import { Button } from "../ui/button"
import { Icons } from "../icons"
import { createClient } from "@/lib/supabase/client"
import { useRouter } from "next/navigation"
import { useAuth } from "@/lib/providers/AuthProvider"
import { getURL } from "@/lib/utils"
import { useRouter } from "next/navigation"
import { useState } from "react"
import { Icons } from "../icons"
import { Button } from "../ui/button"
import Spinner from "../ui/spinner"

function OAuthLoginButtons() {
const [isLoading, setIsLoading] = useState(false)
const supabase = createClient()
const router = useRouter()
const user = useAuth()

const signWithGoogle = async () => {
setIsLoading(true)
Expand Down Expand Up @@ -46,21 +45,15 @@ function OAuthLoginButtons() {
<div className="flex flex-col space-y-3">
<Button onClick={signWithGoogle} disabled={isLoading}>
{isLoading && (
<Icons.spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
<Spinner className="mr-2 h-4 w-4 animate-spin" aria-hidden="true" />
)}
<Icons.google className="w-4 h-4 mr-5" />
Sign in with Google
</Button>

<Button onClick={signWithGithub} disabled={isLoading}>
{isLoading && (
<Icons.spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
<Spinner className="mr-2 h-4 w-4 animate-spin" aria-hidden="true" />
)}
<Icons.gitHub className="w-4 h-4 mr-5" />
Sign in with Github
Expand Down
6 changes: 2 additions & 4 deletions src/components/auth/SigninForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { createClient } from "@/lib/supabase/client"
import { PasswordInput } from "./PasswordInput"
import { authSchema } from "./schema"
import { useToast } from "../ui/use-toast"
import Spinner from "../ui/spinner"

type Inputs = z.infer<typeof authSchema>

Expand Down Expand Up @@ -89,10 +90,7 @@ export function SignInForm() {
/>
<Button disabled={isPending}>
{isPending && (
<Icons.spinner
className="mr-2 h-4 w-4 animate-spin"
aria-hidden="true"
/>
<Spinner className="mr-2 h-4 w-4 animate-spin" aria-hidden="true" />
)}
Sign in
<span className="sr-only">Sign in</span>
Expand Down
1 change: 0 additions & 1 deletion src/components/cart/AddToCartButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const UserCartButton = ({
userId: user.id,
newQuantity: existedProduct.node.quantity + 1,
})
console.log("updated cart", res)
if (res) toast({ title: "Sucess, Added a Product to the Cart." })
}
} catch (err) {
Expand Down
Loading

0 comments on commit c0e6800

Please sign in to comment.