fixing things with profilke page
This commit is contained in:
@@ -30,6 +30,7 @@ export default function Login() {
|
|||||||
// setCurrUser(new UserData(user));
|
// setCurrUser(new UserData(user));
|
||||||
|
|
||||||
console.log(user);
|
console.log(user);
|
||||||
|
window.open("/s", "_self");
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
// Handle Errors here.
|
// Handle Errors here.
|
||||||
@@ -48,7 +49,7 @@ export default function Login() {
|
|||||||
// if auth, go to dashboard
|
// if auth, go to dashboard
|
||||||
if (currUser) {
|
if (currUser) {
|
||||||
console.log("already logged in, redirecting to router");
|
console.log("already logged in, redirecting to router");
|
||||||
router.push("/s");
|
window.open("/s", "_self");
|
||||||
}
|
}
|
||||||
}, [currUser]);
|
}, [currUser]);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from "react";
|
|||||||
import User from "@nirvana/common/models/user";
|
import User from "@nirvana/common/models/user";
|
||||||
import UserService from "@nirvana/common/services/userService";
|
import UserService from "@nirvana/common/services/userService";
|
||||||
import { useAuth } from "../../contexts/authContext";
|
import { useAuth } from "../../contexts/authContext";
|
||||||
|
import { UserStatus } from "../../../common/models/user";
|
||||||
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
const { currUser } = useAuth();
|
const { currUser } = useAuth();
|
||||||
@@ -43,12 +44,10 @@ export default function Profile() {
|
|||||||
console.log("got user from the backend");
|
console.log("got user from the backend");
|
||||||
|
|
||||||
setUser(returnedUser);
|
setUser(returnedUser);
|
||||||
setNickname(returnedUser.nickName ?? "");
|
|
||||||
setFirstName(
|
setFirstName(
|
||||||
returnedUser.firstName ?? currUser.displayName.split(" ")[0]
|
returnedUser?.firstName ?? currUser.displayName!.split(" ")[0]
|
||||||
);
|
);
|
||||||
setLastName(returnedUser.lastName ?? "");
|
setLastName(returnedUser?.lastName ?? "");
|
||||||
setTeamRole(returnedUser.teamRole ?? "");
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
router.push("/teams/login");
|
router.push("/teams/login");
|
||||||
@@ -67,29 +66,25 @@ export default function Profile() {
|
|||||||
} else if (!lastName) {
|
} else if (!lastName) {
|
||||||
setError("Must input last name");
|
setError("Must input last name");
|
||||||
return;
|
return;
|
||||||
} else if (!nickname) {
|
|
||||||
setError("Must input nickname");
|
|
||||||
return;
|
|
||||||
} else if (nickname.length > 22) {
|
|
||||||
setError("nickname must be less than 22 characters");
|
|
||||||
return;
|
|
||||||
} else if (!teamRole) {
|
|
||||||
setError("Must input team role!");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the user in the backend or just merge results
|
// create the user in the backend or just merge results
|
||||||
let newUser = new User();
|
const newUser = new User(
|
||||||
newUser.id = currUser.uid;
|
user?.id,
|
||||||
|
currUser!.email!,
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
currUser!.photoURL!,
|
||||||
|
UserStatus.online
|
||||||
|
);
|
||||||
|
newUser.id = currUser!.uid;
|
||||||
newUser.firstName = firstName;
|
newUser.firstName = firstName;
|
||||||
newUser.lastName = lastName;
|
newUser.lastName = lastName;
|
||||||
newUser.nickName = nickname;
|
newUser.avatarUrl = currUser!.photoURL!;
|
||||||
newUser.avatarUrl = currUser.photoURL;
|
|
||||||
newUser.teamRole = teamRole;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await userService.updateUser(newUser);
|
await userService.updateUser(newUser);
|
||||||
router.push("/teams");
|
window.open("/s", "_self");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setError(
|
setError(
|
||||||
"Something went wrong in saving your information. Please try again."
|
"Something went wrong in saving your information. Please try again."
|
||||||
@@ -100,7 +95,7 @@ export default function Profile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const [firstName, setFirstName] = useState<string>(
|
const [firstName, setFirstName] = useState<string>(
|
||||||
currUser.displayName.split(" ")[0]
|
currUser!.displayName?.split(" ")[0] ?? ""
|
||||||
);
|
);
|
||||||
const [lastName, setLastName] = useState<string>("");
|
const [lastName, setLastName] = useState<string>("");
|
||||||
const [nickname, setNickname] = useState<string>("");
|
const [nickname, setNickname] = useState<string>("");
|
||||||
@@ -120,7 +115,9 @@ export default function Profile() {
|
|||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<span className="flex flex-col items-start">
|
<span className="flex flex-col items-start">
|
||||||
<span className="text-md">Avatar*</span>
|
<span className="text-md">
|
||||||
|
Avatar<span className="text-orange-500">*</span>
|
||||||
|
</span>
|
||||||
<span className="text-gray-300 text-xs">
|
<span className="text-gray-300 text-xs">
|
||||||
Please change your google image to change this.
|
Please change your google image to change this.
|
||||||
</span>
|
</span>
|
||||||
@@ -132,7 +129,9 @@ export default function Profile() {
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span className="flex flex-col items-start">
|
<span className="flex flex-col items-start">
|
||||||
<span className="text-md">Email*</span>
|
<span className="text-md">
|
||||||
|
Email<span className="text-orange-500">*</span>
|
||||||
|
</span>
|
||||||
<span className="text-gray-300 text-xs mb-2">
|
<span className="text-gray-300 text-xs mb-2">
|
||||||
This is set from your Google account and cannot be changed.
|
This is set from your Google account and cannot be changed.
|
||||||
</span>
|
</span>
|
||||||
@@ -146,7 +145,9 @@ export default function Profile() {
|
|||||||
|
|
||||||
<div className="flex flex-row justify-between space-x-3">
|
<div className="flex flex-row justify-between space-x-3">
|
||||||
<span className="flex flex-col items-start flex-1">
|
<span className="flex flex-col items-start flex-1">
|
||||||
<span className="text-md">First Name*</span>
|
<span className="text-md">
|
||||||
|
First Name<span className="text-orange-500">*</span>
|
||||||
|
</span>
|
||||||
<span className="text-gray-300 text-xs mb-2"></span>
|
<span className="text-gray-300 text-xs mb-2"></span>
|
||||||
<input
|
<input
|
||||||
placeholder="ex. John"
|
placeholder="ex. John"
|
||||||
@@ -157,7 +158,9 @@ export default function Profile() {
|
|||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span className="flex flex-col items-start flex-1">
|
<span className="flex flex-col items-start flex-1">
|
||||||
<span className="text-md">Last Name*</span>
|
<span className="text-md">
|
||||||
|
Last Name<span className="text-orange-500">*</span>
|
||||||
|
</span>
|
||||||
<span className="text-gray-300 text-xs mb-2"></span>
|
<span className="text-gray-300 text-xs mb-2"></span>
|
||||||
<input
|
<input
|
||||||
placeholder="ex. Brown"
|
placeholder="ex. Brown"
|
||||||
@@ -170,34 +173,6 @@ export default function Profile() {
|
|||||||
|
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
<span className="flex flex-col items-start">
|
|
||||||
<span className="text-md">Nickname*</span>
|
|
||||||
<span className="text-gray-300 text-xs mb-2">
|
|
||||||
What does your team call you? This is what is displayed.
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
placeholder="ex. nicky"
|
|
||||||
className="w-full rounded-lg bg-gray-50 p-3"
|
|
||||||
value={nickname}
|
|
||||||
onChange={(e) => setNickname(e.target.value)}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<span className="flex flex-col items-start">
|
|
||||||
<span className="text-md">Role*</span>
|
|
||||||
<span className="text-gray-300 text-xs mb-2">
|
|
||||||
Are you a developer? designer? manager?
|
|
||||||
</span>
|
|
||||||
<input
|
|
||||||
placeholder="ex. designer"
|
|
||||||
className="w-full rounded-lg bg-gray-50 p-3"
|
|
||||||
value={teamRole}
|
|
||||||
onChange={(e) => setTeamRole(e.target.value)}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<Divider />
|
|
||||||
|
|
||||||
<span className="flex flex-row justify-end space-x-2">
|
<span className="flex flex-row justify-end space-x-2">
|
||||||
{/* if they already had a nickname, they are probably revisiting this page */}
|
{/* if they already had a nickname, they are probably revisiting this page */}
|
||||||
{/* can't cancel if they are a new user */}
|
{/* can't cancel if they are a new user */}
|
||||||
|
|||||||
@@ -43,6 +43,20 @@ export default function MainRecoilDataHandler() {
|
|||||||
|
|
||||||
(async function () {
|
(async function () {
|
||||||
try {
|
try {
|
||||||
|
// get my current user profile and stay updated to my status
|
||||||
|
const unsubUser = onSnapshot(
|
||||||
|
doc(db, Collections.users, currUser!.uid),
|
||||||
|
(doc) => {
|
||||||
|
if (doc.exists()) {
|
||||||
|
const nirvanaUser = doc.data() as User;
|
||||||
|
setNirvanaUser(nirvanaUser);
|
||||||
|
} else {
|
||||||
|
window.open("/teams/profile", "_self");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
unsubs.push(unsubUser);
|
||||||
|
|
||||||
// get all conversations that I am a part of
|
// get all conversations that I am a part of
|
||||||
const q = query(
|
const q = query(
|
||||||
collectionGroup(db, Collections.conversationMembers),
|
collectionGroup(db, Collections.conversationMembers),
|
||||||
@@ -93,16 +107,6 @@ export default function MainRecoilDataHandler() {
|
|||||||
|
|
||||||
unsubs.push(unsubscribeUserConvoMember);
|
unsubs.push(unsubscribeUserConvoMember);
|
||||||
|
|
||||||
// get my current user profile and stay updated to my status
|
|
||||||
const unsubUser = onSnapshot(
|
|
||||||
doc(db, Collections.users, currUser!.uid),
|
|
||||||
(doc) => {
|
|
||||||
const nirvanaUser = doc.data() as User;
|
|
||||||
setNirvanaUser(nirvanaUser);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
unsubs.push(unsubUser);
|
|
||||||
|
|
||||||
// get every conversation where I am in the activeMembers list
|
// get every conversation where I am in the activeMembers list
|
||||||
const convoQuery = query(
|
const convoQuery = query(
|
||||||
collection(db, Collections.conversations),
|
collection(db, Collections.conversations),
|
||||||
|
|||||||
Reference in New Issue
Block a user