Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
saa00123 committed Sep 5, 2023
1 parent 329a8de commit 8a78a52
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 46 deletions.
2 changes: 1 addition & 1 deletion front/src/components/frames/Side/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function Profile() {
src={ProfileImg}
/>
<div className='flex justify-center items-center m-auto ml-1 text-white'>
{user ? user.nickname : "Guest"}
{user ? user.nickname : "최정훈"}
</div>
</div>
);
Expand Down
49 changes: 6 additions & 43 deletions front/src/components/frames/token/UserContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import React, {
useMemo,
} from "react";
import { useNavigate } from "react-router-dom";
import axios from "axios";

type User = {
token: string;
token: string | null;
nickname: string;
isNewUser: boolean;
};
Expand All @@ -21,27 +20,6 @@ type UserContextType = [

const UserContext = createContext<UserContextType | undefined>(undefined);

interface Member {
id: number;
name: string;
}

interface Team {
id: number;
name: string;
industryGroup: string;
}

interface TeamData {
id: number;
rank: string;
isAcceptMember: boolean;
isAcceptTeam: boolean;
nickname: string;
member: Member;
team: Team;
}

export const useUser = (): UserContextType => {
const context = useContext(UserContext);
if (!context) {
Expand All @@ -54,7 +32,6 @@ export const UserProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const [user, setUser] = useState<User | null>(null);
const [teamData, setTeamData] = useState<TeamData[]>();
const navigate = useNavigate();

useEffect(() => {
Expand All @@ -64,28 +41,14 @@ export const UserProvider: React.FC<{ children: React.ReactNode }> = ({
return tokenCookie ? tokenCookie.split("=")[1] : null;
};

const fetchTeamData = async () => {
try {
const response = await axios.get("staffs/myteam");
setTeamData(response.data);
if (response.data && response.data[0]?.nickname === "sample") {
navigate("/ChangeNickname");
}
} catch (error) {
console.error(error);
}
};

const token = fetchTokenFromCookie();
const storedNickname = localStorage.getItem("nickname");

if (token) {
if (storedNickname) {
setUser({ token, nickname: storedNickname, isNewUser: false });
} else {
setUser({ token, nickname: "Guest", isNewUser: true });
fetchTeamData();
}
if (storedNickname) {
setUser({ token, nickname: storedNickname, isNewUser: false });
} else if (token) {
setUser({ token, nickname: "Guest", isNewUser: true });
navigate("/ChangeNickname");
}
}, [navigate]);

Expand Down
2 changes: 1 addition & 1 deletion front/src/components/graph/AnalysisContribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import subData1 from "./GraphData/subData1";

function AnaylsisContribute() {
const [user] = useUser();
const currentNickname = user ? user.nickname : "Guest";
const currentNickname = user ? user.nickname : "최정훈";

const activeData = currentNickname === "최정훈" ? mainData : subData1;

Expand Down
2 changes: 1 addition & 1 deletion front/src/components/graph/CompareGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function CompareGraph() {
const [chartData, setChartData] = useState<any[]>([]);

const [user] = useUser();
const currentNickname = user ? user.nickname : "Guest";
const currentNickname = user ? user.nickname : "최정훈";

useEffect(() => {
const activeData = currentNickname === "최정훈" ? mainData : subData1;
Expand Down

0 comments on commit 8a78a52

Please sign in to comment.