Skip to content

Commit

Permalink
Refactor: #80 URL revoke를 위한 로직 변경 및 파일 경로 수정, 시간 상수 활용 코드 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoonyesol committed Sep 3, 2024
1 parent 125ee96 commit 9269d29
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
14 changes: 5 additions & 9 deletions src/components/user/auth-form/ProfileImageContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useFormContext } from 'react-hook-form';
import { convertBytesToString } from '@utils/converter';
import { USER_SETTINGS } from '@constants/settings';
import useToast from '@hooks/useToast';
import { useEffect, useRef } from 'react';
import { useEffect } from 'react';

type ProfileImageContainerProps = {
imageUrl: string;
Expand All @@ -14,14 +14,12 @@ type ProfileImageContainerProps = {
export default function ProfileImageContainer({ imageUrl, setImageUrl }: ProfileImageContainerProps) {
const { setValue } = useFormContext();
const { toastWarn } = useToast();
const imageRef = useRef<string | null>(null);

// 컴포넌트 언마운트 시 이미지 URL 해제
useEffect(() => {
return () => {
if (imageRef.current) URL.revokeObjectURL(imageRef.current);
if (imageUrl) URL.revokeObjectURL(imageUrl);
};
}, []);
}, [imageUrl]);

const handleChangeImg = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
Expand All @@ -37,13 +35,11 @@ export default function ProfileImageContainer({ imageUrl, setImageUrl }: Profile
const image = URL.createObjectURL(file);
setImageUrl(image);
setValue('profileUrl', image);
imageRef.current = image;
};

const handleRemoveImg = () => {
if (imageRef.current) {
URL.revokeObjectURL(imageRef.current);
imageRef.current = null;
if (imageUrl) {
URL.revokeObjectURL(imageUrl);
}

setImageUrl('');
Expand Down
8 changes: 4 additions & 4 deletions src/constants/settings.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { MB } from '@constants/units';
import { DAY, MB, MINUTE, SECOND } from '@constants/units';

export const AUTH_SETTINGS = Object.freeze({
// ACCESS_TOKEN_EXPIRATION: 3000, // 테스트용 3초
ACCESS_TOKEN_EXPIRATION: 15 * 60 * 1000, // 15분
REFRESH_TOKEN_EXPIRATION: 7 * 24 * 60 * 60 * 1000, // 7일
// ACCESS_TOKEN_EXPIRATION: 5 * SECOND, // 테스트용 5초
ACCESS_TOKEN_EXPIRATION: 15 * MINUTE, // 15분
REFRESH_TOKEN_EXPIRATION: 7 * DAY, // 7일
});

export const USER_SETTINGS = Object.freeze({
Expand Down
2 changes: 1 addition & 1 deletion src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import userServiceHandler from '@mocks/services/userServiceHandler';
import teamServiceHandler from '@mocks/services/teamServiceHandler';
import projectServiceHandler from '@mocks/services/projectServiceHandler';
import taskServiceHandler from '@mocks/services/taskServiceHandler';
import authServiceHandler from './services/authServiceHandler';
import authServiceHandler from '@mocks/services/authServiceHandler';

const handlers = [
...userServiceHandler,
Expand Down
4 changes: 2 additions & 2 deletions src/services/axiosProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import axios from 'axios';
import { SECOND } from '@constants/units';
import { JWT_TOKEN_DUMMY } from '@mocks/mockData';
import type { AxiosInstance, AxiosRequestConfig } from 'axios';
import useToast from '@hooks/useToast';
import { getAccessToken } from '@services/authService';
import { useAuthStore } from '@/stores/useAuthStore';
import useToast from '@/hooks/useToast';
import { getAccessToken } from './authService';

const BASE_URL = import.meta.env.VITE_BASE_URL;
const defaultConfigOptions: AxiosRequestConfig = {
Expand Down

0 comments on commit 9269d29

Please sign in to comment.