Skip to content

Commit

Permalink
fix :: profileImgSrc setting
Browse files Browse the repository at this point in the history
  • Loading branch information
wjzlskxk committed Nov 6, 2024
1 parent cb474f2 commit 6c7f83c
Showing 1 changed file with 38 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ChangeEvent, useEffect, useState } from "react";
import { useRecoilState } from "recoil";
import * as S from "./style";
import { BiPlus } from "react-icons/bi";
import DODAM_DEFAULT_PROFILE from "../../../../../images/default_profile.png";
import CAMERA_IMAGE from "../../../../../images/camera.svg";
import { MyInfoModifyModalState } from "../../../../../store/modal";
import useModifyMainProfile from "../../../../../hooks/mainProfile/useModifyMainProfile";
import fileUpload from "../../../../../repository/mainProfile/fileUpload";
import { autoHypenPhone } from "../../../../../util/autoHypenPhone";
import { profileInfo } from "../../../../../store/profile";
import useMyGradeInfo from "../../../../../hooks/profile/useMyGradeInfo";
import MyInfoClassModifyModal from "../MyInfoClassModifyModal/MyInfoClassModifyModal";
import patternCheck from "../../../../../util/patternCheck";
import { B1ndToast } from "@b1nd/b1nd-toastify";
import { ChangeEvent, useEffect, useState } from 'react';
import { useRecoilState } from 'recoil';
import * as S from './style';
import { BiPlus } from 'react-icons/bi';
import DODAM_DEFAULT_PROFILE from '../../../../../images/default_profile.png';
import CAMERA_IMAGE from '../../../../../images/camera.svg';
import { MyInfoModifyModalState } from '../../../../../store/modal';
import useModifyMainProfile from '../../../../../hooks/mainProfile/useModifyMainProfile';
import fileUpload from '../../../../../repository/mainProfile/fileUpload';
import { autoHypenPhone } from '../../../../../util/autoHypenPhone';
import { profileInfo } from '../../../../../store/profile';
import useMyGradeInfo from '../../../../../hooks/profile/useMyGradeInfo';
import MyInfoClassModifyModal from '../MyInfoClassModifyModal/MyInfoClassModifyModal';
import patternCheck from '../../../../../util/patternCheck';
import { B1ndToast } from '@b1nd/b1nd-toastify';

const MyInfoModifyModal = () => {
const [isOpenMyInfoModifyModal, setIsOpenMyInfoModifyModal] = useRecoilState(MyInfoModifyModalState);
Expand All @@ -22,10 +22,10 @@ const MyInfoModifyModal = () => {

const { student, phone, email, profileImage } = tempProfileInfo;

const [emailInfo, setEmailInfo] = useState<string>("");
const [phoneInfo, setPhoneInfo] = useState<string>("");
const [emailInfo, setEmailInfo] = useState<string>('');
const [phoneInfo, setPhoneInfo] = useState<string>('');

const [tempPhoneInfo, setTempPhoneInfo] = useState<string>("");
const [tempPhoneInfo, setTempPhoneInfo] = useState<string>('');

const { patchMainProfile } = useModifyMainProfile();

Expand All @@ -48,8 +48,10 @@ const MyInfoModifyModal = () => {
try {
const formData = new FormData();
if (e.target.files) {
formData.append("file", e.target.files[0]);
const { data } = await fileUpload.postFileUpload(formData.get("file") ? formData : "");
const url = URL.createObjectURL(e.target.files[0]);
setImageSrc(url);
formData.append('file', e.target.files[0]);
const { data } = await fileUpload.postFileUpload(formData.get('file') ? formData : '');
if (data) {
setImageSrc(data);
}
Expand All @@ -58,7 +60,7 @@ const MyInfoModifyModal = () => {
};

useEffect(() => {
setPhoneInfo(tempPhoneInfo.split("-")[0] + tempPhoneInfo.split("-")[1] + tempPhoneInfo.split("-")[2]);
setPhoneInfo(tempPhoneInfo.split('-')[0] + tempPhoneInfo.split('-')[1] + tempPhoneInfo.split('-')[2]);
}, [tempPhoneInfo]);

const emailInfoHandler = (e: any) => {
Expand All @@ -78,12 +80,12 @@ const MyInfoModifyModal = () => {
)
) {
try {
if (!patternCheck.emailCheck(emailInfo) || emailInfo.trim() === "") {
return B1ndToast.showInfo("์ด๋ฉ”์ผ ํ˜•์‹์„ ์ง€์ผœ์ฃผ์„ธ์š”!");
if (!patternCheck.emailCheck(emailInfo) || emailInfo.trim() === '') {
return B1ndToast.showInfo('์ด๋ฉ”์ผ ํ˜•์‹์„ ์ง€์ผœ์ฃผ์„ธ์š”!');
}

if (!patternCheck.phoneCheck(phoneInfo) || phoneInfo.trim() === "") {
return B1ndToast.showInfo("์ „ํ™”๋ฒˆํ˜ธ ํ˜•์‹์„ ์ง€์ผœ์ฃผ์„ธ์š”!");
if (!patternCheck.phoneCheck(phoneInfo) || phoneInfo.trim() === '') {
return B1ndToast.showInfo('์ „ํ™”๋ฒˆํ˜ธ ํ˜•์‹์„ ์ง€์ผœ์ฃผ์„ธ์š”!');
}

await patchMainProfile({
Expand All @@ -92,7 +94,7 @@ const MyInfoModifyModal = () => {
phone: phoneInfo,
});

B1ndToast.showSuccess("๋‚ด ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜์…จ์Šต๋‹ˆ๋‹ค!");
B1ndToast.showSuccess('๋‚ด ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜์…จ์Šต๋‹ˆ๋‹ค!');

setTempProfileInfo({
...tempProfileInfo,
Expand All @@ -103,10 +105,10 @@ const MyInfoModifyModal = () => {

setIsOpenMyInfoModifyModal((prev: boolean) => !prev);
} catch (error) {
B1ndToast.showError("๋‚ด ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค!");
B1ndToast.showError('๋‚ด ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค!');
}
} else {
B1ndToast.showInfo("๋‚ด ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”!");
B1ndToast.showInfo('๋‚ด ์ •๋ณด๋ฅผ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”!');
}
};

Expand All @@ -122,11 +124,11 @@ const MyInfoModifyModal = () => {
<BiPlus
className="exitIcon"
style={{
fontSize: "30px",
transform: "rotate(45deg)",
position: "absolute",
top: "20px",
right: "20px",
fontSize: '30px',
transform: 'rotate(45deg)',
position: 'absolute',
top: '20px',
right: '20px',
}}
onClick={() => {
setIsOpenMyInfoModifyModal(false);
Expand All @@ -144,7 +146,7 @@ const MyInfoModifyModal = () => {
{isLoading ? (
<>๋กœ๋”ฉ์ค‘..</>
) : (
<S.ModalPictureImg src={imageSrc === null || imageSrc === "" ? DODAM_DEFAULT_PROFILE : imageSrc} />
<S.ModalPictureImg src={imageSrc === null || imageSrc === '' ? DODAM_DEFAULT_PROFILE : imageSrc} />
)}
</div>

Expand All @@ -154,7 +156,7 @@ const MyInfoModifyModal = () => {
</div>
</S.PictureImageModifyLabel>
<input
style={{ display: "none" }}
style={{ display: 'none' }}
type="file"
id="file_upload"
accept="image/jpg, image/png, image/jpeg"
Expand All @@ -164,7 +166,7 @@ const MyInfoModifyModal = () => {

<S.PictureBecomeBasicImageBtn
onClick={() => {
setImageSrc("");
setImageSrc('');
}}
>
๊ธฐ๋ณธ ํ”„๋กœํ•„๋กœ ๋ณ€๊ฒฝ
Expand Down

0 comments on commit 6c7f83c

Please sign in to comment.