Skip to content

Commit

Permalink
Merge branch 'dev' into #601-add-unread-num-chatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyogyeong8 authored Jan 4, 2024
2 parents 66bcf6d + 59217e6 commit 0363049
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 29 deletions.
21 changes: 6 additions & 15 deletions src/components/ModalPopup/ModalMypageModify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ import theme from "@/tools/theme";
type ModalMypageModifyProps = Omit<
Parameters<typeof Modal>[0],
"padding" | "children" | "onEnter"
> & { profToken?: string; onUpdate?: () => void };
>;

type ProfileImageLargeProps = Parameters<typeof ProfileImage>[0];

type ButtonProfileImageProps = {
onUpdate?: ModalMypageModifyProps["onUpdate"];
};

const ProfileImageLarge = (props: ProfileImageLargeProps) => (
<div
css={{
Expand All @@ -48,7 +44,7 @@ const ProfileImageLarge = (props: ProfileImageLargeProps) => (
</div>
);

const ButtonProfileImage = ({ onUpdate }: ButtonProfileImageProps) => {
const ButtonProfileImage = () => {
const { t } = useTranslation("mypage");
const axios = useAxios();

Expand Down Expand Up @@ -88,7 +84,6 @@ const ButtonProfileImage = ({ onUpdate }: ButtonProfileImageProps) => {
});
if (data2?.result) {
fetchLoginInfo();
onUpdate?.();
setProfileAlert("SUCCESS");
return;
}
Expand All @@ -98,7 +93,7 @@ const ButtonProfileImage = ({ onUpdate }: ButtonProfileImageProps) => {
} catch (e) {
setProfileAlert("FAIL");
}
}, [onUpdate]);
}, []);

const onClick = useCallback(() => {
if (!profileAlert) inputRef.current?.click();
Expand Down Expand Up @@ -140,11 +135,7 @@ const ButtonProfileImage = ({ onUpdate }: ButtonProfileImageProps) => {
);
};

const ModalMypageModify = ({
profToken,
onUpdate,
...modalProps
}: ModalMypageModifyProps) => {
const ModalMypageModify = ({ ...modalProps }: ModalMypageModifyProps) => {
const { t } = useTranslation("mypage");
const axios = useAxios();

Expand Down Expand Up @@ -227,9 +218,9 @@ const ModalMypageModify = ({
<Modal padding="32px 10px 10px" onEnter={handleEditProfile} {...modalProps}>
<div css={styleName}>{loginInfo?.name}</div>
{loginInfo?.profileImgUrl && (
<ProfileImageLarge url={loginInfo?.profileImgUrl} token={profToken} />
<ProfileImageLarge url={loginInfo?.profileImgUrl} />
)}
<ButtonProfileImage onUpdate={onUpdate} />
<ButtonProfileImage />
<DottedLine direction="row" margin="0 2px" />
<div css={{ rowGap: "10px", padding: "0px 20px" }}>
<div css={{ ...styleTitle, marginTop: "24px" }}>
Expand Down
11 changes: 5 additions & 6 deletions src/components/User/ProfileImage.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { useEffect, useState } from "react";

import theme from "@/tools/theme";
import { getS3Url } from "@/tools/trans";

import defaultImg from "@/static/assets/profileImgOnError.png";

type ProfileImageProps = {
url: string;
token?: string;
};

const ProfileImage = ({ url, token }: ProfileImageProps) => {
const getSrc = () => getS3Url(`/profile-img/${url}?token=${token || ""}`);
const [src, setSrc] = useState(getSrc());
const ProfileImage = ({ url }: ProfileImageProps) => {
const [src, setSrc] = useState(url);

useEffect(() => setSrc(getSrc()), [url, token]);
useEffect(() => {
setSrc(url);
}, [url]);

return (
<div
Expand Down
9 changes: 1 addition & 8 deletions src/pages/Mypage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useCallback, useState } from "react";
import { useTranslation } from "react-i18next";

import useDateToken from "@/hooks/useDateToken";
import { useValueRecoilState } from "@/hooks/useFetchRecoilState";

import AdaptiveDiv from "@/components/AdaptiveDiv";
Expand Down Expand Up @@ -29,7 +28,6 @@ import { isNotificationOn } from "@/tools/trans";

const Mypage = () => {
const { t, i18n } = useTranslation("mypage");
const [profImgToken, refreshProfImgToken] = useDateToken();
const loginInfo = useValueRecoilState("loginInfo");
const notificationOptions = useValueRecoilState("notificationOptions");
const { id: userId } = loginInfo || {};
Expand Down Expand Up @@ -102,10 +100,7 @@ const Mypage = () => {
<div css={{ display: "flex", alignItems: "center" }}>
<div css={styleProfImg}>
{loginInfo?.profileImgUrl && (
<ProfileImage
url={loginInfo.profileImgUrl}
token={profImgToken}
/>
<ProfileImage url={loginInfo.profileImgUrl} />
)}
</div>
<div css={theme.font16_bold} className="selectable">
Expand Down Expand Up @@ -155,8 +150,6 @@ const Mypage = () => {
<ModalMypageModify
isOpen={isOpenProfileModify}
onChangeIsOpen={setIsOpenProfileModify}
onUpdate={refreshProfImgToken}
profToken={profImgToken}
/>
<ModalReport isOpen={isOpenReport} onChangeIsOpen={setIsOpenReport} />
<ModalNotification
Expand Down

0 comments on commit 0363049

Please sign in to comment.