-
Notifications
You must be signed in to change notification settings - Fork 619
[Dashboard] Feature: Add account settings page with Name and Email fields #5461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
graphite-app
merged 1 commit into
main
from
11-20-add_account_settings_page_with_name_and_email_fields
Nov 20, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,39 @@ | ||
| "use server"; | ||
|
|
||
| import { getAuthToken } from "../../app/api/lib/getAuthToken"; | ||
| import { API_SERVER_URL } from "../constants/env"; | ||
|
|
||
| export async function confirmEmailWithOTP(otp: string) { | ||
| const token = await getAuthToken(); | ||
|
|
||
| if (!token) { | ||
| return { | ||
| errorMessage: "You are not authorized to perform this action", | ||
| }; | ||
| } | ||
|
|
||
| const res = await fetch(`${API_SERVER_URL}/v1/account/confirmEmail`, { | ||
| method: "PUT", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| body: JSON.stringify({ | ||
| confirmationToken: otp, | ||
| }), | ||
| }); | ||
|
|
||
| if (!res.ok) { | ||
| const json = await res.json(); | ||
|
|
||
| if (json.error) { | ||
| return { | ||
| errorMessage: json.error.message, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| errorMessage: "Failed to confirm email", | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,37 @@ | ||
| "use server"; | ||
| import { getAuthToken } from "../../app/api/lib/getAuthToken"; | ||
| import { API_SERVER_URL } from "../constants/env"; | ||
|
|
||
| export async function updateAccount(values: { | ||
| name?: string; | ||
| email?: string; | ||
| }) { | ||
| const token = await getAuthToken(); | ||
|
|
||
| if (!token) { | ||
| throw new Error("No Auth token"); | ||
| } | ||
|
|
||
| const res = await fetch(`${API_SERVER_URL}/v1/account`, { | ||
| method: "PUT", | ||
| headers: { | ||
| "Content-Type": "application/json", | ||
| Authorization: `Bearer ${token}`, | ||
| }, | ||
| body: JSON.stringify(values), | ||
| }); | ||
|
|
||
| if (!res.ok) { | ||
| const json = await res.json(); | ||
|
|
||
| if (json.error) { | ||
| return { | ||
| errorMessage: json.error.message, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| errorMessage: "Failed To Update Account", | ||
| }; | ||
| } | ||
| } |
This file contains hidden or 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
61 changes: 41 additions & 20 deletions
61
apps/dashboard/src/app/account/settings/AccountSettingsPage.tsx
This file contains hidden or 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,35 +1,56 @@ | ||
| "use client"; | ||
|
|
||
| import { confirmEmailWithOTP } from "@/actions/confirmEmail"; | ||
| import { updateAccount } from "@/actions/updateAccount"; | ||
| import { useDashboardRouter } from "@/lib/DashboardRouter"; | ||
| import type { Account } from "@3rdweb-sdk/react/hooks/useApi"; | ||
| import type { ThirdwebClient } from "thirdweb"; | ||
| import { upload } from "thirdweb/storage"; | ||
| import { AccountSettingsPageUI } from "./AccountSettingsPageUI"; | ||
|
|
||
| export function AccountSettingsPage(props: { | ||
| account: Account; | ||
| client: ThirdwebClient; | ||
| }) { | ||
| const router = useDashboardRouter(); | ||
| return ( | ||
| <div> | ||
| <AccountSettingsPageUI | ||
| account={props.account} | ||
| updateAccountImage={async (file) => { | ||
| if (file) { | ||
| // upload to IPFS | ||
| const ipfsUri = await upload({ | ||
| client: props.client, | ||
| files: [file], | ||
| }); | ||
|
|
||
| // TODO - Implement updating the account image with uri | ||
| console.log(ipfsUri); | ||
| } else { | ||
| // TODO - Implement deleting the account image | ||
| } | ||
|
|
||
| throw new Error("Not implemented"); | ||
| }} | ||
| /> | ||
| <div className="border-border border-b py-10"> | ||
| <div className="container max-w-[950px]"> | ||
| <h1 className="font-semibold text-3xl tracking-tight"> | ||
| Account Settings | ||
| </h1> | ||
| </div> | ||
| </div> | ||
| <div className="container max-w-[950px] grow pt-8 pb-20"> | ||
| <AccountSettingsPageUI | ||
| // TODO - remove hide props these when these fields are functional | ||
| hideAvatar | ||
| hideDeleteAccount | ||
| account={props.account} | ||
| updateEmailWithOTP={async (otp) => { | ||
| const res = await confirmEmailWithOTP(otp); | ||
| if (res?.errorMessage) { | ||
| throw new Error(res.errorMessage); | ||
| } | ||
| router.refresh(); | ||
| }} | ||
| updateName={async (name) => { | ||
| const res = await updateAccount({ name }); | ||
| if (res?.errorMessage) { | ||
| throw new Error(res.errorMessage); | ||
| } | ||
| router.refresh(); | ||
| }} | ||
| // yes, this is weird - | ||
| // to send OTP to email, we use updateAccount | ||
| sendEmail={async (email) => { | ||
| const res = await updateAccount({ email }); | ||
| if (res?.errorMessage) { | ||
| throw new Error(res.errorMessage); | ||
| } | ||
| }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.