-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #145 from moinulmoin/refactor-codebase
Refactor codebase and ui
- Loading branch information
Showing
25 changed files
with
342 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"use server"; | ||
|
||
import { revalidatePath } from "next/cache"; | ||
import db from "~/lib/db"; | ||
import { getImageKeyFromUrl, isOurCdnUrl } from "~/lib/utils"; | ||
import { utapi } from "~/server/uploadthing"; | ||
import { type payload } from "~/types"; | ||
|
||
export const updateUser = async (id: string, payload: payload) => { | ||
await db.user.update({ | ||
where: { id }, | ||
data: { ...payload }, | ||
}); | ||
|
||
revalidatePath("/dashboard/settings"); | ||
}; | ||
|
||
export async function removeUserOldImageFromCDN( | ||
id: string, | ||
newImageUrl: string | ||
) { | ||
const user = await db.user.findFirst({ | ||
where: { id }, | ||
select: { picture: true }, | ||
}); | ||
|
||
const currentImageUrl = user?.picture; | ||
|
||
if (!currentImageUrl) throw new Error("User Picture Missing"); | ||
|
||
try { | ||
if (isOurCdnUrl(currentImageUrl)) { | ||
const currentImageFileKey = getImageKeyFromUrl(currentImageUrl); | ||
|
||
await utapi.deleteFiles(currentImageFileKey as string); | ||
revalidatePath("/dashboard/settings"); | ||
} | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
const newImageFileKey = getImageKeyFromUrl(newImageUrl); | ||
await utapi.deleteFiles(newImageFileKey as string); | ||
console.error(e.message); | ||
} | ||
} | ||
} | ||
|
||
export async function removeNewImageFromCDN(image: string) { | ||
const imageFileKey = getImageKeyFromUrl(image); | ||
await utapi.deleteFiles(imageFileKey as string); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { type User } from "lucia"; | ||
import { type Metadata } from "next"; | ||
import { getUser } from "~/server/user"; | ||
import { type CurrentUser } from "~/types"; | ||
import { getPageSession } from "~/lib/auth"; | ||
import SettingsForm from "./settings-form"; | ||
|
||
export const metadata: Metadata = { | ||
title: "Settings", | ||
}; | ||
|
||
export default async function Settings() { | ||
const currentUser = (await getUser()) as CurrentUser; | ||
return <SettingsForm currentUser={currentUser} />; | ||
const session = await getPageSession(); | ||
return <SettingsForm currentUser={session?.user as User} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
fe796d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
chadnext – ./
chadnext.vercel.app
chadnext-moinulmoin.vercel.app
chadnext-git-main-moinulmoin.vercel.app
chadnext.moinulmoin.com