-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Changing from react-toast-notifications to react-hot-toast
- Loading branch information
Showing
4 changed files
with
190 additions
and
171 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
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 |
---|---|---|
@@ -1,191 +1,191 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import Head from "next/head"; | ||
import { getSession } from "next-auth/client"; | ||
|
||
import Navbar from "../components/Navbar"; | ||
import Footer from "../components/Footer"; | ||
import { useToasts } from "react-toast-notifications"; | ||
import { Toast, toast } from "react-hot-toast"; | ||
import { SpinnerCircular } from "spinners-react"; | ||
|
||
const Account = ({ session }: any) => { | ||
const [name, setName] = useState(session?.user?.name); | ||
const [username, setUsername] = useState(); | ||
const [bio, setBio] = useState(); | ||
|
||
const { addToast } = useToasts(); | ||
|
||
useEffect(() => { | ||
const get = async () => { | ||
const response = await fetch("/api/get-user"); | ||
const json = await response.json(); | ||
setUsername(json.username ? json.username : ""); | ||
setName(json.name ? json.name : ""); | ||
setBio(json.bio ? json.bio : ""); | ||
}; | ||
|
||
get(); | ||
}, []); | ||
|
||
const handleNameChange = (e: any) => { | ||
setName(e.target.value); | ||
}; | ||
|
||
const handleUsernameChange = (e: any) => { | ||
setUsername(e.target.value); | ||
const [name, setName] = useState(session?.user?.name); | ||
const [username, setUsername] = useState(); | ||
const [bio, setBio] = useState(); | ||
|
||
const [updating, setUpdating] = useState(false); | ||
|
||
useEffect(() => { | ||
const get = async () => { | ||
const response = await fetch("/api/get-user"); | ||
const json = await response.json(); | ||
setUsername(json.username ? json.username : ""); | ||
setName(json.name ? json.name : ""); | ||
setBio(json.bio ? json.bio : ""); | ||
}; | ||
|
||
const handleBioChange = (e: any) => { | ||
setBio(e.target.value); | ||
}; | ||
get(); | ||
}, []); | ||
|
||
const handleSubmit = async (e: any) => { | ||
e.preventDefault(); | ||
console.log(e); | ||
const handleNameChange = (e: any) => { | ||
setName(e.target.value); | ||
}; | ||
|
||
const response = await fetch("/api/update-user", { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
method: "POST", | ||
body: JSON.stringify({ | ||
username: username, | ||
name: name, | ||
bio: bio | ||
}), | ||
}); | ||
const handleUsernameChange = (e: any) => { | ||
setUsername(e.target.value); | ||
}; | ||
|
||
if (response.ok) { | ||
addToast('success', { | ||
appearance: 'success', | ||
autoDismiss: true | ||
}) | ||
} | ||
const handleBioChange = (e: any) => { | ||
setBio(e.target.value); | ||
}; | ||
|
||
const json = await response.json(); | ||
console.log(json); | ||
}; | ||
const handleSubmit = async (e: any) => { | ||
e.preventDefault(); | ||
setUpdating(true); | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>My Account | Crystal</title> | ||
</Head> | ||
<Navbar /> | ||
<main className="flex flex-col p-8"> | ||
<header className="flex items-center justify-between"> | ||
<h1 className="text-4xl md:text-8xl lg:text-9xl tracking-tighter font-bold text-black py-5"> | ||
My Account | ||
</h1> | ||
</header> | ||
<hr className="border-1 border-gray-300" /> | ||
<div | ||
className="flex justify-start gap-8 items-center mt-8 profile-picture p-4 bg-cover" | ||
style={{ | ||
backgroundImage: | ||
'url("https://source.unsplash.com/collection/94997000/)', | ||
}} | ||
> | ||
<img | ||
src={session ? session?.user?.image : ""} | ||
className="ml-4 w-40 rounded-full border-4 border-white shadow-2xl" | ||
alt="" | ||
/> | ||
<h1 className="text-8xl font-bold text-white py-2 px-4 bg-black bg-opacity-50 rounded-lg"> | ||
{name} | ||
</h1> | ||
</div> | ||
<form onSubmit={handleSubmit}> | ||
<div className="account-information mt-8 flex justify-center items-start gap-8 flex-col max-w-4xl"> | ||
<div className="username w-full"> | ||
<div className="username-input flex justify-start items-center gap-8 w-full"> | ||
<h1 className="font-bold text-4xl tracking-tighter"> | ||
Username | ||
</h1> | ||
<input | ||
value={username} | ||
onChange={handleUsernameChange} | ||
type="text" | ||
name="username" | ||
className="w-full p-1 font-light text-xl border-2 border-gray-200 rounded-lg" | ||
placeholder="Username..." | ||
/> | ||
</div> | ||
<label | ||
htmlFor="username" | ||
className="max-w-xl text-gray-500" | ||
> | ||
Your username is the unique identifier for your | ||
account. Give people your username so they can | ||
follow you! | ||
</label> | ||
</div> | ||
<div className="name w-full"> | ||
<div className="name-input flex justify-start items-center gap-8 w-full"> | ||
<h1 className="font-bold text-4xl tracking-tighter"> | ||
Name | ||
</h1> | ||
<input | ||
value={name} | ||
onChange={handleNameChange} | ||
type="text" | ||
name="name" | ||
className="w-full p-1 font-light text-xl border-2 border-gray-200 rounded-lg" | ||
placeholder="Name..." | ||
/> | ||
</div> | ||
<label | ||
htmlFor="name" | ||
className="max-w-xl text-gray-500" | ||
> | ||
Your name will appear in your profile. | ||
</label> | ||
</div> | ||
<div className="bio w-full"> | ||
<div className="bio-input flex justify-start items-start gap-8 w-full"> | ||
<h1 className="font-bold text-4xl tracking-tighter"> | ||
Bio | ||
</h1> | ||
<textarea | ||
onChange={handleBioChange} | ||
value={bio} | ||
cols={30} | ||
rows={3} | ||
name="bio" | ||
className="w-full p-1 font-light text-xl border-2 border-gray-200 rounded-lg resize-none" | ||
placeholder="Bio..." | ||
/> | ||
</div> | ||
<label | ||
htmlFor="bio" | ||
className="max-w-xl text-gray-500" | ||
> | ||
Your bio will appear in your profile. It is like | ||
a description for your account. | ||
</label> | ||
</div> | ||
</div> | ||
<div className="save-button mt-8"> | ||
<button | ||
type="submit" | ||
className="p-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg px-36 py-2" | ||
> | ||
Save | ||
</button> | ||
</div> | ||
</form> | ||
</main> | ||
<Footer /> | ||
</> | ||
); | ||
try { | ||
const response = await fetch("/api/update-user", { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
method: "POST", | ||
body: JSON.stringify({ | ||
username: username, | ||
name: name, | ||
bio: bio, | ||
}), | ||
}); | ||
|
||
if (response.ok) { | ||
toast.success("Successfully updated user!"); | ||
setUpdating(false); | ||
} else { | ||
toast.error("Error updating user :c"); | ||
setUpdating(false); | ||
} | ||
} catch (e) { | ||
toast.error("Error updating user :c"); | ||
setUpdating(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Head> | ||
<title>My Account | Crystal</title> | ||
</Head> | ||
<Navbar /> | ||
<main className="flex flex-col p-8"> | ||
<header className="flex items-center justify-between"> | ||
<h1 className="text-4xl md:text-8xl lg:text-9xl tracking-tighter font-bold text-black py-5"> | ||
My Account | ||
</h1> | ||
</header> | ||
<hr className="border-1 border-gray-300" /> | ||
<div | ||
className="flex justify-start gap-8 items-center mt-8 profile-picture p-4 bg-cover" | ||
style={{ | ||
backgroundImage: | ||
'url("https://source.unsplash.com/collection/94997000/)', | ||
}} | ||
> | ||
<img | ||
src={session ? session?.user?.image : ""} | ||
className="ml-4 w-20 md:w-40 rounded-full border-4 border-white shadow-2xl" | ||
alt="" | ||
/> | ||
<h1 className="text-4xl md:text-8xl font-bold text-white py-2 px-4 bg-black bg-opacity-50 rounded-lg"> | ||
{name} | ||
</h1> | ||
</div> | ||
<form onSubmit={handleSubmit}> | ||
<div className="account-information mt-8 flex justify-center items-start gap-8 flex-col max-w-4xl"> | ||
<div className="username w-full"> | ||
<div className="username-input flex justify-start items-center gap-8 w-full"> | ||
<h1 className="font-bold text-4xl tracking-tighter"> | ||
Username | ||
</h1> | ||
<input | ||
value={username} | ||
onChange={handleUsernameChange} | ||
type="text" | ||
name="username" | ||
className="w-full p-1 font-light text-xl border-2 border-gray-200 rounded-lg" | ||
placeholder="Username..." | ||
/> | ||
</div> | ||
<label htmlFor="username" className="max-w-xl text-gray-500"> | ||
Your username is the unique identifier for your account. Give | ||
people your username so they can follow you! | ||
</label> | ||
</div> | ||
<div className="name w-full"> | ||
<div className="name-input flex justify-start items-center gap-8 w-full"> | ||
<h1 className="font-bold text-4xl tracking-tighter">Name</h1> | ||
<input | ||
value={name} | ||
onChange={handleNameChange} | ||
type="text" | ||
name="name" | ||
className="w-full p-1 font-light text-xl border-2 border-gray-200 rounded-lg" | ||
placeholder="Name..." | ||
/> | ||
</div> | ||
<label htmlFor="name" className="max-w-xl text-gray-500"> | ||
Your name will appear in your profile. | ||
</label> | ||
</div> | ||
<div className="bio w-full"> | ||
<div className="bio-input flex justify-start items-start gap-8 w-full"> | ||
<h1 className="font-bold text-4xl tracking-tighter">Bio</h1> | ||
<textarea | ||
onChange={handleBioChange} | ||
value={bio} | ||
cols={30} | ||
rows={3} | ||
name="bio" | ||
className="w-full p-1 font-light text-xl border-2 border-gray-200 rounded-lg resize-none" | ||
placeholder="Bio..." | ||
/> | ||
</div> | ||
<label htmlFor="bio" className="max-w-xl text-gray-500"> | ||
Your bio will appear in your profile. It is like a description | ||
for your account. | ||
</label> | ||
</div> | ||
</div> | ||
<div className="save-button mt-8"> | ||
<button | ||
type="submit" | ||
className="flex px-36 justify-center items-center p-2 bg-blue-500 hover:bg-blue-600 text-white rounded-lg py-2 h-12 w-36" | ||
> | ||
{updating === false ? ( | ||
<p>Save</p> | ||
) : ( | ||
<SpinnerCircular | ||
style={{ height: "100%" }} | ||
thickness={200} | ||
speed={100} | ||
color="rgba(255, 255, 255, 1)" | ||
secondaryColor="rgba(0, 0, 0, 0.3)" | ||
/> | ||
)} | ||
</button> | ||
</div> | ||
</form> | ||
</main> | ||
<Footer /> | ||
</> | ||
); | ||
}; | ||
|
||
export default Account; | ||
|
||
export async function getServerSideProps(context: any) { | ||
const session = await getSession(context); | ||
const session = await getSession(context); | ||
|
||
return { | ||
props: { | ||
session, | ||
}, | ||
}; | ||
return { | ||
props: { | ||
session, | ||
}, | ||
}; | ||
} |
Oops, something went wrong.
9790a43
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: